def test_get_materialgroup_by_id(self): # GIVEN user = userhelper.given_a_user_exists_and_is_authenticated(self.client) material_group = materialgrouphelper.given_material_group_exists(user) # WHEN response = self.client.get(reverse('planner_materialgroups_detail', kwargs={'pk': material_group.pk})) # THEN self.assertEqual(response.status_code, status.HTTP_200_OK) materialgrouphelper.verify_material_group_matches_data(self, material_group, response.data)
def test_create_materialgroup(self): # GIVEN user = userhelper.given_a_user_exists_and_is_authenticated(self.client) # WHEN data = { 'title': 'some title', 'shown_on_calendar': False, } response = self.client.post(reverse('planner_materialgroups_list'), json.dumps(data), content_type='application/json') # THEN self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(MaterialGroup.objects.count(), 1) material_group = MaterialGroup.objects.get(pk=response.data['id']) data.update({'user': user.pk}) materialgrouphelper.verify_material_group_matches_data(self, material_group, data) materialgrouphelper.verify_material_group_matches_data(self, material_group, response.data)
def test_update_materialgroup_by_id(self): # GIVEN user = userhelper.given_a_user_exists_and_is_authenticated(self.client) material_group = materialgrouphelper.given_material_group_exists(user) self.assertEqual(material_group.title, 'Test Material Group') self.assertTrue(material_group.shown_on_calendar) # WHEN data = { 'title': 'new title', 'shown_on_calendar': False } response = self.client.put(reverse('planner_materialgroups_detail', kwargs={'pk': material_group.pk}), json.dumps(data), content_type='application/json') # THEN self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertDictContainsSubset(data, response.data) material_group = MaterialGroup.objects.get(pk=material_group.pk) materialgrouphelper.verify_material_group_matches_data(self, material_group, response.data)
def test_import_success(self): # GIVEN user = userhelper.given_a_user_exists_and_is_authenticated(self.client) # WHEN with open( os.path.join(os.path.dirname(__file__), os.path.join('../../resources', 'sample.json'))) as fp: data = {'file[]': [fp]} self.client.post(reverse('importexport_resource_import'), data) # We are intentionally uploading this file twice so that, in the case of unit tests, the key IDs do not line # up and the remapping is properly tested with open( os.path.join(os.path.dirname(__file__), os.path.join('../../resources', 'sample.json'))) as fp: data = {'file[]': [fp]} response = self.client.post( reverse('importexport_resource_import'), data) # THEN self.assertEqual(response.status_code, status.HTTP_200_OK) external_calendars = ExternalCalendar.objects.all() course_groups = CourseGroup.objects.all() courses = Course.objects.all() course_schedules = CourseSchedule.objects.all() categories = Category.objects.all() material_groups = MaterialGroup.objects.all() materials = Material.objects.all() events = Event.objects.all() homework = Homework.objects.all() reminders = Reminder.objects.all() self.assertEqual(len(external_calendars), 2) self.assertEqual(len(course_groups), 4) self.assertEqual(len(courses), 4) self.assertEqual(len(course_schedules), 4) self.assertEqual(len(categories), 4) self.assertEqual(len(material_groups), 2) self.assertEqual(len(materials), 2) self.assertEqual(len(events), 4) self.assertEqual(len(homework), 4) self.assertEqual(len(reminders), 4) externalcalendarhelper.verify_externalcalendar_matches_data( self, external_calendars[1], { 'id': 2, 'title': 'My Calendar', 'url': 'http://go.com/valid-ical-feed', 'color': '#fad165', 'shown_on_calendar': False, 'user': user.pk }) coursegrouphelper.verify_course_group_matches_data( self, course_groups[2], { 'average_grade': 66.6667, 'start_date': '2017-01-06', 'end_date': '2017-05-08', 'private_slug': None, 'shown_on_calendar': True, 'title': 'Test Course Group', 'trend': None, 'user': user.pk }) coursegrouphelper.verify_course_group_matches_data( self, course_groups[3], { 'average_grade': -1.0, 'start_date': '2017-01-06', 'end_date': '2017-05-08', 'private_slug': None, 'shown_on_calendar': True, 'title': 'Test Course Group', 'trend': None, 'user': user.pk }) coursehelper.verify_course_matches_data( self, courses[2], { 'title': 'Test Course', 'room': '', 'credits': 5.0, 'color': '#4986e7', 'website': 'http://mycourse.com', 'is_online': False, 'current_grade': 66.6667, 'trend': None, 'private_slug': None, 'teacher_name': 'My Teacher', 'teacher_email': '*****@*****.**', 'start_date': '2017-01-06', 'end_date': '2017-05-08', 'course_group': course_groups[2].pk }) coursehelper.verify_course_matches_data( self, courses[3], { 'title': 'Test Course', 'room': 'DNC 201', 'credits': 5.0, 'color': '#4986e7', 'website': 'http://mycourse.com', 'is_online': False, 'current_grade': -1.0, 'trend': None, 'private_slug': None, 'teacher_name': 'My Teacher', 'teacher_email': '*****@*****.**', 'start_date': '2017-01-06', 'end_date': '2017-05-08', 'course_group': course_groups[3].pk }) courseschedulehelper.verify_course_schedule_matches( self, course_schedules[2], { 'days_of_week': '0101010', 'sun_start_time': '12:00:00', 'sun_end_time': '12:00:00', 'mon_start_time': '2:30:00', 'mon_end_time': '3:00:00', 'tue_start_time': '12:00:00', 'tue_end_time': '12:00:00', 'wed_start_time': '2:30:00', 'wed_end_time': '3:00:00', 'thu_start_time': '12:00:00', 'thu_end_time': '12:00:00', 'fri_start_time': '2:30:00', 'fri_end_time': '5:00:00', 'sat_start_time': '12:00:00', 'sat_end_time': '12:00:00', 'course': courses[2].pk }) courseschedulehelper.verify_course_schedule_matches( self, course_schedules[3], { 'days_of_week': '0101010', 'sun_start_time': '12:00:00', 'sun_end_time': '12:00:00', 'mon_start_time': '2:30:00', 'mon_end_time': '3:00:00', 'tue_start_time': '12:00:00', 'tue_end_time': '12:00:00', 'wed_start_time': '2:30:00', 'wed_end_time': '3:00:00', 'thu_start_time': '12:00:00', 'thu_end_time': '12:00:00', 'fri_start_time': '2:30:00', 'fri_end_time': '5:00:00', 'sat_start_time': '12:00:00', 'sat_end_time': '12:00:00', 'course': courses[3].pk }) categoryhelper.verify_category_matches_data( self, categories[1], { 'title': 'Test Category 1', 'weight': 0.0, 'color': '#4986e7', 'average_grade': -1.0, 'grade_by_weight': 0.0, 'trend': None, 'course': courses[3].pk }) categoryhelper.verify_category_matches_data( self, categories[3], { 'title': 'Uncategorized', 'weight': 0.0, 'color': '#4986e7', 'average_grade': 66.6667, 'grade_by_weight': 0.0, 'trend': None, 'course': courses[2].pk }) materialgrouphelper.verify_material_group_matches_data( self, material_groups[1], { 'title': 'Test Material Group', 'shown_on_calendar': True, 'user': user.pk }) materialhelper.verify_material_matches_data( self, materials[1], { 'title': 'Test Material', 'status': 3, 'condition': 7, 'website': 'http://www.material.com', 'price': '9.99', 'details': 'Return by 7/1', 'material_group': material_groups[1].pk, 'courses': [] }) eventhelper.verify_event_matches_data( self, events[2], { 'title': 'Test Event', 'all_day': False, 'show_end_time': True, 'start': '2017-05-08T12:00:00Z', 'end': '2017-05-08T14:00:00Z', 'priority': 75, 'url': None, 'comments': 'A comment on an event.', 'owner_id': None, 'user': user.pk }) eventhelper.verify_event_matches_data( self, events[3], { 'title': 'Test Event', 'all_day': False, 'show_end_time': True, 'start': '2017-05-08T12:00:00Z', 'end': '2017-05-08T14:00:00Z', 'priority': 75, 'url': None, 'comments': 'A comment on an event.', 'owner_id': None, 'user': user.pk }) homeworkhelper.verify_homework_matches_data( self, homework[2], { 'title': 'Test Homework', 'all_day': False, 'show_end_time': True, 'start': '2017-05-08T16:00:00Z', 'end': '2017-05-08T18:00:00Z', 'priority': 65, 'url': None, 'comments': 'A comment on a homework.', 'current_grade': '20/30', 'completed': True, 'category': categories[3].pk, 'course': courses[2].pk, 'materials': [materials[1].pk] }) homeworkhelper.verify_homework_matches_data( self, homework[3], { 'title': 'Test Homework', 'all_day': False, 'show_end_time': True, 'start': '2017-05-08T16:00:00Z', 'end': '2017-05-08T18:00:00Z', 'priority': 65, 'url': None, 'comments': 'A comment on a homework.', 'current_grade': '-1/100', 'completed': False, 'category': categories[1].pk, 'course': courses[3].pk, 'materials': [] }) reminderhelper.verify_reminder_matches_data( self, reminders[2], { 'id': 1, 'title': 'Test Homework Reminder', 'message': 'You need to do something now.', 'start_of_range': '2017-05-08T15:45:00Z', 'offset': 15, 'offset_type': 0, 'type': 2, 'sent': False, 'homework': homework[0].pk, 'event': None, 'user': user.pk }) reminderhelper.verify_reminder_matches_data( self, reminders[3], { 'id': 3, 'title': 'Test Homework Reminder', 'message': 'You need to do something now.', 'start_of_range': '2017-05-08T15:45Z', 'offset': 15, 'offset_type': 0, 'type': 2, 'sent': False, 'homework': homework[2].pk, 'event': None, 'user': user.pk })