def setUp(self): """Setup""" self.username, self.password, self.user = test.set_up_user_and_auth( 'test', 'test123', '*****@*****.**') self.rein_user, self.rein_pass, self.rein = test.set_up_user_and_auth( "Rein", "123", '*****@*****.**') self.no_perm_user, self.no_perm_pass, self.no_permission_user = test.set_up_user_and_auth( "no_perm", "123", '*****@*****.**') self.course = factory.make_course("Beeldbewerken", "BB", enddate=timezone.now())
def setUp(self): """Set up the test file.""" self.username, self.password, self.user = test.set_up_user_and_auth( 'test123', 'test123', '*****@*****.**') self.rein_user, self.rein_pass, self.rein = test.set_up_user_and_auth( "Rein", "123", '*****@*****.**') self.no_perm_user, self.no_perm_pass, self.no_permission_user = test.set_up_user_and_auth( "no_perm", "123", '*****@*****.**') self.course = factory.make_course("Beeldbewerken", "BB") self.lars = factory.make_user("Lars", "123", "*****@*****.**") self.student1 = factory.make_user("Student1", "123", "Student1.com") self.student2 = factory.make_user("Student2", "123", "Student2.com") self.not_found_pk = 9999
def setUp(self): # Create superuser self.supername, self.superpass, self.user = test.set_up_user_and_auth( 'super', 'pass', '*****@*****.**') self.user.is_superuser = True self.user.save() # Create student self.studentname, self.studentpass, self.student = test.set_up_user_and_auth( 'student', 'pass', '*****@*****.**') self.instance_data = { 'name': 'UvA', }
def test_get_comments(self): """Test update comment function.""" course = factory.make_course('Portfolio', 'PAV', author=self.rein) template = factory.make_entry_template('template') format = factory.make_format([template]) assignment = factory.make_assignment('Colloq', 'description1', format=format, courses=[course]) student_user, student_pass, student = test.set_up_user_and_auth( 'student', 'pass', '*****@*****.**') test.set_up_participation(student, course, 'Student') journal = factory.make_journal(assignment, student) entry = factory.make_entry(template) factory.make_node(journal, entry) comment = factory.make_comment(entry, self.rein, 'Excellent!', True) login = test.logging_in(self, self.rein_user, self.rein_pass) update_dict = {'text': 'Bad!'} test.api_patch_call(self, '/comments/' + str(comment.pk) + '/', update_dict, login) q_comment = Comment.objects.get(pk=comment.pk) self.assertEquals(q_comment.text, 'Bad!')
def test_update_course_roles(self): """Test update course roles""" teacher_user, teacher_pass, teacher = test.set_up_user_and_auth( 'Teacher', 'pass', '*****@*****.**') teacher_role = factory.make_role_teacher("TE", self.course) factory.make_role_ta('TA2', self.course) factory.make_participation(teacher, self.course, teacher_role) login = test.logging_in(self, teacher_user, teacher_pass) result = test.api_get_call(self, '/roles/', login, params={'course_id': self.course.pk}) roles = result.json()['roles'] for role in roles: if role['name'] == 'TA2': role['can_grade'] = 1 roles.append( serialize.RoleSerializer( factory.make_role_default_no_perms('test_role', self.course)).data) test.api_patch_call(self, '/roles/{}/'.format(self.course.pk), {'roles': roles}, login) role_test = Role.objects.get(name='TA2', course=self.course) self.assertTrue(role_test.can_grade) self.assertEquals( Role.objects.filter(name='test_role', course=self.course).count(), 1)
def test_create_entry(self): """"Test create entry.""" _, _, user2 = test.set_up_user_and_auth('testh', 'test123h', '*****@*****.**') course = factory.make_course('Portfolio', 'PAV', author=user2) template = factory.make_entry_template("some_template") format = factory.make_format([template]) assignment = factory.make_assignment("Assignment", "Your favorite assignment", format=format, courses=[course]) journal = factory.make_journal(assignment, self.user) field = factory.make_field(template, 'Some field', 0) login = test.logging_in(self, self.username, self.password) format.available_templates.add(template) role = factory.make_role_default_no_perms("student", course, can_have_journal=True) factory.make_participation(user=self.user, course=course, role=role) create_entry_dict = { 'journal_id': journal.id, 'template_id': template.id, 'content': [{ 'id': field.pk, 'data': "This is some data" }] } test.api_post_call(self, '/entries/', create_entry_dict, login, 201) self.assertTrue(Entry.objects.filter(node__journal=journal).exists()) self.assertEquals( Content.objects.get(entry=1).data, "This is some data")
def test_get_names(self): """Test get names function.""" course = factory.make_course('Portfolio', 'PAV', author=self.rein) template = factory.make_entry_template('template') format = factory.make_format([template]) assignment = factory.make_assignment('Colloq', 'description1', format=format, courses=[course], is_published=True) student_user, student_pass, student = test.set_up_user_and_auth( 'student', 'pass', '*****@*****.**', 'first', 'last') test.set_up_participation(student, course, 'Student') journal = test.set_up_journal(assignment, template, student, 4) login = test.logging_in(self, student_user, student_pass) url = '/names/{}/{}/{}/'.format(course.pk, assignment.pk, journal.pk) result = test.api_get_call(self, url, login).json() self.assertEquals(result['names']['course'], 'Portfolio') self.assertEquals(result['names']['journal'], 'first last') self.assertEquals(result['names']['assignment'], 'Colloq') # permissions and authorization check for the api call. login = test.logging_in(self, self.no_perm_user, self.no_perm_pass) test.api_get_call(self, url, login, status=403)
def test_get_course_users(self): """Test the get course users function.""" teacher_user, teacher_pass, teacher = test.set_up_user_and_auth( 'teacher', 'pass', '*****@*****.**') test.set_up_participation(teacher, self.course, 'Teacher') test.set_up_participation(self.lars, self.course, 'Student') test.set_up_participation(self.rein, self.course, 'TA') login = test.logging_in(self, teacher_user, teacher_pass) response = test.api_get_call(self, '/participations/', login, params={'course_id': self.course.pk}) self.assertEquals(len(response.json()['participants']), 3) response = test.api_get_call(self, '/participations/unenrolled/', login, params={ 'course_id': self.course.pk, 'unenrolled_query': 'test123' }) self.assertEquals(len(response.json()['participants']), 1) self.assertEquals(response.json()['participants'][0]['username'], self.username) # permissions and authorization check for the api call. login = test.logging_in(self, self.no_perm_user, self.no_perm_pass) test.api_get_call(self, '/participations/', login, status=403, params={'course_id': self.course.pk}) test.api_get_call(self, '/participations/', login, status=404, params={'course_id': self.not_found_pk}) test.test_unauthorized_api_get_call( self, '/participations/', params={'course_id': self.not_found_pk}) test.test_unauthorized_api_get_call( self, '/courses/' + str(self.course.pk) + '/') test.test_unauthorized_api_get_call( self, '/participations/unenrolled/', params={'course_id': self.course.pk}) test.set_up_participation(self.no_permission_user, self.course, 'Student') test.api_get_call(self, '/participations/', login, status=403, params={'course_id': self.course.pk})
def test_get_nodes(self): """Test the get nodes function.""" course = factory.make_course('Portfolio', 'PAV', author=self.rein) template = factory.make_entry_template('template') format = factory.make_format([template]) assignment = factory.make_assignment('Colloq', 'description1', format=format, courses=[course]) student_user, student_pass, student = test.set_up_user_and_auth( 'student', 'pass', '*****@*****.**') test.set_up_participation(student, course, 'Student') journal = test.set_up_journal(assignment, template, student, 4) login = test.logging_in(self, student_user, student_pass) response = test.api_get_call(self, '/nodes/', login, params={'journal_id': journal.pk}) result = response.json() self.assertEquals(len(result['nodes']), 5) login = test.logging_in(self, self.rein_user, self.rein_pass) response = test.api_get_call(self, '/nodes/', login, params={'journal_id': journal.pk}) result = response.json() self.assertEquals(len(result['nodes']), 4) # permissions and authorization check for the api call. login = test.logging_in(self, self.no_perm_user, self.no_perm_pass) test.api_get_call(self, '/nodes/', login, status=403, params={'journal_id': journal.pk}) test.api_get_call(self, '/nodes/', login, status=404, params={'journal_id': self.not_found_pk}) test.test_unauthorized_api_get_call(self, '/nodes/', params={'journal_id': journal.pk})
def setUp(self): """Setup.""" self.factory = RequestFactory() self.request = { "oauth_consumer_key": settings.LTI_KEY, "oauth_signature_method": "HMAC-SHA1", "oauth_version": "1.0", "custom_assignment_due": "2018-11-10 23:59:00 +0100", "custom_assignment_id": "bughh", "custom_assignment_lock": "2018-12-15 23:59:59 +0100", "custom_assignment_title": "TestAss", "custom_assignment_unlock": "2018-08-16 00:00:00 +0200", "custom_assignment_points": "10", "custom_assignment_publish": "true", "custom_course_id": "asdf", "custom_course_name": "TestCourse", "custom_course_start": "2018-06-15 14:41:00 +0200", "context_label": "aaaa", "lti_message_type": "basic-lti-launch-request", "lti_version": "LTI-1p0", 'custom_username': '******', "roles": "Instructor", "custom_user_image": "https://uvadlo-tes.instructure.com/images/thumbnails/11601/\ 6ivT7povCYWoXPCVOSnfPqWADsLktcGXTXkAUYDv", "user_id": "0000" } self.oauth_consumer = oauth2.Consumer(settings.LTI_KEY, settings.LTI_SECRET) self.username, self.password, self.user = test.set_up_user_and_auth( 'TestUser', 'Pass', '*****@*****.**') self.user.lti_id = 'awefd' self.user.verified_email = True self.user.save() self.created_assignment = factory.make_assignment( "TestAss", "TestDescr") self.created_journal = factory.make_journal(self.created_assignment, self.user)
def test_get_comments(self): """Test get comments function.""" course = factory.make_course('Portfolio', 'PAV', author=self.rein) template = factory.make_entry_template('template') format = factory.make_format([template]) assignment = factory.make_assignment('Colloq', 'description1', format=format, courses=[course]) student_user, student_pass, student = test.set_up_user_and_auth( 'student', 'pass', '*****@*****.**') test.set_up_participation(student, course, 'Student') journal = factory.make_journal(assignment, student) entry = factory.make_entry(template) factory.make_node(journal, entry) factory.make_comment(entry, self.rein, 'Excellent!', True) login = test.logging_in(self, student_user, student_pass) result = test.api_get_call(self, '/comments/', login, params={ 'entry_id': entry.pk }).json() self.assertEquals(result['comments'][0]['text'], 'Excellent!') # permissions and authorization check for the api call. login = test.logging_in(self, self.no_perm_user, self.no_perm_pass) test.api_get_call(self, '/comments/', login, status=403, params={'entry_id': entry.pk}) test.api_get_call(self, '/comments/', login, status=404, params={'entry_id': self.not_found_pk}) test.test_unauthorized_api_get_call(self, '/comments/', params={'entry_id': entry.pk})
def test_get_lti_params_from_jwt_wrong_user(self): """Hopefully returns an error that tells wrong user logged in.""" login = test.logging_in(self, self.username, self.password) self.request["user_id"] = "12def" self.username, self.password, self.user = test.set_up_user_and_auth( 'TestUser2', 'Pass', '*****@*****.**') self.user.lti_id = '12def' self.user.verified_email = True self.user.save() jwt_params = jwt.encode(self.request, settings.SECRET_KEY, algorithm='HS256').decode('utf-8') response = test.api_get_call( self, '/get_lti_params_from_jwt/{0}/'.format(jwt_params), login=login, status=403) self.assertIn( "The user specified that should be logged in according to the request is not the logged in user.", response.content.decode('utf-8'))
def test_update_assignment(self): """Test update assignment""" teacher_user, teacher_pass, teacher = test.set_up_user_and_auth( 'Teacher', 'pass', '*****@*****.**') teacher_role = factory.make_role_teacher("TE", self.course) factory.make_participation(teacher, self.course, teacher_role) assign = test.set_up_assignments('Assign', '', 1, self.course)[0] login = test.logging_in(self, teacher_user, teacher_pass) test.api_patch_call(self, '/assignments/' + str(assign.pk) + '/', { 'name': 'Assign2', 'description': 'summary', 'is_published': True }, login) assign = Assignment.objects.get(pk=assign.pk) self.assertEquals(assign.name, 'Assign2') self.assertEquals(assign.description, 'summary')
def test_create_new_course(self): """Test create new course.""" username, password, user = test.set_up_user_and_auth('test2', 'test1233', '*****@*****.**', is_teacher=True) lti_id = '12AB' login = test.logging_in(self, username, password) create_course_dict = { 'name': 'Beeldbewerken', 'abbreviation': 'BB', 'lti_id': lti_id } test.api_post_call(self, '/courses/', params=create_course_dict, login=login, status=201) self.assertEquals( Lti_ids.objects.get(lti_id=lti_id).course.name, 'Beeldbewerken')
def test_GDPR(self): # Test normal user login = test.logging_in(self, self.username, self.password) _, _, other_user = test.set_up_user_and_auth('teacher', 'pass', '*****@*****.**') # Other user test.api_get_call(self, '/users/{0}/GDPR/'.format(other_user.pk), login, status=403) # Multiple times its own for _ in range( int(api_settings.DEFAULT_THROTTLE_RATES['gdpr'].split('/') [0])): test.api_get_call(self, '/users/0/GDPR/', login) test.api_get_call(self, '/users/0/GDPR/', login, status=429) # Test super user self.user.is_superuser = True self.user.save() # Other user test.api_get_call(self, '/users/{0}/GDPR/'.format(other_user.pk), login, status=403) # Multiple times its own for _ in range( int(api_settings.DEFAULT_THROTTLE_RATES['gdpr'].split('/') [0])): test.api_get_call(self, '/users/0/GDPR/', login) test.api_get_call(self, '/users/0/GDPR/', login) self.user.is_superuser = False self.user.save()
def setUp(self): """Set up the test file.""" self.username, self.password, self.user = test.set_up_user_and_auth('test', 'test123', '*****@*****.**') self.teacher = test.set_up_users('teacher', 1)[0]
def setUp(self): """Setup.""" self.username, self.password, self.user = test.set_up_user_and_auth( 'test', 'test123', '*****@*****.**')
def test_get_unenrolled_users(self): """Test the get get_unenrolledusers.""" teacher_user, teacher_pass, teacher = test.set_up_user_and_auth( 'teacher', 'pass', '*****@*****.**') test.set_up_participation(teacher, self.course, 'Teacher') test.set_up_participation(self.lars, self.course, 'Student') test.set_up_participation(self.rein, self.course, 'TA') login = test.logging_in(self, teacher_user, teacher_pass) response = test.api_get_call(self, '/participations/unenrolled/', login, params={ 'course_id': self.course.pk, 'unenrolled_query': 'test12' }) self.assertEquals(len(response.json()['participants']), 1) self.assertEquals(response.json()['participants'][0]['username'], self.username) response = test.api_get_call(self, '/participations/unenrolled/', login, params={ 'course_id': self.course.pk, 'unenrolled_query': 'Student' }) self.assertEquals(len(response.json()['participants']), 2) response = test.api_get_call(self, '/participations/unenrolled/', login, params={ 'course_id': self.course.pk, 'unenrolled_query': 'no_perm' }) self.assertEquals(len(response.json()['participants']), 1) self.assertEquals(response.json()['participants'][0]['username'], self.no_perm_user) login = test.logging_in(self, self.no_perm_user, self.no_perm_pass) test.api_get_call(self, '/participations/unenrolled/', login, status=403, params={ 'course_id': self.course.pk, 'unenrolled_query': '' }) test.test_unauthorized_api_get_call(self, '/participations/unenrolled/', params={ 'course_id': self.course.pk, 'unenrolled_query': '' }) test.set_up_participation(self.no_permission_user, self.course, 'Student') test.api_get_call(self, '/participations/unenrolled/', login, status=403, params={ 'course_id': self.course.pk, 'unenrolled_query': '' })
def setUp(self): """Setup""" self.username, self.password, self.user = test.set_up_user_and_auth( 'test', 'test123', '*****@*****.**') self.course = factory.make_course("Beeldbewerken", "BB")