def setUp(self): # create test user with permissions self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) group = permissions.get_or_create_student_permissions() group.user_set.add(self.student_user) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) self.client.login(username=self.instructor_username, password=self.password) # populate test database self.course = Course(name='Bounty Hunting 101') self.course.save() self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term='before', enroll_key='4') self.group.save() self.student = Student(user=self.student_user, wwuid='9994141', labgroup=self.group) self.student.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() # retrieve the view self.view_name = 'api:assignment-lc'
def setUp(self): # create test user with permissions self.username = '******' self.password = '******' self.student_username = '******' self.instructor_user = User.objects.create_user(username=self.username, password=self.password) group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.client.login(username=self.username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='fact') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term='never', enroll_key='6') self.group.save() # retrieve the view self.view_name = 'api:student-lc'
def test_labgroup_visibility_instructor(self): """ Tests that labgroups displayed to instructor were created by that instructor """ # setup second instructor users self.instructor_username_2 = 'different_instructor' self.instructor_user_2 = User.objects.create_user(username=self.instructor_username_2, password=self.password) self.instructor_2 = Instructor(user=self.instructor_user_2, wwuid="7654321") self.instructor_2.save() # add labgroups to database LabGroup(course=self.course, instructor=self.instructor, group_name='test name 1', term=get_current_term(), enroll_key='test key 1').save() LabGroup(course=self.course, instructor=self.instructor_2, group_name='test name 2', term=get_current_term(), enroll_key='test key 2').save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response labgroups = LabGroup.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) # assert response_body contains exactly 1 labgroup self.assertEqual(len(response_body['labgroups']), 1)
def setUp(self): # create test user with permissions self.instructor_username = '******' self.student_username = '******' self.password = '******' self.instructor_user = User.objects.create_user(username=self.instructor_username, password=self.password) self.student_user = User.objects.create_user(username=self.student_username, password=self.password) self.instructor_user.groups.add(permissions.get_or_create_instructor_permissions()) self.student_user.groups.add(permissions.get_or_create_student_permissions()) self.client.login(username=self.instructor_username, password=self.password) # Create foreign keys self.instructor = Instructor(user=self.instructor_user, wwuid="1234567") self.instructor.save() self.course_1 = Course(name="test course 1") self.course_1.save() self.course_2 = Course(name="test course 2") self.course_2.save() # add labgroups to database self.labgroup_1 = LabGroup(course=self.course_1, instructor=self.instructor, term='test1', enroll_key='test key 1') self.labgroup_1.save() self.labgroup_2 = LabGroup(course=self.course_1, instructor=self.instructor, term='test2', enroll_key='test key 2') self.labgroup_2.save() self.labgroup_3 = LabGroup(course=self.course_1, instructor=self.instructor, term='test3', enroll_key='test key 3') self.labgroup_3.save() # retrieve the view self.view_name = 'api:lab-group-rud'
def setUp(self): # create test users self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) group = permissions.get_or_create_student_permissions() group.user_set.add(self.student_user) self.client.login(username=self.student_username, password=self.password) # populate the database self.student = Student(labgroup=None, user=self.student_user, wwuid='1111111') self.student.save() self.instructor = Instructor(user=self.instructor_user, wwuid='2222222') self.instructor.save() self.course = Course(name='test name') self.course.save() self.labgroup = LabGroup(course=self.course, instructor=self.instructor, group_name='A', term='FALL2018', enroll_key='ABC') self.labgroup.save() # retrieve the view self.view_name = 'api:enroll'
def setUp(self): # create test user with permissions and test student user self.instructor_username = '******' self.student_username_1 = 'test student 1' self.student_username_2 = 'test student 2' self.student_username_3 = 'test student 3' self.password = '******' self.student_user_1 = User.objects.create_user( username=self.student_username_1, password=self.password) self.student_user_2 = User.objects.create_user( username=self.student_username_2, password=self.password) self.student_user_3 = User.objects.create_user( username=self.student_username_3, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.instructor_user.user_permissions.add( Permission.objects.get(codename='change_student')) self.instructor_user.user_permissions.add( Permission.objects.get(codename='delete_student')) self.client.login(username=self.instructor_username, password=self.password) # populate database self.instructor = Instructor(user=self.instructor_user, wwuid='9999999') self.instructor.save() self.course = Course(name='test course') self.course.save() self.group_1 = LabGroup(course=self.course, instructor=self.instructor, term='never', enroll_key='6') self.group_1.save() self.group_2 = LabGroup(course=self.course, instructor=self.instructor, term='ever', enroll_key='8') self.group_2.save() self.student_1 = Student(user=self.student_user_1, labgroup=self.group_1, wwuid='1111111') self.student_1.save() self.student_2 = Student(user=self.student_user_2, labgroup=self.group_1, wwuid='2222222') self.student_2.save() self.student_3 = Student(user=self.student_user_3, labgroup=self.group_1, wwuid='3333333') self.student_3.save() # retrieve the view self.view_name = 'api:student-rud'
def setUp(self): # create test user with permissions self.username = '******' self.password = '******' self.user = User.objects.create_user(username=self.username, password=self.password) Instructor(user=self.user, wwuid='9999999').save() group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.user) self.client.login(username=self.username, password=self.password) # add courses and or templates to database self.course = Course(name="Astrophysics 820") self.course.save() self.template = AssignmentTemplate(name='Gravitational Vortices', course=self.course) self.template.save() self.template_2 = AssignmentTemplate(name='Cosmic Drift', course=self.course) self.template_2.save() self.task_template_1 = TaskTemplate(assignment_template=self.template, problem_num=1, summary='This is a summary.', prompt='This is the prompt1', prompt_format='CAF-citation', image_urls='all', attempts_allowed=1, numeric_accuracy=1, numeric_only=False) self.task_template_1.save() self.task_template_2 = TaskTemplate(assignment_template=self.template, problem_num=2, summary='This is a summary.', prompt='This is the prompt2', prompt_format='CAF-citation', image_urls='all', attempts_allowed=2, numeric_accuracy=2, numeric_only=False) self.task_template_2.save() self.task_template_3 = TaskTemplate(assignment_template=self.template, problem_num=3, summary='This is a summary.', prompt='This is the prompt3', prompt_format='SIGFIGS', image_urls='all', attempts_allowed=3, numeric_accuracy=3, numeric_only=True) self.task_template_3.save() # retrieve the view self.view_name = 'api:task-template-rud'
def test_assignment_list_instructor_does_not_own(self): """ Tests that assignments are properly listed. """ # create other instructor and labgroup user = User.objects.create_user(username='******', password='******') instructor = Instructor(wwuid='2027616', user=user) instructor.save() labgroup = LabGroup(course=self.course, instructor=instructor, term=get_current_term(), enroll_key='ABC') labgroup.save() # add assignments to database current_time = datetime.now(timezone(settings.TIME_ZONE)) assignment_1 = Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)) assignment_1.save() Assignment(assignment_template=self.template, labgroup=labgroup, open_date=current_time, close_date=current_time + timedelta(days=1)).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_body['assignments']), 1) self.assertEqual( response_body['assignments'][0]['assignment_template'], assignment_1.assignment_template.id) self.assertEqual(response_body['assignments'][0]['name'], assignment_1.assignment_template.name) self.assertEqual(response_body['assignments'][0]['labgroup'], assignment_1.labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][0]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_1.open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][0]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_1.close_date.replace(tzinfo=None))
def setUp(self): # create test user with permissions self.instructor_username = '******' self.student_username = '******' self.password = '******' self.instructor_user = User.objects.create_user(username=self.instructor_username, password=self.password) self.student_user = User.objects.create_user(username=self.student_username, password=self.password) self.instructor_user.groups.add(permissions.get_or_create_instructor_permissions()) self.student_user.groups.add(permissions.get_or_create_student_permissions()) self.client.login(username=self.instructor_username, password=self.password) # retrieve the view self.view_name = 'api:lab-group-lc' # Create foreign keys self.instructor = Instructor(user=self.instructor_user, wwuid="1234567") self.instructor.save() self.course = Course(name="test_course") self.course.save()
def setUp(self): # create test user with permissions self.username = '******' self.password = '******' self.instructor_user = User.objects.create_user(username=self.username, password=self.password) self.instructor_user.user_permissions.add( Permission.objects.get(codename='add_assignment')) self.instructor_user.user_permissions.add( Permission.objects.get(codename='change_assignment')) self.instructor_user.user_permissions.add( Permission.objects.get(codename='delete_assignment')) self.client.login(username=self.username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='Bounty Hunting 101') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term='before', enroll_key='4') self.group.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() self.assignment = Assignment(assignment_template=self.template, labgroup=self.group, open_date='2013-12-10T22:22:22Z', close_date='2014-12-10T22:22:22Z') self.assignment.save() self.assignment2 = Assignment(assignment_template=self.template, labgroup=self.group, open_date='2014-12-10T22:22:22Z', close_date='2015-12-10T22:22:22Z') self.assignment2.save() self.assignment3 = Assignment(assignment_template=self.template, labgroup=self.group, open_date='1492-12-10T22:22:22Z', close_date='3012-12-10T22:22:22Z') self.assignment3.save() # retrieve the view self.view_name = 'api:assignment-rud'
def setUp(self): # create test user with permissions self.instructor_username = '******' self.password = '******' self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.instructor = Instructor(user=self.instructor_user, wwuid='9999999') self.instructor.save() group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) self.client.login(username=self.instructor_username, password=self.password) # retrieve the view self.view_name = 'api:template-lc' # make a fake course self.course = Course(name="TestCourse") self.course.save()
def setUp(self): # create test user with permissions self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.client.login(username=self.student_username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='Bounty Hunting 101') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='4', group_name='Group A') self.group.save() self.student = Student(user=self.student_user, labgroup=self.group, wwuid='1111111') self.student.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() self.assignment = Assignment( assignment_template=self.template, labgroup=self.group, open_date=datetime.now(timezone(settings.TIME_ZONE)), close_date=datetime.now(timezone(settings.TIME_ZONE)) + timedelta(days=1)) self.assignment.save() self.assignment_entry = AssignmentEntry(student=self.student, assignment=self.assignment) self.assignment_entry.save() # retrieve the view self.view_name = 'api:assignment-entry-submit'
def test_labgroup_create_different_instructor(self): """ Tests that a labgroup is not created if the instructor passed in is not the instructors making the request. """ # create new user and instructor user = User.objects.create_user(username='******', password='******') instructor = Instructor(user=user, wwuid='9999999') instructor.save() # request request_body = { 'course': self.course.id, 'instructor': instructor.id, 'group_name': 'test name', 'term': 'FALL2000', 'enroll_key': 'test enroll_key', } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertFalse(LabGroup.objects.exists())
def setUp(self): # create test user with permissions self.username = '******' self.username_2 = 'test 2' self.username_3 = 'test 3' self.password = '******' self.user = User.objects.create_user(username=self.username, password=self.password) self.user_2 = User.objects.create_user(username=self.username_2, password=self.password) self.user_3 = User.objects.create_user(username=self.username_3, password=self.password) self.user.user_permissions.add( Permission.objects.get(codename='change_instructor')) self.user.user_permissions.add( Permission.objects.get(codename='delete_instructor')) self.client.login(username=self.username, password=self.password) # add courses to database self.instructor_1 = Instructor(wwuid='wwuid 1', user=self.user) self.instructor_1.save() self.instructor_2 = Instructor(wwuid='wwuid 2', user=self.user_2) self.instructor_2.save() self.instructor_3 = Instructor(wwuid='wwuid 3', user=self.user_3) self.instructor_3.save() # retrieve the view self.view_name = 'api:instructor-rud'
def test_instructor_list(self): """ Tests that instructors are properly listed. """ # add courses to database Instructor(wwuid='wwuid 1', user=self.user).save() Instructor(wwuid='wwuid 2', user=self.user_2).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response instructors = Instructor.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['instructors'][0]['pk'], instructors[0].id) self.assertTrue('wwuid' not in response_body['instructors'][0].keys()) self.assertEqual(response_body['instructors'][0]['user'], instructors[0].user.id) self.assertEqual(response_body['instructors'][1]['pk'], instructors[1].id) self.assertTrue('wwuid' not in response_body['instructors'][1].keys()) self.assertEqual(response_body['instructors'][1]['user'], instructors[1].user.id)
def setUp(self): # create test user with permissions self.username = '******' self.password = '******' self.user = User.objects.create_user(username=self.username, password=self.password) Instructor(user=self.user, wwuid='9999999').save() group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.user) self.client.login(username=self.username, password=self.password) # add courses and or templates to database self.course = Course(name="testcourse") self.course.save() self.template_1 = AssignmentTemplate(name='test name 1', course=self.course) self.template_1.save() self.template_2 = AssignmentTemplate(name='test name 2', course=self.course) self.template_2.save() self.template_3 = AssignmentTemplate(name='test name 3', course=self.course) self.template_3.save() # retrieve the view self.view_name = 'api:template-rud'
class StudentRUDTest(APITestCase): """ Test cases for retrieve, update, and destroy requests on StudentRUDView. """ def setUp(self): # create test user with permissions and test student user self.instructor_username = '******' self.student_username_1 = 'test student 1' self.student_username_2 = 'test student 2' self.student_username_3 = 'test student 3' self.password = '******' self.student_user_1 = User.objects.create_user( username=self.student_username_1, password=self.password) self.student_user_2 = User.objects.create_user( username=self.student_username_2, password=self.password) self.student_user_3 = User.objects.create_user( username=self.student_username_3, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.instructor_user.user_permissions.add( Permission.objects.get(codename='change_student')) self.instructor_user.user_permissions.add( Permission.objects.get(codename='delete_student')) self.client.login(username=self.instructor_username, password=self.password) # populate database self.instructor = Instructor(user=self.instructor_user, wwuid='9999999') self.instructor.save() self.course = Course(name='test course') self.course.save() self.group_1 = LabGroup(course=self.course, instructor=self.instructor, term='never', enroll_key='6') self.group_1.save() self.group_2 = LabGroup(course=self.course, instructor=self.instructor, term='ever', enroll_key='8') self.group_2.save() self.student_1 = Student(user=self.student_user_1, labgroup=self.group_1, wwuid='1111111') self.student_1.save() self.student_2 = Student(user=self.student_user_2, labgroup=self.group_1, wwuid='2222222') self.student_2.save() self.student_3 = Student(user=self.student_user_3, labgroup=self.group_1, wwuid='3333333') self.student_3.save() # retrieve the view self.view_name = 'api:student-rud' def test_student_retrieve(self): """ Tests that a student is properly retrieved. """ # request response = self.client.get( reverse(self.view_name, args=[self.student_2.id])) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['user'], self.student_2.user.id) self.assertEqual(response_body['labgroup'], self.student_2.labgroup.id) self.assertEqual(response_body['wwuid'], self.student_2.wwuid) def test_student_update(self): """ Tests that a student is properly updated. """ # modify values request_body = { 'user': self.student_user_2.id, 'labgroup': self.group_2.id, 'wwuid': '8888888', } # request response = self.client.put( reverse(self.view_name, args=[self.student_2.id]), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database student = Student.objects.filter(user=self.student_user_2).first() self.assertEqual(student.user.id, request_body['user']) self.assertEqual(student.labgroup.id, request_body['labgroup']) self.assertEqual(student.wwuid, request_body['wwuid']) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['user'], request_body['user']) self.assertEqual(response_body['labgroup'], request_body['labgroup']) self.assertEqual(response_body['wwuid'], request_body['wwuid']) def test_student_destroy(self): """ Tests that a student is properly destroyed. """ # request response = self.client.delete( reverse(self.view_name, args=[self.student_2.id])) # test database students = Student.objects.all() self.assertTrue(self.student_1 in students) self.assertTrue(self.student_2 not in students) self.assertTrue(self.student_3 in students) # test response self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class StudentLCTest(APITestCase): """ Test cases for list and create requests on StudentLCView. """ def setUp(self): # create test user with permissions self.username = '******' self.password = '******' self.student_username = '******' self.instructor_user = User.objects.create_user(username=self.username, password=self.password) group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.client.login(username=self.username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='fact') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term='never', enroll_key='6') self.group.save() # retrieve the view self.view_name = 'api:student-lc' def test_student_create(self): """ Tests that a student is properly created. """ # request request_body = { 'user': self.student_user.id, 'labgroup': self.group.id, 'wwuid': '16', } response = self.client.post(reverse(self.view_name), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database student = Student.objects.first() self.assertEqual(student.user.id, request_body['user']) self.assertEqual(student.labgroup.id, request_body['labgroup']) self.assertEqual(student.wwuid, request_body['wwuid']) # test response self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response_body['user'], request_body['user']) self.assertEqual(response_body['labgroup'], request_body['labgroup']) self.assertEqual(response_body['wwuid'], request_body['wwuid']) def test_student_permissions(self): """ Tests that a student's user is assigned the appropriate permissions. """ # request request_body = {'wwuid': '1111111', 'user': self.student_user.id} self.client.post(reverse(self.view_name), request_body) # check that the user is in the instructor group self.assertTrue( self.student_user.groups.filter(name='Student').exists()) def test_student_list(self): """ Tests that students are properly listed. """ # add students to database Student(user=self.student_user, labgroup=self.group, wwuid='64').save() Student(user=self.instructor_user, labgroup=self.group, wwuid='12').save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response students = Student.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['students'][0]['user'], students[0].user.id) self.assertEqual(response_body['students'][0]['labgroup'], students[0].labgroup.id) self.assertEqual(response_body['students'][0]['wwuid'], students[0].wwuid) self.assertEqual(response_body['students'][1]['user'], students[1].user.id) self.assertEqual(response_body['students'][1]['labgroup'], students[1].labgroup.id) self.assertEqual(response_body['students'][1]['wwuid'], students[1].wwuid) def test_student_list_not_shown_to_students(self): """ Tests that students are not listed to other students. """ # login the student self.client.logout() self.client.login(username=self.student_username, password=self.password) # add students to database Student(user=self.student_user, labgroup=self.group, wwuid='64').save() Student(user=self.instructor_user, labgroup=self.group, wwuid='12').save() # request response = self.client.get(reverse(self.view_name)) # test response self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
class LabGroupRUDTest(APITestCase): """ Test cases for retrieve, update, and destroy requests on LabGroupRUDView. """ def setUp(self): # create test user with permissions self.instructor_username = '******' self.student_username = '******' self.password = '******' self.instructor_user = User.objects.create_user(username=self.instructor_username, password=self.password) self.student_user = User.objects.create_user(username=self.student_username, password=self.password) self.instructor_user.groups.add(permissions.get_or_create_instructor_permissions()) self.student_user.groups.add(permissions.get_or_create_student_permissions()) self.client.login(username=self.instructor_username, password=self.password) # Create foreign keys self.instructor = Instructor(user=self.instructor_user, wwuid="1234567") self.instructor.save() self.course_1 = Course(name="test course 1") self.course_1.save() self.course_2 = Course(name="test course 2") self.course_2.save() # add labgroups to database self.labgroup_1 = LabGroup(course=self.course_1, instructor=self.instructor, term='test1', enroll_key='test key 1') self.labgroup_1.save() self.labgroup_2 = LabGroup(course=self.course_1, instructor=self.instructor, term='test2', enroll_key='test key 2') self.labgroup_2.save() self.labgroup_3 = LabGroup(course=self.course_1, instructor=self.instructor, term='test3', enroll_key='test key 3') self.labgroup_3.save() # retrieve the view self.view_name = 'api:lab-group-rud' def test_labgroup_retrieve_instructor(self): """ Tests that a labgroup is properly retrieved for instructors. """ # request response = self.client.get(reverse(self.view_name, args=[self.labgroup_2.id])) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], self.labgroup_2.id) self.assertEqual(response_body['course'], self.labgroup_2.course.id) self.assertEqual(response_body['term'], self.labgroup_2.term) self.assertEqual(response_body['group_name'], self.labgroup_2.group_name) self.assertEqual(response_body['instructor'], self.labgroup_2.instructor.id) self.assertEqual(response_body['enroll_key'], self.labgroup_2.enroll_key) def test_labgroup_retrieve_student(self): """ Tests that a labgroup is properly retrieved for students. """ # request self.client.logout() self.client.login(username=self.student_username, password=self.password) response = self.client.get(reverse(self.view_name, args=[self.labgroup_2.id])) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], self.labgroup_2.id) self.assertEqual(response_body['course'], self.labgroup_2.course.id) self.assertEqual(response_body['term'], self.labgroup_2.term) self.assertEqual(response_body['group_name'], self.labgroup_2.group_name) self.assertEqual(response_body['instructor'], self.labgroup_2.instructor.id) self.assertTrue('enroll_key' not in response_body.keys()) def test_labgroup_update(self): """ Tests that a labgroup is properly updated. """ # modify values request_body = { 'course': self.course_2.id, 'instructor': self.instructor.id, 'group_name': 'changed', 'term': 'FALL2000', 'enroll_key': 'changed', } # request response = self.client.put(reverse(self.view_name, args=[self.labgroup_2.id]), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database labgroup = LabGroup.objects.get(id=self.labgroup_2.id) self.assertEqual(labgroup.id, self.labgroup_2.id) self.assertEqual(labgroup.course.id, request_body['course']) self.assertEqual(labgroup.group_name, request_body['group_name']) self.assertEqual(labgroup.instructor.id, request_body['instructor']) self.assertEqual(labgroup.term, request_body['term']) self.assertEqual(labgroup.enroll_key, request_body['enroll_key']) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], self.labgroup_2.id) self.assertEqual(response_body['course'], request_body['course']) self.assertEqual(response_body['group_name'], request_body['group_name']) self.assertEqual(response_body['instructor'], request_body['instructor']) self.assertEqual(response_body['term'], request_body['term']) self.assertEqual(response_body['enroll_key'], request_body['enroll_key']) def test_labgroup_destroy(self): """ Tests that a labgroup is properly destroyed. """ # request response = self.client.delete(reverse(self.view_name, args=[self.labgroup_2.id])) # test database labgroups = LabGroup.objects.all() self.assertTrue(self.labgroup_1 in labgroups) self.assertTrue(self.labgroup_2 not in labgroups) self.assertTrue(self.labgroup_3 in labgroups) # test response self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class AssignmentEntryEntrySubmitTest(APITestCase): """ Test cases for submitting assignment on AssignmentEntrySubmitView. """ def setUp(self): # create test user with permissions self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.client.login(username=self.student_username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='Bounty Hunting 101') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='4', group_name='Group A') self.group.save() self.student = Student(user=self.student_user, labgroup=self.group, wwuid='1111111') self.student.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() self.assignment = Assignment( assignment_template=self.template, labgroup=self.group, open_date=datetime.now(timezone(settings.TIME_ZONE)), close_date=datetime.now(timezone(settings.TIME_ZONE)) + timedelta(days=1)) self.assignment.save() self.assignment_entry = AssignmentEntry(student=self.student, assignment=self.assignment) self.assignment_entry.save() # retrieve the view self.view_name = 'api:assignment-entry-submit' def test_assignment_entry_submit(self): """ Tests that an assignment is properly submitted. """ # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) response_body = json.loads(response.content.decode('utf-8')) # test database assignment_entry = AssignmentEntry.objects.get( id=self.assignment_entry.id) self.assertEqual(assignment_entry.student, self.student) self.assertEqual(assignment_entry.assignment, self.assignment) self.assertNotEqual(assignment_entry.start_date, None) self.assertNotEqual(assignment_entry.submit_date, None) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], assignment_entry.id) self.assertEqual(response_body['student'], self.student.id) self.assertEqual(response_body['assignment'], self.assignment.id) self.assertTrue('start_date' in response_body.keys()) self.assertTrue('submit_date' in response_body.keys()) def test_assignment_entry_does_not_exist(self): """ Tests that nothing happens when the assignment does not exist. """ # request response = self.client.post(reverse(self.view_name, args=[0])) # test database assignment_entry = AssignmentEntry.objects.get( id=self.assignment_entry.id) self.assertEqual(assignment_entry.submit_date, None) # test response self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) def test_assignment_entry_not_started(self): """ Tests that nothing happens when the assignment entry has not been started. """ # delete assignment_entry self.assignment_entry.delete() # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test database self.assertEqual(len(AssignmentEntry.objects.all()), 0) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) def test_assignment_entry_already_submitted(self): """ Tests that nothing happens when the assignment entry has already been submitted. """ # submit assignment self.assignment_entry.submit_date = datetime.now( timezone(settings.TIME_ZONE)) self.assignment_entry.save() # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertEqual( AssignmentEntry.objects.get( id=self.assignment_entry.id).submit_date, self.assignment_entry.submit_date) def test_assignment_closed(self): """ Tests that nothing happens when the user tries to start an assignment that has been closed. """ # modify open dates self.assignment.open_date = datetime.now(timezone( settings.TIME_ZONE)) - timedelta(days=2) self.assignment.close_date = datetime.now(timezone( settings.TIME_ZONE)) - timedelta(days=1) self.assignment.save() # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test response self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # test database self.assertEqual(self.assignment_entry.submit_date, None)
class AssignmentTemplateLCTest(APITestCase): """ Test cases for list and create requests on AssignmentTemplateLCView. """ def setUp(self): # create test user with permissions self.instructor_username = '******' self.password = '******' self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.instructor = Instructor(user=self.instructor_user, wwuid='9999999') self.instructor.save() group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) self.client.login(username=self.instructor_username, password=self.password) # retrieve the view self.view_name = 'api:template-lc' # make a fake course self.course = Course(name="TestCourse") self.course.save() def test_assignment_template_create(self): """ Tests that an assignment template is properly created. """ # request request_body = {'name': 'test name', 'course': self.course.id} # create assignment template response = self.client.post(reverse(self.view_name), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database temp = AssignmentTemplate.objects.first() self.assertEqual(temp.name, request_body['name']) self.assertEqual(self.course.id, request_body['course']) # test response self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response_body['pk'], temp.id) self.assertEqual(response_body['name'], request_body['name']) self.assertEqual(response_body['course'], self.course.id) def test_assignment_template_list_instructor(self): """ Tests that assignment templates are properly listed for instructors. """ # add assignment templates to database AssignmentTemplate(name='test name 1', course=self.course).save() AssignmentTemplate(name='test name 2', course=self.course).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response assignments = AssignmentTemplate.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['templates'][0]['pk'], assignments[0].id) self.assertEqual(response_body['templates'][0]['course'], assignments[0].course.id) self.assertEqual(response_body['templates'][0]['name'], assignments[0].name) self.assertEqual(response_body['templates'][1]['pk'], assignments[1].id) self.assertEqual(response_body['templates'][1]['course'], assignments[1].course.id) self.assertEqual(response_body['templates'][1]['name'], assignments[1].name) def test_assignment_template_list_student(self): """ Tests that assignment templates are properly listed for students. """ # create a labgroup labgroup_1 = LabGroup(group_name='A', course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='ABC') labgroup_1.save() # create an unused labgroup labgroup_2 = LabGroup(group_name='B', course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='ABC') labgroup_2.save() # create student user student_user = User.objects.create_user(username='******', password=self.password) Student(user=student_user, wwuid='1111111', labgroup=labgroup_1).save() group = permissions.get_or_create_student_permissions() group.user_set.add(student_user) self.client.logout() self.client.login(username=student_user.username, password=self.password) # add assignment templates to database at1 = AssignmentTemplate(name='test name 1', course=self.course) at1.save() at2 = AssignmentTemplate(name='test name 2', course=self.course) at2.save() # assign student the first assignment template assignment = Assignment( assignment_template=at1, labgroup=labgroup_1, open_date=datetime.now(timezone(settings.TIME_ZONE)) - timedelta(days=1), close_date=datetime.now(timezone(settings.TIME_ZONE)) + timedelta(days=1)) assignment.save() # create different assignment Assignment(assignment_template=at2, labgroup=labgroup_2, open_date=datetime.now(timezone(settings.TIME_ZONE)) - timedelta(days=1), close_date=datetime.now(timezone(settings.TIME_ZONE)) + timedelta(days=1)) # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response assignments = AssignmentTemplate.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_body['templates']), 1) self.assertEqual(response_body['templates'][0]['pk'], assignments[0].id) self.assertEqual(response_body['templates'][0]['course'], assignments[0].course.id) self.assertEqual(response_body['templates'][0]['name'], assignments[0].name)
class AssignmentEntryTest(APITestCase): """ Test cases for viewing the user's assignment entry on AssignmentEntryView. """ def setUp(self): # create test user with permissions self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.client.login(username=self.student_username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='Bounty Hunting 101') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='4', group_name='Group A') self.group.save() self.student = Student(user=self.student_user, labgroup=self.group, wwuid='1111111') self.student.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() self.assignment = Assignment( assignment_template=self.template, labgroup=self.group, open_date=datetime.now(timezone(settings.TIME_ZONE)), close_date=datetime.now(timezone(settings.TIME_ZONE)) + timedelta(days=1)) self.assignment.save() # retrieve the view self.view_name = 'api:assignment-entry' def test_view_assignment_entry(self): """ Tests that an assignment entry is properly retrieved. """ # create assignment entry assignment_entry = AssignmentEntry(student=self.student, assignment=self.assignment) assignment_entry.save() # request response = self.client.get( reverse(self.view_name, args=[self.assignment.id])) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], assignment_entry.id) self.assertEqual(response_body['student'], self.student.id) self.assertEqual(response_body['assignment'], self.assignment.id) self.assertTrue('start_date' in response_body.keys()) self.assertTrue('submit_date' in response_body.keys()) def test_view_assignment_entry_not_started(self): """ Tests that an assignment entry is not retrieved if it has not been started. """ # request response = self.client.get( reverse(self.view_name, args=[self.assignment.id])) # test response self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
class InstructorRUDTest(APITestCase): """ Test cases for retrieve, update, and destroy requests on InstructorRUDView. """ def setUp(self): # create test user with permissions self.username = '******' self.username_2 = 'test 2' self.username_3 = 'test 3' self.password = '******' self.user = User.objects.create_user(username=self.username, password=self.password) self.user_2 = User.objects.create_user(username=self.username_2, password=self.password) self.user_3 = User.objects.create_user(username=self.username_3, password=self.password) self.user.user_permissions.add( Permission.objects.get(codename='change_instructor')) self.user.user_permissions.add( Permission.objects.get(codename='delete_instructor')) self.client.login(username=self.username, password=self.password) # add courses to database self.instructor_1 = Instructor(wwuid='wwuid 1', user=self.user) self.instructor_1.save() self.instructor_2 = Instructor(wwuid='wwuid 2', user=self.user_2) self.instructor_2.save() self.instructor_3 = Instructor(wwuid='wwuid 3', user=self.user_3) self.instructor_3.save() # retrieve the view self.view_name = 'api:instructor-rud' def test_instructor_retrieve(self): """ Tests that an instructor is properly retrieved. """ # request response = self.client.get( reverse(self.view_name, args=[self.instructor_2.id])) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], self.instructor_2.id) self.assertTrue('wwuid' not in response_body.keys()) self.assertEqual(response_body['user'], self.instructor_2.user.id) def test_instructor_update(self): """ Tests that an instructor is properly updated. """ # modify values request_body = {'user': self.instructor_2.user.id, 'wwuid': 'changed'} # request response = self.client.put( reverse(self.view_name, args=[self.instructor_2.id]), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database instructor = Instructor.objects.filter(id=self.instructor_2.id).first() self.assertEqual(instructor.id, self.instructor_2.id) self.assertTrue('wwuid' not in response_body.keys()) self.assertEqual(instructor.user.id, request_body['user']) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['pk'], self.instructor_2.id) self.assertTrue('wwuid' not in response_body.keys()) self.assertEqual(response_body['user'], request_body['user']) def test_instructor_destroy(self): """ Tests that an instructor is properly destroyed. """ # request response = self.client.delete( reverse(self.view_name, args=[self.instructor_2.id])) # test database instructors = Instructor.objects.all() self.assertTrue(self.instructor_1 in instructors) self.assertTrue(self.instructor_2 not in instructors) self.assertTrue(self.instructor_3 in instructors) # test response self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class AssignmentRUDTest(APITestCase): """ Test cases for retrieve, update, and destroy requests on AssignmentRUDView. """ def setUp(self): # create test user with permissions self.username = '******' self.password = '******' self.instructor_user = User.objects.create_user(username=self.username, password=self.password) self.instructor_user.user_permissions.add( Permission.objects.get(codename='add_assignment')) self.instructor_user.user_permissions.add( Permission.objects.get(codename='change_assignment')) self.instructor_user.user_permissions.add( Permission.objects.get(codename='delete_assignment')) self.client.login(username=self.username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='Bounty Hunting 101') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term='before', enroll_key='4') self.group.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() self.assignment = Assignment(assignment_template=self.template, labgroup=self.group, open_date='2013-12-10T22:22:22Z', close_date='2014-12-10T22:22:22Z') self.assignment.save() self.assignment2 = Assignment(assignment_template=self.template, labgroup=self.group, open_date='2014-12-10T22:22:22Z', close_date='2015-12-10T22:22:22Z') self.assignment2.save() self.assignment3 = Assignment(assignment_template=self.template, labgroup=self.group, open_date='1492-12-10T22:22:22Z', close_date='3012-12-10T22:22:22Z') self.assignment3.save() # retrieve the view self.view_name = 'api:assignment-rud' def test_assignment_retrieve(self): """ Tests that an assignment is properly retrieved. """ # request response = self.client.get( reverse(self.view_name, args=[self.assignment.id])) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['assignment_template'], self.assignment.assignment_template.id) self.assertEqual(response_body['name'], self.assignment.assignment_template.name) self.assertEqual(response_body['labgroup'], self.assignment.labgroup.id) self.assertEqual(response_body['open_date'], self.assignment.open_date) self.assertEqual(response_body['close_date'], self.assignment.close_date) def test_assignment_update(self): """ Tests that an assignment is properly updated. """ # modify values request_body = { 'assignment_template': self.template.id, 'labgroup': self.group.id, 'open_date': '1890-10-10T22:22:22Z', 'close_date': '1892-10-10T22:22:22Z', } # request response = self.client.put( reverse(self.view_name, args=[self.assignment.id]), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database assignment_tester = Assignment.objects.filter( pk=self.assignment.id).first() self.assertEqual(assignment_tester.assignment_template.id, request_body['assignment_template']) self.assertEqual(assignment_tester.labgroup.id, request_body['labgroup']) self.assertEqual( assignment_tester.open_date.replace(tzinfo=None), datetime.strptime(request_body['open_date'], '%Y-%m-%dT%H:%M:%SZ')) self.assertEqual( assignment_tester.close_date.replace(tzinfo=None), datetime.strptime(request_body['close_date'], '%Y-%m-%dT%H:%M:%SZ')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['assignment_template'], request_body['assignment_template']) self.assertEqual(response_body['labgroup'], request_body['labgroup']) self.assertEqual(response_body['open_date'], request_body['open_date']) self.assertEqual(response_body['close_date'], request_body['close_date']) def test_assignment_update_check_valid_dates(self): """ Tests that an assignment is not updated when the open and close dates are incompatible. """ # get current time current_time = datetime.now(timezone(settings.TIME_ZONE)) # request request_body = { 'assignment_template': self.template.id, 'labgroup': self.group.id, 'open_date': (current_time + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), 'close_date': current_time.strftime('%Y-%m-%dT%H:%M:%SZ'), } response = self.client.put( reverse(self.view_name, args=[self.assignment.id]), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertEqual(self.assignment.assignment_template.id, request_body['assignment_template']) self.assertEqual(self.assignment.labgroup.id, request_body['labgroup']) self.assertNotEqual(self.assignment.open_date, request_body['open_date']) self.assertNotEqual(self.assignment.close_date, request_body['close_date']) def test_assignment_update_template_course_incompatible(self): """ Tests that an assignment is not created when the assignment template doesn't belong to a shared course. """ # create different course course = Course(name='other course') course.save() # create different template template = AssignmentTemplate(course=course, name='other template') template.save() # request current_time = datetime.now(timezone(settings.TIME_ZONE)) request_body = { 'assignment_template': template.id, 'labgroup': self.group.id, 'open_date': (current_time - timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), 'close_date': (current_time + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), } response = self.client.put( reverse(self.view_name, args=[self.assignment.id]), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database assignment = Assignment.objects.get(id=self.assignment.id) self.assertNotEqual(assignment.assignment_template, template) def test_assignment_destroy(self): """ Tests that an assignment is properly destroyed. """ # request response = self.client.delete( reverse(self.view_name, args=[self.assignment2.id])) # test database assignments = Assignment.objects.all() self.assertTrue(self.assignment in assignments) self.assertTrue(self.assignment2 not in assignments) self.assertTrue(self.assignment3 in assignments) # test response self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class AssignmentLCTest(APITestCase): """ Test cases for list and create requests on AssignmentLCView. """ def setUp(self): # create test user with permissions self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) group = permissions.get_or_create_student_permissions() group.user_set.add(self.student_user) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) self.client.login(username=self.instructor_username, password=self.password) # populate test database self.course = Course(name='Bounty Hunting 101') self.course.save() self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term='before', enroll_key='4') self.group.save() self.student = Student(user=self.student_user, wwuid='9994141', labgroup=self.group) self.student.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() # retrieve the view self.view_name = 'api:assignment-lc' def test_assignment_create(self): """ Tests that an assignment is properly created. """ # request request_body = { 'assignment_template': self.template.id, 'labgroup': self.group.id, 'open_date': '2013-12-12T22:22:22Z', 'close_date': '2014-12-12T22:22:22Z', } response = self.client.post(reverse(self.view_name), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database assignment = Assignment.objects.first() self.assertEqual(assignment.assignment_template.id, request_body['assignment_template']) self.assertEqual(assignment.labgroup.id, request_body['labgroup']) self.assertEqual( assignment.open_date.replace(tzinfo=None), datetime.strptime(request_body['open_date'], '%Y-%m-%dT%H:%M:%SZ')) self.assertEqual( assignment.close_date.replace(tzinfo=None), datetime.strptime(request_body['close_date'], '%Y-%m-%dT%H:%M:%SZ')) # test response self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response_body['assignment_template'], request_body['assignment_template']) self.assertEqual(response_body['labgroup'], request_body['labgroup']) self.assertEqual(response_body['open_date'], request_body['open_date']) self.assertEqual(response_body['close_date'], request_body['close_date']) def test_assignment_create_check_valid_dates(self): """ Tests that an assignment is not created when the open and close dates are incompatible. """ # get current time current_time = datetime.now(timezone(settings.TIME_ZONE)) # request request_body = { 'assignment_template': self.template.id, 'labgroup': self.group.id, 'open_date': (current_time + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), 'close_date': current_time.strftime('%Y-%m-%dT%H:%M:%SZ'), } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertFalse(Assignment.objects.exists()) def test_assignment_create_template_course_incompatible(self): """ Tests that an assignment is not created when the assignment template doesn't belong to a shared course. """ # create different course course = Course(name='other course') course.save() # create different template template = AssignmentTemplate(course=course, name='other template') template.save() # request current_time = datetime.now(timezone(settings.TIME_ZONE)) request_body = { 'assignment_template': template.id, 'labgroup': self.group.id, 'open_date': (current_time - timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), 'close_date': (current_time + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertFalse(Assignment.objects.exists()) def test_assignment_list_instructor(self): """ Tests that assignments are properly listed. """ # add assignments to database current_time = datetime.now(timezone(settings.TIME_ZONE)) Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)).save() Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response assignments = Assignment.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( response_body['assignments'][0]['assignment_template'], assignments[0].assignment_template.id) self.assertEqual(response_body['assignments'][0]['name'], assignments[0].assignment_template.name) self.assertEqual(response_body['assignments'][0]['labgroup'], assignments[0].labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][0]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[0].open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][0]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[0].close_date.replace(tzinfo=None)) self.assertEqual( response_body['assignments'][1]['assignment_template'], assignments[1].assignment_template.id) self.assertEqual(response_body['assignments'][1]['name'], assignments[1].assignment_template.name) self.assertEqual(response_body['assignments'][1]['labgroup'], assignments[1].labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][1]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[1].open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][1]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[1].close_date.replace(tzinfo=None)) def test_assignment_list_instructor_does_not_own(self): """ Tests that assignments are properly listed. """ # create other instructor and labgroup user = User.objects.create_user(username='******', password='******') instructor = Instructor(wwuid='2027616', user=user) instructor.save() labgroup = LabGroup(course=self.course, instructor=instructor, term=get_current_term(), enroll_key='ABC') labgroup.save() # add assignments to database current_time = datetime.now(timezone(settings.TIME_ZONE)) assignment_1 = Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)) assignment_1.save() Assignment(assignment_template=self.template, labgroup=labgroup, open_date=current_time, close_date=current_time + timedelta(days=1)).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_body['assignments']), 1) self.assertEqual( response_body['assignments'][0]['assignment_template'], assignment_1.assignment_template.id) self.assertEqual(response_body['assignments'][0]['name'], assignment_1.assignment_template.name) self.assertEqual(response_body['assignments'][0]['labgroup'], assignment_1.labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][0]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_1.open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][0]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_1.close_date.replace(tzinfo=None)) def test_assignment_list_student(self): """ Tests that assignments are properly listed. """ # login the student self.client.logout() self.client.login(username=self.student_username, password=self.password) # add assignments to database current_time = datetime.now(timezone(settings.TIME_ZONE)) Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)).save() Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response assignments = Assignment.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( response_body['assignments'][0]['assignment_template'], assignments[0].assignment_template.id) self.assertEqual(response_body['assignments'][0]['name'], assignments[0].assignment_template.name) self.assertEqual(response_body['assignments'][0]['labgroup'], assignments[0].labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][0]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[0].open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][0]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[0].close_date.replace(tzinfo=None)) self.assertEqual( response_body['assignments'][1]['assignment_template'], assignments[1].assignment_template.id) self.assertEqual(response_body['assignments'][1]['name'], assignments[1].assignment_template.name) self.assertEqual(response_body['assignments'][1]['labgroup'], assignments[1].labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][1]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[1].open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][1]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignments[1].close_date.replace(tzinfo=None)) def test_assignment_list_student_different_labgroup(self): """ Tests that assignments are not listed if they are for a different labgroup. """ # login the student self.client.logout() self.client.login(username=self.student_username, password=self.password) # create other labgroup labgroup = LabGroup(course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='ABC') labgroup.save() # add assignments to database current_time = datetime.now(timezone(settings.TIME_ZONE)) assignment_1 = Assignment(assignment_template=self.template, labgroup=self.group, open_date=current_time, close_date=current_time + timedelta(days=1)) assignment_1.save() Assignment(assignment_template=self.template, labgroup=labgroup, open_date=current_time, close_date=current_time + timedelta(days=1)).save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_body['assignments']), 1) self.assertEqual( response_body['assignments'][0]['assignment_template'], assignment_1.assignment_template.id) self.assertEqual(response_body['assignments'][0]['name'], assignment_1.assignment_template.name) self.assertEqual(response_body['assignments'][0]['labgroup'], assignment_1.labgroup.id) self.assertEqual( datetime.strptime(response_body['assignments'][0]['open_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_1.open_date.replace(tzinfo=None)) self.assertEqual( datetime.strptime(response_body['assignments'][0]['close_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_1.close_date.replace(tzinfo=None))
class AssignmentEntryStartTest(APITestCase): """ Test cases for starting assignments on AssignmentEntryStartView. """ def setUp(self): # create test user with permissions self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) self.client.login(username=self.student_username, password=self.password) # populate test database self.instructor = Instructor(user=self.instructor_user, wwuid='9994141') self.instructor.save() self.course = Course(name='Bounty Hunting 101') self.course.save() self.group = LabGroup(course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='4', group_name='Group A') self.group.save() self.student = Student(user=self.student_user, labgroup=self.group, wwuid='1111111') self.student.save() self.template = AssignmentTemplate(course=self.course, name='Royalty Kidnapping Section A') self.template.save() self.assignment = Assignment( assignment_template=self.template, labgroup=self.group, open_date=datetime.now(timezone(settings.TIME_ZONE)), close_date=datetime.now(timezone(settings.TIME_ZONE)) + timedelta(days=1)) self.assignment.save() # retrieve the view self.view_name = 'api:assignment-entry-start' def test_assignment_start(self): """ Tests that an assignment entry is properly created. """ # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) response_body = json.loads(response.content.decode('utf-8')) # test return code self.assertEqual(response.status_code, status.HTTP_201_CREATED) # test database assignment_entry = AssignmentEntry.objects.get(id=response_body['pk']) self.assertEqual(assignment_entry.student, self.student) self.assertEqual(assignment_entry.assignment, self.assignment) self.assertNotEqual(assignment_entry.start_date, None) self.assertEqual(assignment_entry.submit_date, None) # test response self.assertEqual(response_body['pk'], assignment_entry.id) self.assertEqual(response_body['student'], assignment_entry.student.id) self.assertEqual( datetime.strptime(response_body['start_date'], '%Y-%m-%dT%H:%M:%S.%fZ'), assignment_entry.start_date.replace(tzinfo=None)) self.assertEqual(response_body['submit_date'], None) def test_assignment_start_duplicate(self): """ Tests that nothing happens when the assignment is started more than once. """ # create extra assignment entry self.client.post(reverse(self.view_name, args=[self.assignment.id])) # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test database self.assertEqual(len(AssignmentEntry.objects.all()), 1) # test response self.assertEqual(response.status_code, status.HTTP_409_CONFLICT) def test_assignment_does_not_exist(self): """ Tests that nothing happens when the assignment does not exist. """ response = self.client.post(reverse(self.view_name, args=[0])) # test database self.assertEqual(len(AssignmentEntry.objects.all()), 0) # test response self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) def test_student_not_assigned_assignment(self): """ Tests that nothing happens when the user tries to start an assignment not assigned to their labgroup. """ # add user to different labgroup new_labgroup = LabGroup(course=self.course, instructor=self.instructor, term=get_current_term(), enroll_key='ABC', group_name='Group B') new_labgroup.save() self.student.labgroup = new_labgroup self.student.save() # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test database self.assertEqual(len(AssignmentEntry.objects.all()), 0) # test response self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) def test_assignment_not_open(self): """ Tests that nothing happens when the user tries to start an assignment that is not open. """ # modify open dates self.assignment.open_date = datetime.now(timezone( settings.TIME_ZONE)) + timedelta(days=1) self.assignment.close_date = datetime.now(timezone( settings.TIME_ZONE)) + timedelta(days=2) self.assignment.save() # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test response self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # test database self.assertEqual(len(AssignmentEntry.objects.all()), 0) def test_assignment_closed(self): """ Tests that nothing happens when the user tries to start an assignment that has been closed. """ # modify open dates self.assignment.open_date = datetime.now(timezone( settings.TIME_ZONE)) - timedelta(days=2) self.assignment.close_date = datetime.now(timezone( settings.TIME_ZONE)) - timedelta(days=1) self.assignment.save() # request response = self.client.post( reverse(self.view_name, args=[self.assignment.id])) # test response self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # test database self.assertEqual(len(AssignmentEntry.objects.all()), 0)
class EnrollTest(APITestCase): """ Test cases for POST requests on EnrollView. """ def setUp(self): # create test users self.student_username = '******' self.instructor_username = '******' self.password = '******' self.student_user = User.objects.create_user( username=self.student_username, password=self.password) self.instructor_user = User.objects.create_user( username=self.instructor_username, password=self.password) group = permissions.get_or_create_instructor_permissions() group.user_set.add(self.instructor_user) group = permissions.get_or_create_student_permissions() group.user_set.add(self.student_user) self.client.login(username=self.student_username, password=self.password) # populate the database self.student = Student(labgroup=None, user=self.student_user, wwuid='1111111') self.student.save() self.instructor = Instructor(user=self.instructor_user, wwuid='2222222') self.instructor.save() self.course = Course(name='test name') self.course.save() self.labgroup = LabGroup(course=self.course, instructor=self.instructor, group_name='A', term='FALL2018', enroll_key='ABC') self.labgroup.save() # retrieve the view self.view_name = 'api:enroll' def test_enroll(self): """ Tests that a labgroup can be properly enrolled in. """ # request request_body = { 'wwuid': self.student.wwuid, 'labgroup': self.labgroup.id, 'enroll_key': self.labgroup.enroll_key } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) # test database self.assertEqual(Student.objects.first().user, self.student_user) self.assertEqual(Student.objects.first().labgroup, self.labgroup) self.assertEqual(Student.objects.first().wwuid, self.student.wwuid) def test_enroll_bad_labgroup(self): """ Tests that entering a bad labgroup is properly handled. """ # request request_body = { 'wwuid': self.student.wwuid, 'labgroup': 0, 'enroll_key': self.labgroup.enroll_key } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) # test database self.assertEqual(Student.objects.first().labgroup, None) def test_enroll_bad_key(self): """ Tests that a labgroup is not enrolled in with a bad key. """ # request request_body = { 'wwuid': self.student.wwuid, 'labgroup': self.labgroup.id, 'enroll_key': '' } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # test database self.assertEqual(Student.objects.first().labgroup, None) def test_missing_parameters(self): """ Tests that a missing parameter causes the request to do nothing. """ # request request_body = { 'wwuid': self.student.wwuid, 'enroll_key': self.labgroup.enroll_key } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertEqual(Student.objects.first().labgroup, None) def test_invalid_student(self): """ Tests that entering invalid student does nothing. """ # request request_body = { 'wwuid': '123456789', # too long 'labgroup': self.labgroup.id, 'enroll_key': self.labgroup.enroll_key } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertEqual(len(Student.objects.all()), 0) def test_enroll_status(self): """ Tests that the enrollment status of a user can be retrieved. """ # enroll request request_body = { 'user': self.student_user, 'student': self.student, } self.client.post(reverse(self.view_name), request_body) # enroll status request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['user']['username'], self.student_user.username) self.assertEqual(response_body['user']['email'], self.student_user.email) self.assertEqual(response_body['user']['first_name'], self.student_user.first_name) self.assertEqual(response_body['user']['last_name'], self.student_user.last_name) self.assertEqual(response_body['student']['pk'], self.student.id) self.assertEqual(response_body['student']['labgroup'], self.student.labgroup) self.assertEqual(response_body['student']['user'], self.student.user.id) self.assertEqual(response_body['student']['wwuid'], self.student.wwuid) def test_enroll_status_not_enrolled(self): """ Tests that no enrollment status is retrieved for an un-enrolled user. """ # un-enroll user self.student.delete() # enroll status request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['user']['username'], self.student_user.username) self.assertEqual(response_body['user']['email'], self.student_user.email) self.assertEqual(response_body['user']['first_name'], self.student_user.first_name) self.assertEqual(response_body['user']['last_name'], self.student_user.last_name) self.assertEqual(response_body['student'], None)
class LabGroupLCTest(APITestCase): """ Test cases for list and create requests on LabGroupLCView. """ def setUp(self): # create test user with permissions self.instructor_username = '******' self.student_username = '******' self.password = '******' self.instructor_user = User.objects.create_user(username=self.instructor_username, password=self.password) self.student_user = User.objects.create_user(username=self.student_username, password=self.password) self.instructor_user.groups.add(permissions.get_or_create_instructor_permissions()) self.student_user.groups.add(permissions.get_or_create_student_permissions()) self.client.login(username=self.instructor_username, password=self.password) # retrieve the view self.view_name = 'api:lab-group-lc' # Create foreign keys self.instructor = Instructor(user=self.instructor_user, wwuid="1234567") self.instructor.save() self.course = Course(name="test_course") self.course.save() def test_labgroup_create(self): """ Tests that a labgroup is properly created. """ # request request_body = { 'course': self.course.id, 'instructor': self.instructor.id, 'group_name': 'test name', 'term': 'FALL2000', 'enroll_key': 'test enroll_key', } response = self.client.post(reverse(self.view_name), request_body) response_body = json.loads(response.content.decode('utf-8')) # test database labgroup = LabGroup.objects.first() self.assertEqual(labgroup.course.id, request_body['course']) self.assertEqual(labgroup.instructor.id, request_body['instructor']) self.assertEqual(labgroup.group_name, request_body['group_name']) self.assertEqual(labgroup.term, request_body['term']) self.assertEqual(labgroup.enroll_key, request_body['enroll_key']) # test response self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response_body['pk'], labgroup.id) self.assertEqual(response_body['course'], request_body['course']) self.assertEqual(response_body['instructor'], request_body['instructor']) self.assertEqual(response_body['group_name'], request_body['group_name']) self.assertEqual(response_body['term'], request_body['term']) self.assertEqual(response_body['enroll_key'], request_body['enroll_key']) def test_labgroup_create_different_instructor(self): """ Tests that a labgroup is not created if the instructor passed in is not the instructors making the request. """ # create new user and instructor user = User.objects.create_user(username='******', password='******') instructor = Instructor(user=user, wwuid='9999999') instructor.save() # request request_body = { 'course': self.course.id, 'instructor': instructor.id, 'group_name': 'test name', 'term': 'FALL2000', 'enroll_key': 'test enroll_key', } response = self.client.post(reverse(self.view_name), request_body) # test response self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # test database self.assertFalse(LabGroup.objects.exists()) def test_labgroup_list_instructor(self): """ Tests that labgroups are properly listed for instructors. """ # add labgroups to database LabGroup(course=self.course, instructor=self.instructor, group_name='test name 1', term=get_current_term(), enroll_key='test key 1').save() LabGroup(course=self.course, instructor=self.instructor, group_name='test name 2', term=get_current_term(), enroll_key='test key 2').save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response labgroups = LabGroup.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['labgroups'][0]['pk'], labgroups[0].id) self.assertEqual(response_body['labgroups'][0]['course'], labgroups[0].course.id) self.assertEqual(response_body['labgroups'][0]['instructor'], labgroups[0].instructor.id) self.assertEqual(response_body['labgroups'][0]['group_name'], labgroups[0].group_name) self.assertEqual(response_body['labgroups'][0]['enroll_key'], labgroups[0].enroll_key) self.assertEqual(response_body['labgroups'][0]['term'], labgroups[0].term) self.assertEqual(response_body['labgroups'][1]['pk'], labgroups[1].id) self.assertEqual(response_body['labgroups'][1]['course'], labgroups[1].course.id) self.assertEqual(response_body['labgroups'][1]['instructor'], labgroups[1].instructor.id) self.assertEqual(response_body['labgroups'][1]['group_name'], labgroups[1].group_name) self.assertEqual(response_body['labgroups'][1]['enroll_key'], labgroups[1].enroll_key) self.assertEqual(response_body['labgroups'][1]['term'], labgroups[1].term) def test_labgroup_list_student(self): """ Tests that labgroups are properly listed for students. """ # add labgroups to database LabGroup(course=self.course, instructor=self.instructor, group_name='test name 1', term=get_current_term(), enroll_key='test key 1').save() LabGroup(course=self.course, instructor=self.instructor, group_name='test name 2', term=get_current_term(), enroll_key='test key 2').save() # request self.client.logout() self.client.login(username=self.student_username, password=self.password) response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response labgroups = LabGroup.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response_body['labgroups'][0]['pk'], labgroups[0].id) self.assertEqual(response_body['labgroups'][0]['course'], labgroups[0].course.id) self.assertEqual(response_body['labgroups'][0]['instructor'], labgroups[0].instructor.id) self.assertEqual(response_body['labgroups'][0]['group_name'], labgroups[0].group_name) self.assertTrue('enroll_key' not in response_body['labgroups'][0].keys()) self.assertEqual(response_body['labgroups'][0]['term'], labgroups[0].term) self.assertEqual(response_body['labgroups'][1]['pk'], labgroups[1].id) self.assertEqual(response_body['labgroups'][1]['course'], labgroups[1].course.id) self.assertEqual(response_body['labgroups'][1]['instructor'], labgroups[1].instructor.id) self.assertEqual(response_body['labgroups'][1]['group_name'], labgroups[1].group_name) self.assertTrue('enroll_key' not in response_body['labgroups'][0].keys()) self.assertEqual(response_body['labgroups'][1]['term'], labgroups[1].term) def test_labgroup_visibility_instructor(self): """ Tests that labgroups displayed to instructor were created by that instructor """ # setup second instructor users self.instructor_username_2 = 'different_instructor' self.instructor_user_2 = User.objects.create_user(username=self.instructor_username_2, password=self.password) self.instructor_2 = Instructor(user=self.instructor_user_2, wwuid="7654321") self.instructor_2.save() # add labgroups to database LabGroup(course=self.course, instructor=self.instructor, group_name='test name 1', term=get_current_term(), enroll_key='test key 1').save() LabGroup(course=self.course, instructor=self.instructor_2, group_name='test name 2', term=get_current_term(), enroll_key='test key 2').save() # request response = self.client.get(reverse(self.view_name)) response_body = json.loads(response.content.decode('utf-8')) # test response labgroups = LabGroup.objects.all() self.assertEqual(response.status_code, status.HTTP_200_OK) # assert response_body contains exactly 1 labgroup self.assertEqual(len(response_body['labgroups']), 1) def test_labgroup_filter_by_course(self): """ Tests that labgroups can be filtered by the courses query parameter. """ # add course to database course = Course(name='course name') course.save() # add labgroups to database labgroup = LabGroup(course=course, instructor=self.instructor, group_name='test name 1', term=get_current_term(), enroll_key='test key 1') labgroup.save() LabGroup(course=self.course, instructor=self.instructor, group_name='test name 2', term=get_current_term(), enroll_key='test key 2').save() # request response = self.client.get(reverse(self.view_name), {'course': course.id}) response_body = json.loads(response.content.decode('utf-8')) # test response self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_body['labgroups']), 1) self.assertEqual(response_body['labgroups'][0]['pk'], labgroup.id) self.assertEqual(response_body['labgroups'][0]['course'], labgroup.course.id) self.assertEqual(response_body['labgroups'][0]['instructor'], labgroup.instructor.id) self.assertEqual(response_body['labgroups'][0]['group_name'], labgroup.group_name) self.assertEqual(response_body['labgroups'][0]['term'], labgroup.term) self.assertEqual(response_body['labgroups'][0]['enroll_key'], labgroup.enroll_key)