Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
anshnagwekar committed Jul 12, 2023
1 parent e10a244 commit 68f472d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 55 deletions.
14 changes: 14 additions & 0 deletions backend/courses/migrations/0058_merge_20230712_1350.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.2.18 on 2023-07-12 17:50

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('courses', '0054_userprofile_uuid_secret_and_more'),
('courses', '0057_alter_ngssrestriction_inclusive'),
]

operations = [
]
1 change: 0 additions & 1 deletion backend/courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone
from genericpath import exists

from review.annotations import review_averages

Expand Down
1 change: 0 additions & 1 deletion backend/courses/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from textwrap import dedent

from django.contrib.auth import get_user_model
Expand Down
2 changes: 1 addition & 1 deletion backend/courses/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import include, path
from django.urls import path

from courses import views
from courses.views import CourseListSearch
Expand Down
36 changes: 17 additions & 19 deletions backend/courses/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from datetime import timezone

from django.contrib.auth import get_user_model
from django.db.models import Prefetch, Q, Subquery
from django.forms.models import model_to_dict
from django.http import HttpResponse, JsonResponse
from django.db.models import Prefetch, Q
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.views import View
from django_auto_prefetching import AutoPrefetchViewSetMixin
from rest_framework import generics, mixins, serializers, status, viewsets
from rest_framework.decorators import permission_classes
from rest_framework import generics, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

Expand All @@ -28,7 +23,6 @@
AttributeListSerializer,
CourseDetailSerializer,
CourseListSerializer,
FriendshipRequestSerializer,
FriendshipSerializer,
MiniSectionSerializer,
NGSSRestrictionListSerializer,
Expand Down Expand Up @@ -401,15 +395,18 @@ def get_accepted_friends(user):

class FriendshipView(generics.ListAPIView):
"""
get: Get a list of all friendships and friendship requests (sent and recieved) for the specified user.
Filter the list by status (accepted, sent) to distinguish between friendships and friendship requests.
post: Create a friendship between two users (sender and recipient). If a previous request does not exist between
the two friendships, then we create friendship request. If a previous request exists (where the recipient is the sender) and
the recipient of a request hits this route, then we accept the request.
delete: Delete a friendship between two users (sender and recipient). If there exists only a friendship request between two users, then
we either delete the friendship request if the sender hits the route, or we reject the request if the recipient hits this route.
get: Get a list of all friendships and friendship requests (sent and recieved) for the
specified user. Filter the list by status (accepted, sent) to distinguish between
friendships and friendship requests.
post: Create a friendship between two users (sender and recipient). If a previous request does
not exist between the two friendships, then we create friendship request. If a previous request
exists (where the recipient is the sender) and the recipient of a request hits this route, then
we accept the request.
delete: Delete a friendship between two users (sender and recipient). If there exists only
a friendship request between two users, then we either delete the friendship request
if the sender hits the route, or we reject the request if the recipient hits this route.
"""

# model = Friendship
Expand Down Expand Up @@ -511,7 +508,8 @@ def post(self, request):
return Response({}, status=status.HTTP_409_CONFLICT)

def delete(self, request):
# either deletes a friendship or cancels/rejects a friendship request (depends on who sends the request)
# either deletes a friendship or cancels/rejects a friendship request
# (depends on who sends the request)
res = {}
sender = request.user
recipient = get_object_or_404(User, username=request.data.get("pennkey"))
Expand Down
7 changes: 3 additions & 4 deletions backend/plan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError
from django.db.models import Prefetch, Q, Subquery
from django.forms.models import model_to_dict
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django_auto_prefetching import AutoPrefetchViewSetMixin
from ics import Calendar as ICSCal
Expand All @@ -16,7 +14,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from courses.models import Course, Friendship, Meeting, Section, User
from courses.models import Course, Meeting, Section
from courses.serializers import CourseListSerializer
from courses.util import get_course_and_section, get_current_semester
from courses.views import get_accepted_friends
Expand Down Expand Up @@ -189,7 +187,8 @@ def recommend_courses_view(request):

class PrimaryScheduleViewSet(viewsets.ModelViewSet):
"""
list: Get the primary schedule for the current user as well as primary schedules of the user's friends.
list: Get the primary schedule for the current user as well as primary
schedules of the user's friends.
update: Create or update the primary schedule for the current user.
"""
Expand Down
8 changes: 0 additions & 8 deletions backend/tests/courses/test_friendship_models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import json

from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.test import TestCase
from options.models import Option
from rest_framework.test import APIClient

from alert.management.commands.recomputestats import recompute_precomputed_fields
from alert.models import AddDropPeriod
from courses.models import Friendship, UserProfile
from tests.courses.util import create_mock_data


friendship_url = "/api/base/friendship/"
Expand Down Expand Up @@ -111,7 +104,6 @@ def test_basic_friendship_remove(self):

def test_basic_null_delete(self):
u1 = self.u1
u2 = self.u2
make_friends = self.client2.delete(friendship_url, {"friend_id": u1.id})
self.assertEquals(make_friends.status_code, 404) # friendship does not exist

Expand Down
24 changes: 3 additions & 21 deletions backend/tests/plan/test_primary_schedules.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.test import TestCase
from options.models import ( # TODO: can't resolve this import for some reason (also appears in other PCP Schedule tests)
Option,
)
from rest_framework.test import APIClient

from alert.management.commands.recomputestats import recompute_precomputed_fields
from alert.models import AddDropPeriod
from courses.models import Friendship
from courses.util import invalidate_current_semester_cache
from plan.models import PrimarySchedule, Schedule
from plan.models import Schedule
from tests.alert.test_alert import TEST_SEMESTER, set_semester
from tests.courses.util import create_mock_data, create_mock_data_with_reviews
from tests.courses.util import create_mock_data_with_reviews


primary_schedule_url = "/api/plan/primary-schedules/"
TEST_SEMESTER = "2019A"


def set_semester():
post_save.disconnect(
receiver=invalidate_current_semester_cache,
sender=Option,
dispatch_uid="invalidate_current_semester_cache",
)
Option(key="SEMESTER", value=TEST_SEMESTER, value_type="TXT").save()
AddDropPeriod(semester=TEST_SEMESTER).save()


class PrimaryScheduleTest(TestCase):
Expand Down Expand Up @@ -63,7 +45,7 @@ def setUp(self):
# TODO: write test cases for the following cases
"""
- remove primary schedule (and check no other primary scheudles in the models)
- can't do this since we don't have a remove primary schedule feature. I think
- can't do this since we don't have a remove primary schedule feature. I think
it's fine that we don't have one for now.
"""

Expand Down

0 comments on commit 68f472d

Please sign in to comment.