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])
def test_create_course_schedule(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) # WHEN data = { 'days_of_week': '0101010', 'mon_start_time': '14:30:00', 'mon_end_time': '15:30:00', 'wed_start_time': '14:30:00', 'wed_end_time': '15:30:00', 'fri_start_time': '14:30:00', 'fri_end_time': '15:30:00', # These fields are set to their defaults 'sun_start_time': '12:00:00', 'sun_end_time': '12:00:00', 'tue_start_time': '12:00:00', 'tue_end_time': '12:00:00', 'thu_start_time': '12:00:00', 'thu_end_time': '12:00:00', 'sat_start_time': '12:00:00', 'sat_end_time': '12:00:00', 'course': course.pk, } response = self.client.post(reverse( 'planner_coursegroups_courses_courseschedules_list', kwargs={ 'course_group': course_group.pk, 'course': course.pk }), json.dumps(data), content_type='application/json') # THEN self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(CourseSchedule.objects.count(), 1) course_schedule = CourseSchedule.objects.get(pk=response.data['id']) courseschedulehelper.verify_course_schedule_matches( self, course_schedule, data) courseschedulehelper.verify_course_schedule_matches( self, course_schedule, response.data)
def test_update_course_schedule_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) course_schedule = courseschedulehelper.given_course_schedule_exists( course) # WHEN data = { 'days_of_week': '0001000', 'wed_start_time': '18:30:00', 'wed_end_time': '19:30:00', # These fields are set to their defaults 'sun_start_time': '12:00:00', 'sun_end_time': '12:00:00', 'mon_start_time': '12:00:00', 'mon_end_time': '12:00:00', 'tue_start_time': '12:00:00', 'tue_end_time': '12:00:00', 'thu_start_time': '12:00:00', 'thu_end_time': '12:00:00', 'fri_start_time': '12:00:00', 'fri_end_time': '12:00:00', 'sat_start_time': '12:00:00', 'sat_end_time': '12:00:00', } response = self.client.put(reverse( 'planner_coursegroups_courses_courseschedules_detail', kwargs={ 'course_group': course_group.pk, 'course': course.pk, 'pk': course_schedule.pk }), json.dumps(data), content_type='application/json') # THEN self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertDictContainsSubset(data, response.data) course_schedule = CourseSchedule.objects.get(pk=course_schedule.pk) courseschedulehelper.verify_course_schedule_matches( self, course_schedule, response.data)
def test_get_course_schedule_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) course_schedule = courseschedulehelper.given_course_schedule_exists( course) # WHEN response = self.client.get( reverse('planner_coursegroups_courses_courseschedules_detail', kwargs={ 'course_group': course_group.pk, 'course': course.pk, 'pk': course_schedule.pk })) # THEN self.assertEqual(response.status_code, status.HTTP_200_OK) course_schedule = CourseSchedule.objects.get(pk=course_schedule.pk) courseschedulehelper.verify_course_schedule_matches( self, course_schedule, 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 })