def test_get_coursegroup_by_id(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course1 = coursehelper.given_course_exists(course_group)
        course2 = coursehelper.given_course_exists(course_group)
        homeworkhelper.given_homework_exists(course1)
        homeworkhelper.given_homework_exists(course1, completed=True)
        homeworkhelper.given_homework_exists(course1,
                                             completed=True,
                                             current_grade='25/30')
        homeworkhelper.given_homework_exists(course2)
        homeworkhelper.given_homework_exists(course2, completed=True)

        # WHEN
        response = self.client.get(
            reverse('planner_coursegroups_detail',
                    kwargs={'pk': course_group.pk}))

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        coursegrouphelper.verify_course_group_matches_data(
            self, course_group, response.data)
        self.assertEqual(response.data['num_days'], 122)
        self.assertEqual(response.data['num_days_completed'],
                         (datetime.datetime.now().date() -
                          course_group.start_date).days)
        self.assertEqual(response.data['num_homework'], 5)
        self.assertEqual(response.data['num_homework_completed'], 3)
        self.assertEqual(response.data['num_homework_graded'], 1)
예제 #2
0
    def test_weighted_grade_imbalanced(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course)
        category2 = categoryhelper.given_category_exists(course, title='Test Category 2')
        category3 = categoryhelper.given_category_exists(course, title='Test Category 3')

        # WHEN
        homeworkhelper.given_homework_exists(course, category=category1, completed=True, current_grade='10/10')
        homeworkhelper.given_homework_exists(course, category=category1, completed=True, current_grade='50/100')
        homeworkhelper.given_homework_exists(course, category=category2, completed=True, current_grade='40/50')
        homeworkhelper.given_homework_exists(course, category=category2, completed=True, current_grade='60/100')
        homeworkhelper.given_homework_exists(course, category=category3, completed=True, current_grade='200/200')

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        course = Course.objects.get(pk=course.pk)
        category1 = Category.objects.get(pk=category1.pk)
        category2 = Category.objects.get(pk=category2.pk)
        category3 = Category.objects.get(pk=category3.pk)
        # 360/460 total points
        self.assertEqual(float(course_group.average_grade), 78.2609)
        self.assertEqual(float(course.current_grade), 78.2609)
        # 60/110 total points
        self.assertEqual(float(category1.average_grade), 54.5454)
        # 100/150 total points
        self.assertEqual(float(category2.average_grade), 66.6667)
        # 200/200 total points
        self.assertEqual(float(category3.average_grade), 100)
예제 #3
0
    def test_not_found(self):
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homeworkhelper.given_homework_exists(course)

        # WHEN
        responses = [
            self.client.get(
                reverse('planner_reminders_detail', kwargs={'pk': '9999'})),
            self.client.put(
                reverse('planner_reminders_detail', kwargs={'pk': '9999'})),
            self.client.delete(
                reverse('planner_reminders_detail', kwargs={'pk': '9999'}))
        ]

        # THEN
        for response in responses:
            if isinstance(response.data, list):
                self.assertEqual(response.status_code, status.HTTP_200_OK)
                self.assertEqual(len(response.data), 0)
            else:
                self.assertEqual(response.status_code,
                                 status.HTTP_404_NOT_FOUND)
                self.assertIn('not found', response.data['detail'].lower())
예제 #4
0
    def test_export_success(self):
        # GIVEN
        user1 = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        user2 = userhelper.given_a_user_exists(username='******', email='*****@*****.**')
        external_calendar = externalcalendarhelper.given_external_calendar_exists(user1)
        event1 = eventhelper.given_event_exists(user1)
        event2 = eventhelper.given_event_exists(user1)
        eventhelper.given_event_exists(user2)
        course_group1 = coursegrouphelper.given_course_group_exists(user1)
        course_group2 = coursegrouphelper.given_course_group_exists(user1)
        course_group3 = coursegrouphelper.given_course_group_exists(user2)
        course1 = coursehelper.given_course_exists(course_group1, room='')
        course2 = coursehelper.given_course_exists(course_group2)
        course3 = coursehelper.given_course_exists(course_group3)
        course_schedule1 = courseschedulehelper.given_course_schedule_exists(course1)
        course_schedule2 = courseschedulehelper.given_course_schedule_exists(course2)
        courseschedulehelper.given_course_schedule_exists(course3)
        category1 = categoryhelper.given_category_exists(course1, title='Uncategorized')
        category2 = categoryhelper.given_category_exists(course2)
        category3 = categoryhelper.given_category_exists(course3)
        material_group1 = materialgrouphelper.given_material_group_exists(user1)
        material_group2 = materialgrouphelper.given_material_group_exists(user2)
        material1 = materialhelper.given_material_exists(material_group1)
        materialhelper.given_material_exists(material_group2)
        homework1 = homeworkhelper.given_homework_exists(course1, category=category1, completed=True,
                                                         current_grade="20/30", materials=[material1])
        homework2 = homeworkhelper.given_homework_exists(course2, category=category2, current_grade="-1/100")
        homeworkhelper.given_homework_exists(course3, category=category3, completed=True, current_grade="-1/100")
        reminder = reminderhelper.given_reminder_exists(user1, homework=homework1)

        # WHEN
        response = self.client.get(reverse('importexport_resource_export'))
        data = json.loads(response.content.decode('utf-8'))

        # THEN
        course_group1 = CourseGroup.objects.get(pk=course_group1.pk)
        course_group2 = CourseGroup.objects.get(pk=course_group2.pk)
        course1 = Course.objects.get(pk=course1.pk)
        course2 = Course.objects.get(pk=course2.pk)
        category1 = Category.objects.get(pk=category1.pk)
        category2 = Category.objects.get(pk=category2.pk)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        externalcalendarhelper.verify_externalcalendar_matches_data(self, external_calendar,
                                                                    data['external_calendars'][0])
        eventhelper.verify_event_matches_data(self, event1, data['events'][0])
        eventhelper.verify_event_matches_data(self, event2, data['events'][1])
        coursegrouphelper.verify_course_group_matches_data(self, course_group1, data['course_groups'][0])
        coursegrouphelper.verify_course_group_matches_data(self, course_group2, data['course_groups'][1])
        coursehelper.verify_course_matches_data(self, course1, data['courses'][0])
        coursehelper.verify_course_matches_data(self, course2, data['courses'][1])
        courseschedulehelper.verify_course_schedule_matches(self, course_schedule1, data['course_schedules'][0])
        courseschedulehelper.verify_course_schedule_matches(self, course_schedule2, data['course_schedules'][1])
        categoryhelper.verify_category_matches_data(self, category1, data['categories'][1])
        categoryhelper.verify_category_matches_data(self, category2, data['categories'][0])
        homeworkhelper.verify_homework_matches_data(self, homework1, data['homework'][0])
        homeworkhelper.verify_homework_matches_data(self, homework2, data['homework'][1])
        reminderhelper.verify_reminder_matches_data(self, reminder, data['reminders'][0])
예제 #5
0
    def test_category_changed_deleted_grade_changes(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course, weight=30)
        category2 = categoryhelper.given_category_exists(course, title='Test Category 2', weight=50)
        category3 = categoryhelper.given_category_exists(course, title='Test Category 3', weight=20)
        homeworkhelper.given_homework_exists(course, category=category1, completed=True,
                                             start=datetime.datetime(2017, 4, 8, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 8, 20, 30, tzinfo=pytz.utc),
                                             current_grade='25/60')
        homeworkhelper.given_homework_exists(course, category=category2, completed=True,
                                             start=datetime.datetime(2017, 4, 9, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 9, 20, 30, tzinfo=pytz.utc),
                                             current_grade='75/80')
        homeworkhelper.given_homework_exists(course, category=category3, completed=True,
                                             start=datetime.datetime(2017, 4, 10, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 10, 20, 30, tzinfo=pytz.utc),
                                             current_grade='50/120')
        homeworkhelper.given_homework_exists(course, category=category1, completed=True,
                                             start=datetime.datetime(2017, 4, 11, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 11, 20, 30, tzinfo=pytz.utc),
                                             current_grade='60/80')
        homeworkhelper.given_homework_exists(course, category=category3, completed=True,
                                             start=datetime.datetime(2017, 4, 11, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 11, 20, 30, tzinfo=pytz.utc),
                                             current_grade='110/130')
        course = Course.objects.get(pk=course.pk)
        category1 = Category.objects.get(pk=category1.pk)
        self.assertEqual(float(course.current_grade), 77.8893)
        self.assertEqual(float(category1.average_grade), 60.7143)
        self.assertEqual(float(category1.grade_by_weight), 18.2143)

        # WHEN
        category2.weight = 30
        category2.save()
        category1.weight = 50
        category1.save()

        # THEN
        category1 = Category.objects.get(pk=category1.pk)
        category2 = Category.objects.get(pk=category2.pk)
        self.assertEqual(float(category1.average_grade), 60.7143)
        self.assertEqual(float(category1.grade_by_weight), 30.3571)
        self.assertEqual(float(category2.average_grade), 93.75)
        self.assertEqual(float(category2.grade_by_weight), 28.125)

        # WHEN
        category2.delete()

        # THEN
        course = Course.objects.get(pk=course.pk)
        category1 = Category.objects.get(pk=category1.pk)
        self.assertEqual(float(course.current_grade), 61.6531)
        self.assertEqual(float(category1.average_grade), 60.7143)
        self.assertEqual(float(category1.grade_by_weight), 30.3571)
예제 #6
0
    def test_course_deleted_grade_changes(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course1 = coursehelper.given_course_exists(course_group)
        course2 = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course1, weight=30)
        category2 = categoryhelper.given_category_exists(
            course1, title='Test Category 2', weight=50)
        category3 = categoryhelper.given_category_exists(
            course2, title='Test Category 3', weight=20)
        homeworkhelper.given_homework_exists(
            course1,
            category=category1,
            completed=True,
            start=datetime.datetime(2017, 4, 8, 20, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2017, 4, 8, 20, 30, tzinfo=pytz.utc),
            current_grade='25/100')
        homeworkhelper.given_homework_exists(
            course1,
            category=category2,
            completed=True,
            start=datetime.datetime(2017, 4, 9, 20, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2017, 4, 9, 20, 30, tzinfo=pytz.utc),
            current_grade='75/100')
        homeworkhelper.given_homework_exists(
            course2,
            category=category3,
            completed=True,
            start=datetime.datetime(2017, 4, 10, 20, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2017, 4, 10, 20, 30, tzinfo=pytz.utc),
            current_grade='50/100')
        homeworkhelper.given_homework_exists(
            course1,
            category=category1,
            completed=True,
            start=datetime.datetime(2017, 4, 11, 20, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2017, 4, 11, 20, 30, tzinfo=pytz.utc),
            current_grade='60/80')
        homeworkhelper.given_homework_exists(
            course2,
            category=category3,
            start=datetime.datetime(2017, 4, 12, 20, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2017, 4, 12, 20, 30, tzinfo=pytz.utc),
            completed=True,
            current_grade='4/5')
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        self.assertEqual(float(course_group.average_grade), 58.006)

        # WHEN
        course2.delete()

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        self.assertEqual(float(course_group.average_grade), 64.5833)
예제 #7
0
    def test_homework_feed(self):
        # GIVEN
        user1 = userhelper.given_a_user_exists()
        user1.settings.enable_private_slug()
        user2 = userhelper.given_a_user_exists(username='******',
                                               email='*****@*****.**')
        user2.settings.enable_private_slug()
        course_group1 = coursegrouphelper.given_course_group_exists(user1)
        course_group2 = coursegrouphelper.given_course_group_exists(user1)
        course_group3 = coursegrouphelper.given_course_group_exists(user2)
        course1 = coursehelper.given_course_exists(course_group1, room='')
        course2 = coursehelper.given_course_exists(course_group2)
        course3 = coursehelper.given_course_exists(course_group3)
        category1 = categoryhelper.given_category_exists(course1,
                                                         title='Uncategorized')
        category2 = categoryhelper.given_category_exists(course2)
        category3 = categoryhelper.given_category_exists(course3)
        homework1 = homeworkhelper.given_homework_exists(course1,
                                                         category=category1,
                                                         completed=True,
                                                         current_grade="20/30")
        homework2 = homeworkhelper.given_homework_exists(
            course2, category=category2, current_grade="-1/100")
        homeworkhelper.given_homework_exists(course3,
                                             category=category3,
                                             completed=True,
                                             current_grade="-1/100")

        # WHEN
        response = self.client.get(
            reverse("feed_private_homework_ical",
                    kwargs={"slug": user1.settings.private_slug}))

        # THEN
        calendar = icalendar.Calendar.from_ical(
            response.content.decode('utf-8'))
        self.assertEqual(len(calendar.subcomponents), 2)
        self.assertEqual(calendar.subcomponents[0]['SUMMARY'], homework1.title)
        self.assertEqual(
            calendar.subcomponents[0]['DESCRIPTION'],
            'Class Info: {}\nGrade: {}\nComments: {}'.format(
                homework1.course.title, homework1.current_grade,
                homework1.comments))
        self.assertEqual(calendar.subcomponents[0]['DTSTART'].dt,
                         homework1.start)
        self.assertEqual(calendar.subcomponents[0]['DTEND'].dt, homework1.end)
        self.assertEqual(calendar.subcomponents[1]['SUMMARY'], homework2.title)
        self.assertEqual(calendar.subcomponents[1]['DTSTART'].dt,
                         homework2.start)
        self.assertEqual(calendar.subcomponents[1]['DTEND'].dt, homework2.end)
        self.assertEqual(
            calendar.subcomponents[1]['DESCRIPTION'],
            'Class Info: {} for {} in {}\nComments: {}'.format(
                homework2.category.title, homework2.course.title,
                homework2.course.room, homework2.comments))
예제 #8
0
    def test_title_search_query(self):
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course, title='test1')
        homeworkhelper.given_homework_exists(course, title='test2')

        response = self.client.get(
            reverse('planner_homework_list') + '?search=test1')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['title'], homework.title)
예제 #9
0
    def test_get_homework(self):
        user1 = userhelper.given_a_user_exists()
        user2 = userhelper.given_a_user_exists_and_is_authenticated(
            self.client, username='******', email='*****@*****.**')
        course_group1 = coursegrouphelper.given_course_group_exists(user1)
        course_group2 = coursegrouphelper.given_course_group_exists(user2)
        course1 = coursehelper.given_course_exists(course_group1)
        course2 = coursehelper.given_course_exists(course_group2)
        course3 = coursehelper.given_course_exists(course_group2)
        homeworkhelper.given_homework_exists(course1)
        homeworkhelper.given_homework_exists(course2)
        homeworkhelper.given_homework_exists(course3)
        homeworkhelper.given_homework_exists(course3)

        # WHEN
        response1 = self.client.get(reverse('planner_homework_list'))
        response2 = self.client.get(
            reverse('planner_coursegroups_courses_homework_list',
                    kwargs={
                        'course_group': course_group2.pk,
                        'course': course3.pk
                    }))

        # THEN
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
        self.assertEqual(Homework.objects.count(), 4)
        self.assertEqual(len(response1.data), 3)
        self.assertEqual(len(response2.data), 2)
예제 #10
0
    def test_create_homework_attachment(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)
        tmp_file = attachmenthelper.given_file_exists()

        # WHEN
        with open(tmp_file.name) as fp:
            data = {'homework': homework.pk, 'file[]': [fp]}
            response = self.client.post(reverse('planner_attachments_list'),
                                        data)

        # THEN
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['title'],
                         os.path.basename(tmp_file.name))
        self.assertEqual(response.data[0]['size'],
                         os.path.getsize(tmp_file.name))
        self.assertEqual(response.data[0]['homework'], data['homework'])
        self.assertEqual(Attachment.objects.count(), 1)
        attachment = Attachment.objects.get(pk=response.data[0]['id'])
        attachmenthelper.verify_attachment_matches_data(
            self, attachment, response.data[0])
예제 #11
0
    def test_create_homework_reminder(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        data = {
            'title': 'some title',
            'message': 'some message',
            'offset': 1,
            'offset_type': enums.HOURS,
            'type': enums.POPUP,
            'homework': homework.pk,
            # Read-only fields, unused in the POST but used in the validation of this dict afterward
            'start_of_range':
            (homework.start - timedelta(hours=1)).isoformat(),
            'sent': False,
            'user': user.pk
        }
        response = self.client.post(reverse('planner_reminders_list'),
                                    json.dumps(data),
                                    content_type='application/json')

        # THEN
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Reminder.objects.count(), 1)
        reminder = Reminder.objects.get(pk=response.data['id'])
        reminderhelper.verify_reminder_matches_data(self, reminder, data)
        reminderhelper.verify_reminder_matches_data(self, reminder,
                                                    response.data)
예제 #12
0
    def test_patch_converts_to_utc(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        data = {
            'start': '2016-05-08T12:00:00-0500',
            'end': '2016-05-08T14:00:00-0500',
        }
        response = self.client.patch(reverse(
            'planner_coursegroups_courses_homework_detail',
            kwargs={
                'course_group': course_group.pk,
                'course': course.pk,
                'pk': homework.pk
            }),
                                     json.dumps(data),
                                     content_type='application/json')

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        homework = Homework.objects.get(pk=homework.pk)
        self.assertEquals(
            homework.start.isoformat(),
            parser.parse(data['start']).astimezone(timezone.utc).isoformat())
        self.assertEquals(
            homework.end.isoformat(),
            parser.parse(data['end']).astimezone(timezone.utc).isoformat())
예제 #13
0
    def test_patch_assumes_naive_datetime_to_utc(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        user.settings.time_zone = 'America/New_York'
        user.settings.save()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        data = {
            'start': '2016-05-08 12:00:00',
            'end': '2016-05-08 14:00:00',
        }
        response = self.client.patch(reverse(
            'planner_coursegroups_courses_homework_detail',
            kwargs={
                'course_group': course_group.pk,
                'course': course.pk,
                'pk': homework.pk
            }),
                                     json.dumps(data),
                                     content_type='application/json')

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        homework = Homework.objects.get(pk=homework.pk)

        start = timezone.make_aware(parser.parse(data['start']), timezone.utc)
        end = timezone.make_aware(parser.parse(data['end']), timezone.utc)
        self.assertEquals(homework.start.isoformat(), start.isoformat())
        self.assertEquals(homework.end.isoformat(), end.isoformat())
예제 #14
0
    def test_related_field_owned_by_another_user_forbidden(self):
        # GIVEN
        user1 = userhelper.given_a_user_exists_and_is_authenticated(
            self.client)
        user2 = userhelper.given_a_user_exists(username='******',
                                               email='*****@*****.**')
        event1 = eventhelper.given_event_exists(user1)
        event2 = eventhelper.given_event_exists(user2)
        reminder = reminderhelper.given_reminder_exists(user1, event=event1)
        course_group2 = coursegrouphelper.given_course_group_exists(user2)
        course2 = coursehelper.given_course_exists(course_group2)
        homework2 = homeworkhelper.given_homework_exists(course2)

        # WHEN
        responses = [
            self.client.post(reverse('planner_reminders_list'),
                             json.dumps({'event': event2.pk}),
                             content_type='application/json'),
            self.client.post(reverse('planner_reminders_list'),
                             json.dumps({'homework': homework2.pk}),
                             content_type='application/json'),
            self.client.put(reverse('planner_reminders_detail',
                                    kwargs={'pk': reminder.pk}),
                            json.dumps({'event': event2.pk}),
                            content_type='application/json'),
            self.client.put(reverse('planner_reminders_detail',
                                    kwargs={'pk': reminder.pk}),
                            json.dumps({'homework': homework2.pk}),
                            content_type='application/json')
        ]

        # THEN
        for response in responses:
            self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
예제 #15
0
    def test_update_start_before_end_fails(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        data = {
            'start': '2016-05-08T12:00:00Z',
            'end': '2016-05-07T14:00:00Z',
        }
        response = self.client.patch(reverse(
            'planner_coursegroups_courses_homework_detail',
            kwargs={
                'course_group': course_group.pk,
                'course': course.pk,
                'pk': homework.pk
            }),
                                     json.dumps(data),
                                     content_type='application/json')

        # THEN
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('must be before', response.data['non_field_errors'][0])
예제 #16
0
    def test_update_invalid_fraction_fails(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        response1 = self.client.patch(
            reverse('planner_coursegroups_courses_homework_detail',
                    kwargs={
                        'course_group': course_group.pk,
                        'course': course.pk,
                        'pk': homework.pk
                    }),
            json.dumps({'current_grade': 'not-a-fraction'}),
            content_type='application/json')
        response2 = self.client.patch(
            reverse('planner_coursegroups_courses_homework_detail',
                    kwargs={
                        'course_group': course_group.pk,
                        'course': course.pk,
                        'pk': homework.pk
                    }),
            json.dumps({'current_grade': 'invalid/4'}),
            content_type='application/json')

        # THEN
        self.assertEqual(response1.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response2.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIn('current_grade', response1.data)
        self.assertIn('current_grade', response2.data)
예제 #17
0
    def test_incomplete_not_graded(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course)
        categoryhelper.given_category_exists(course, title='Test Category 2')

        # WHEN
        homework1 = homeworkhelper.given_homework_exists(
            course, category=category1, current_grade='50/100')
        homeworkhelper.given_homework_exists(course,
                                             category=category1,
                                             completed=True,
                                             current_grade='100/100')

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        course = Course.objects.get(pk=course.pk)
        category = Category.objects.get(pk=category1.pk)
        self.assertEqual(float(course_group.average_grade), 100)
        self.assertEqual(float(course.current_grade), 100)
        self.assertEqual(float(category.average_grade), 100)

        # WHEN
        homework1.completed = True
        homework1.save()

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        course = Course.objects.get(pk=course.pk)
        category = Category.objects.get(pk=category1.pk)
        self.assertEqual(float(course_group.average_grade), 75)
        self.assertEqual(float(course.current_grade), 75)
        self.assertEqual(float(category.average_grade), 75)

        # WHEN
        homework1.completed = False
        homework1.save()

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        course = Course.objects.get(pk=course.pk)
        category = Category.objects.get(pk=category1.pk)
        self.assertEqual(float(course_group.average_grade), 100)
        self.assertEqual(float(course.current_grade), 100)
        self.assertEqual(float(category.average_grade), 100)
    def test_get_attachments(self):
        # GIVEN
        user1 = userhelper.given_a_user_exists()
        user2 = userhelper.given_a_user_exists_and_is_authenticated(
            self.client, username='******', email='*****@*****.**')
        event1 = eventhelper.given_event_exists(user1)
        event2 = eventhelper.given_event_exists(user2)
        course_group1 = coursegrouphelper.given_course_group_exists(user1)
        course_group2 = coursegrouphelper.given_course_group_exists(user2)
        course1 = coursehelper.given_course_exists(course_group1)
        course2 = coursehelper.given_course_exists(course_group2)
        course3 = coursehelper.given_course_exists(course_group2)
        homework1 = homeworkhelper.given_homework_exists(course1)
        homework2 = homeworkhelper.given_homework_exists(course2)
        attachmenthelper.given_attachment_exists(user1, course=course1)
        attachmenthelper.given_attachment_exists(user2, course=course2)
        attachmenthelper.given_attachment_exists(user2, course=course3)
        attachmenthelper.given_attachment_exists(user2, course=course3)
        attachmenthelper.given_attachment_exists(user1, event=event1)
        attachmenthelper.given_attachment_exists(user2, event=event2)
        attachmenthelper.given_attachment_exists(user2, event=event2)
        attachmenthelper.given_attachment_exists(user1, homework=homework1)
        attachmenthelper.given_attachment_exists(user2, homework=homework2)
        attachmenthelper.given_attachment_exists(user2, homework=homework2)

        # WHEN
        response1 = self.client.get(reverse('planner_attachments_list'))
        response2 = self.client.get(
            reverse('planner_attachments_list') +
            '?course={}'.format(course3.pk))
        response3 = self.client.get(
            reverse('planner_attachments_list') +
            '?event={}'.format(event2.pk))
        response4 = self.client.get(
            reverse('planner_attachments_list') +
            '?homework={}'.format(homework2.pk))

        # THEN
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
        self.assertEqual(response3.status_code, status.HTTP_200_OK)
        self.assertEqual(response4.status_code, status.HTTP_200_OK)
        self.assertEqual(Attachment.objects.count(), 10)
        self.assertEqual(len(response1.data), 7)
        self.assertEqual(len(response2.data), 2)
        self.assertEqual(len(response3.data), 2)
        self.assertEqual(len(response4.data), 2)
예제 #19
0
    def test_unweighted_grade_unchanged(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category = categoryhelper.given_category_exists(course)

        # WHEN
        homeworkhelper.given_homework_exists(course, category=category, current_grade='-1/100')

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        course = Course.objects.get(pk=course.pk)
        category = Category.objects.get(pk=category.pk)
        self.assertEqual(course_group.average_grade, -1)
        self.assertEqual(course.current_grade, -1)
        self.assertEqual(category.average_grade, -1)
예제 #20
0
    def test_access_object_owned_by_another_user(self):
        # GIVEN
        user1 = userhelper.given_a_user_exists()
        userhelper.given_a_user_exists_and_is_authenticated(
            self.client, username='******', email='*****@*****.**')
        course_group = coursegrouphelper.given_course_group_exists(user1)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        responses = [
            self.client.get(
                reverse('planner_coursegroups_courses_homework_list',
                        kwargs={
                            'course_group': course_group.pk,
                            'course': course.pk
                        })),
            self.client.post(
                reverse('planner_coursegroups_courses_homework_list',
                        kwargs={
                            'course_group': course_group.pk,
                            'course': course.pk
                        })),
            self.client.get(
                reverse('planner_coursegroups_courses_homework_detail',
                        kwargs={
                            'course_group': course_group.pk,
                            'course': course.pk,
                            'pk': homework.pk
                        })),
            self.client.put(
                reverse('planner_coursegroups_courses_homework_detail',
                        kwargs={
                            'course_group': course_group.pk,
                            'course': course.pk,
                            'pk': homework.pk
                        })),
            self.client.delete(
                reverse('planner_coursegroups_courses_homework_detail',
                        kwargs={
                            'course_group': course_group.pk,
                            'course': course.pk,
                            'pk': homework.pk
                        }))
        ]

        # THEN
        self.assertTrue(
            Homework.objects.for_user(
                user1.pk).filter(pk=homework.pk).exists())
        for response in responses:
            if isinstance(response.data, list):
                self.assertEqual(response.status_code, status.HTTP_200_OK)
                self.assertEqual(len(response.data), 0)
            else:
                self.assertEqual(response.status_code,
                                 status.HTTP_404_NOT_FOUND)
예제 #21
0
    def test_range_query(self):
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework1 = homeworkhelper.given_homework_exists(
            course,
            start=datetime.datetime(2017, 5, 8, 16, 0, 0, tzinfo=timezone.utc),
            end=datetime.datetime(2017, 5, 8, 17, 0, 0, tzinfo=timezone.utc))
        homework2 = homeworkhelper.given_homework_exists(
            course,
            start=timezone.now() + timedelta(days=1),
            end=timezone.now() + timedelta(days=1, minutes=30))
        reminderhelper.given_reminder_exists(user, homework=homework1)
        reminderhelper.given_reminder_exists(user, homework=homework2)

        response = self.client.get(
            reverse('planner_reminders_list') +
            f'?start_of_range__lte={quote(timezone.now().isoformat())}')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
예제 #22
0
    def test_range_query(self):
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homeworkhelper.given_homework_exists(
            course,
            start=datetime.datetime(2017, 5, 8, 16, 0, 0, tzinfo=timezone.utc),
            end=datetime.datetime(2017, 5, 8, 17, 0, 0, tzinfo=timezone.utc))
        homework2 = homeworkhelper.given_homework_exists(
            course,
            start=datetime.datetime(2017, 5, 8, 17, 0, 0, tzinfo=timezone.utc),
            end=datetime.datetime(2017, 5, 8, 18, 0, 0, tzinfo=timezone.utc))
        homeworkhelper.given_homework_exists(
            course,
            start=datetime.datetime(2017, 5, 8, 18, 30, 0,
                                    tzinfo=timezone.utc),
            end=datetime.datetime(2017, 5, 8, 19, 0, 0, tzinfo=timezone.utc))
        homework4 = homeworkhelper.given_homework_exists(
            course,
            start=datetime.datetime(2017, 5, 8, 19, 30, 0,
                                    tzinfo=timezone.utc),
            end=datetime.datetime(2017, 5, 8, 21, 0, 0, tzinfo=timezone.utc))

        response = self.client.get(
            reverse('planner_homework_list') +
            '?start__gte={}&end__lt={}'.format(
                quote(homework2.start.isoformat()),
                quote(homework4.end.isoformat())))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)
예제 #23
0
    def test_trend_negative(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category = categoryhelper.given_category_exists(course)

        # WHEN
        homeworkhelper.given_homework_exists(course, category=category, completed=True,
                                             start=datetime.datetime(2017, 4, 8, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 8, 20, 30, tzinfo=pytz.utc),
                                             current_grade='400/100')
        homeworkhelper.given_homework_exists(course, category=category, completed=True,
                                             start=datetime.datetime(2017, 4, 9, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 9, 20, 30, tzinfo=pytz.utc),
                                             current_grade='200/100')
        homeworkhelper.given_homework_exists(course, category=category, completed=True,
                                             start=datetime.datetime(2017, 4, 10, 20, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 10, 20, 30, tzinfo=pytz.utc),
                                             current_grade='0/100')

        # THEN
        course_group = CourseGroup.objects.get(pk=course_group.pk)
        course = Course.objects.get(pk=course.pk)
        category = Category.objects.get(pk=category.pk)
        self.assertEqual(float(course_group.trend), -1)
        self.assertEqual(float(course.trend), -1)
        self.assertEqual(float(category.trend), -1)
예제 #24
0
    def test_get_category_by_id(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category = categoryhelper.given_category_exists(course)
        homeworkhelper.given_homework_exists(course, category=category)
        homeworkhelper.given_homework_exists(course,
                                             completed=True,
                                             category=category)
        homeworkhelper.given_homework_exists(course,
                                             completed=True,
                                             current_grade='25/30',
                                             category=category)

        # WHEN
        response = self.client.get(
            reverse('planner_coursegroups_courses_categories_detail',
                    kwargs={
                        'course_group': course_group.pk,
                        'course': course.pk,
                        'pk': category.pk
                    }))

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        category = Category.objects.get(pk=category.pk)
        categoryhelper.verify_category_matches_data(self, category,
                                                    response.data)
        self.assertEqual(response.data['num_homework'], 3)
        self.assertEqual(response.data['num_homework_graded'], 1)
예제 #25
0
    def test_get_reminders(self):
        user1 = userhelper.given_a_user_exists()
        user2 = userhelper.given_a_user_exists_and_is_authenticated(
            self.client, username='******', email='*****@*****.**')
        event1 = eventhelper.given_event_exists(user1)
        event2 = eventhelper.given_event_exists(user2)
        course_group1 = coursegrouphelper.given_course_group_exists(user1)
        course_group2 = coursegrouphelper.given_course_group_exists(user2)
        course1 = coursehelper.given_course_exists(course_group1)
        course2 = coursehelper.given_course_exists(course_group2)
        course3 = coursehelper.given_course_exists(course_group2)
        homework1 = homeworkhelper.given_homework_exists(course1)
        homework2 = homeworkhelper.given_homework_exists(course2)
        homework3 = homeworkhelper.given_homework_exists(course3)
        homework4 = homeworkhelper.given_homework_exists(course3)
        reminderhelper.given_reminder_exists(user1, homework=homework1)
        reminderhelper.given_reminder_exists(user2, homework=homework2)
        reminderhelper.given_reminder_exists(user2, homework=homework3)
        reminderhelper.given_reminder_exists(user2, homework=homework4)
        reminderhelper.given_reminder_exists(user2, homework=homework4)
        reminderhelper.given_reminder_exists(user1, event=event1)
        reminderhelper.given_reminder_exists(user2, event=event2)
        reminderhelper.given_reminder_exists(user2, event=event2)

        # WHEN
        response1 = self.client.get(reverse('planner_reminders_list'))
        response2 = self.client.get(
            reverse('planner_reminders_list') + f'?homework={homework4.pk}')
        response3 = self.client.get(
            reverse('planner_reminders_list') + f'?event={event2.pk}')

        # THEN
        self.assertEqual(response1.status_code, status.HTTP_200_OK)
        self.assertEqual(response2.status_code, status.HTTP_200_OK)
        self.assertEqual(response3.status_code, status.HTTP_200_OK)
        self.assertEqual(Reminder.objects.count(), 8)
        self.assertEqual(len(response1.data), 6)
        self.assertEqual(len(response2.data), 2)
        self.assertEqual(len(response3.data), 2)
예제 #26
0
    def test_weight_graded_points(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course, weight=30)
        category2 = categoryhelper.given_category_exists(course, title='Test Category 2', weight=50)
        category3 = categoryhelper.given_category_exists(course, title='Test Category 3', weight=20)
        homework1 = homeworkhelper.given_homework_exists(course, category=category1, completed=True,
                                                         start=datetime.datetime(2017, 4, 8, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 8, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='25/100')
        homework2 = homeworkhelper.given_homework_exists(course, category=category2, completed=True,
                                                         start=datetime.datetime(2017, 4, 9, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 9, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='75/100')
        homework3 = homeworkhelper.given_homework_exists(course, category=category3, completed=True,
                                                         start=datetime.datetime(2017, 4, 10, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 10, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='50/100')
        homework4 = homeworkhelper.given_homework_exists(course, category=category1, completed=True,
                                                         start=datetime.datetime(2017, 4, 11, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 11, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='60/80')
        homework5 = homeworkhelper.given_homework_exists(course, category=category3,
                                                         start=datetime.datetime(2017, 4, 12, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 12, 20, 30, tzinfo=pytz.utc),
                                                         completed=True, current_grade='4/5')
        # Incomplete homework are not graded
        homeworkhelper.given_homework_exists(course, category=category1,
                                             start=datetime.datetime(2017, 4, 8, 21, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 8, 21, 30, tzinfo=pytz.utc),
                                             current_grade='80/100')

        # WHEN
        grade_points = gradingservice.get_grade_points_for_course(course.pk)

        # THEN
        self.assertEqual(len(grade_points), 5)
        # ((25 * 30)) / 30
        self.assertEqual(grade_points[0], [homework1.start, 25])
        # ((25 * 30) + (75 * 50)) / 80
        self.assertEqual(grade_points[1], [homework2.start, 56.25])
        # ((25 * 30) + (75 * 50) + (50 * 20)) / 100
        self.assertEqual(grade_points[2], [homework3.start, 55])
        # ((25 * 30) + (75 * 50) + (50 * 20) + ((60/80) * 30)) / 100
        self.assertEqual(grade_points[3], [homework4.start, 59.6154])
        # ((25 * 30) + (75 * 50) + (50 * 20) + ((60/80) * 30) + ((4/5) * 10)) / 100
        self.assertEqual(grade_points[4], [homework5.start, 62.3333])
예제 #27
0
    def test_unweight_graded_points(self):
        # GIVEN
        user = userhelper.given_a_user_exists()
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course)
        category2 = categoryhelper.given_category_exists(course, title='Test Category 2')
        category3 = categoryhelper.given_category_exists(course, title='Test Category 3')
        homework1 = homeworkhelper.given_homework_exists(course, category=category1, completed=True,
                                                         start=datetime.datetime(2017, 4, 8, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 8, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='25/100')
        homework2 = homeworkhelper.given_homework_exists(course, category=category2, completed=True,
                                                         start=datetime.datetime(2017, 4, 9, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 9, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='75/100')
        homework3 = homeworkhelper.given_homework_exists(course, category=category3, completed=True,
                                                         start=datetime.datetime(2017, 4, 10, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 10, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='50/100')
        homework4 = homeworkhelper.given_homework_exists(course, category=category1, completed=True,
                                                         start=datetime.datetime(2017, 4, 11, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 11, 20, 30, tzinfo=pytz.utc),
                                                         current_grade='60/80')
        homework5 = homeworkhelper.given_homework_exists(course, category=category3,
                                                         start=datetime.datetime(2017, 4, 12, 20, 0, tzinfo=pytz.utc),
                                                         end=datetime.datetime(2017, 4, 12, 20, 30, tzinfo=pytz.utc),
                                                         completed=True, current_grade='4/5')
        # Incomplete homework are not graded
        homeworkhelper.given_homework_exists(course, category=category1,
                                             start=datetime.datetime(2017, 4, 8, 21, 0, tzinfo=pytz.utc),
                                             end=datetime.datetime(2017, 4, 8, 21, 30, tzinfo=pytz.utc),
                                             current_grade='80/100')

        # WHEN
        grade_points = gradingservice.get_grade_points_for_course(course.pk)

        # THEN
        self.assertEqual(len(grade_points), 5)
        # (25) / 1
        self.assertEqual(grade_points[0], [homework1.start, 25])
        # (25 + 75) / 2
        self.assertEqual(grade_points[1], [homework2.start, 50])
        # (25 + 75 + 50) / 3
        self.assertEqual(grade_points[2], [homework3.start, 50])
        # (25 + 75 + 50 + (60/80)) / 4
        self.assertEqual(grade_points[3], [homework4.start, 55.2632])
        # (25 + 75 + 50 + (60/80) + (4/5)) / 5
        self.assertEqual(grade_points[4], [homework5.start, 55.5844])
예제 #28
0
    def test_update_homework_by_id(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        category1 = categoryhelper.given_category_exists(course)
        category2 = categoryhelper.given_category_exists(
            course, title='Test Category 2')
        material_group = materialgrouphelper.given_material_group_exists(user)
        material1 = materialhelper.given_material_exists(material_group)
        material2 = materialhelper.given_material_exists(material_group)
        homework = homeworkhelper.given_homework_exists(course,
                                                        category=category1,
                                                        materials=[material1])

        # WHEN
        data = {
            'title': 'some title',
            'all_day': True,
            'show_end_time': False,
            'start': '2016-05-08T12:00:00Z',
            'end': '2016-05-08T14:00:00Z',
            'priority': 12,
            'comments': 'some comment',
            'current_grade': '33/40',
            'completed': True,
            'category': category2.pk,
            'materials': [material2.pk],
            'course': course.pk
        }
        response = self.client.put(reverse(
            'planner_coursegroups_courses_homework_detail',
            kwargs={
                'course_group': course_group.pk,
                'course': course.pk,
                'pk': homework.pk
            }),
                                   json.dumps(data),
                                   content_type='application/json')

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertDictContainsSubset(data, response.data)
        homework = Homework.objects.get(pk=homework.pk)
        homeworkhelper.verify_homework_matches_data(self, homework,
                                                    response.data)
예제 #29
0
    def test_access_object_owned_by_another_user(self):
        # GIVEN
        user1 = userhelper.given_a_user_exists()
        userhelper.given_a_user_exists_and_is_authenticated(
            self.client, username='******', email='*****@*****.**')
        event = eventhelper.given_event_exists(user1)
        event_reminder = reminderhelper.given_reminder_exists(user1,
                                                              event=event)
        course_group = coursegrouphelper.given_course_group_exists(user1)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)
        reminderhelper.given_reminder_exists(user1, homework=homework)

        # WHEN
        responses = [
            self.client.get(
                reverse('planner_reminders_list') + f'?event={event.pk}'),
            self.client.get(
                reverse('planner_reminders_list') +
                f'?homework={homework.pk}'),
            self.client.get(
                reverse('planner_reminders_detail',
                        kwargs={'pk': event_reminder.pk})),
            self.client.put(
                reverse('planner_reminders_detail',
                        kwargs={'pk': event_reminder.pk})),
            self.client.delete(
                reverse('planner_reminders_detail',
                        kwargs={'pk': event_reminder.pk}))
        ]

        # THEN
        self.assertTrue(
            Reminder.objects.filter(pk=event_reminder.pk,
                                    user_id=user1.pk).exists())
        for response in responses:
            if isinstance(response.data, list):
                self.assertEqual(response.status_code, status.HTTP_200_OK)
                self.assertEqual(len(response.data), 0)
            else:
                self.assertEqual(response.status_code,
                                 status.HTTP_404_NOT_FOUND)
예제 #30
0
    def test_delete_homework_by_id(self):
        # GIVEN
        user = userhelper.given_a_user_exists_and_is_authenticated(self.client)
        course_group = coursegrouphelper.given_course_group_exists(user)
        course = coursehelper.given_course_exists(course_group)
        homework = homeworkhelper.given_homework_exists(course)

        # WHEN
        response = self.client.delete(
            reverse('planner_coursegroups_courses_homework_detail',
                    kwargs={
                        'course_group': course_group.pk,
                        'course': course.pk,
                        'pk': homework.pk
                    }))

        # THEN
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertFalse(Homework.objects.filter(pk=homework.pk).exists())
        self.assertEqual(Homework.objects.count(), 0)