def setUp(self): self.create_params = {'name': 'test_course', 'abbreviation': 'TC'} self.student = factory.Student() self.teacher1 = factory.Teacher() self.teacher2 = factory.Teacher() self.admin = factory.Admin() self.course1 = factory.Course(author=self.teacher1) self.course2 = factory.Course(author=self.teacher1) self.course3 = factory.Course(author=self.teacher2)
def setUp(self): self.teacher = factory.Teacher() self.course = factory.Course(author=self.teacher) self.assignment = factory.Assignment(courses=[self.course]) participation = factory.Participation(course=self.course) self.student = participation.user self.roles = VLE.models.Role.objects.all()
def setUp(self): self.teacher = factory.Teacher() self.admin = factory.Admin() self.course = factory.Course(author=self.teacher) self.create_params = { 'name': 'test', 'description': 'test_description', 'course_id': self.course.pk }
def test_get(self): assignment = self.journal.assignment course = assignment.courses.first() payload = {'assignment_id': assignment.pk, 'course_id': course.pk} # Test list api.get(self, 'journals', params=payload, user=self.student, status=403) api.get(self, 'journals', params=payload, user=self.teacher) # Test get api.get(self, 'journals', params={'pk': self.journal.pk}, user=self.student) api.get(self, 'journals', params={'pk': self.journal.pk}, user=self.teacher) api.get(self, 'journals', params={'pk': self.journal.pk}, user=factory.Teacher(), status=403)
def setUp(self): """Setup.""" self.student = factory.Student() self.teacher = factory.Teacher() self.course = factory.LtiCourse(author=self.teacher) self.assignment = factory.LtiAssignment(author=self.teacher, courses=[self.course]) self.journal = factory.Journal( assignment=self.assignment, user=self.student, sourcedid='f6d552', grade_url= 'https://uvadlo-tes.instructure.com/api/lti/v1/tools/267/grade_passback' )
def test_update(self): api.update(self, 'instance', params={'pk': 0}, user=factory.Teacher(), status=403) admin = factory.Admin() resp = api.update(self, 'instance', params={ 'pk': 0, 'name': 'B1' }, user=admin) assert resp['instance']['name'] == 'B1'
def test_copyable(self): teacher = factory.Teacher() course = factory.Course(author=teacher) assignment = factory.TemplateAssignment(courses=[course]) factory.TemplateFormat(assignment=assignment) assignment2 = factory.TemplateAssignment(courses=[course]) factory.TemplateFormat(assignment=assignment2) journal = factory.Journal(assignment=assignment2) [factory.Entry(node__journal=journal) for _ in range(4)] resp = api.get(self, 'assignments/copyable', params={'pk': assignment.pk}, user=teacher)['data'] assert len(resp[0]['assignments']) == 1 assert resp[0]['course'][ 'id'] == course.id, 'copyable assignments should be displayed' before_id = api.get(self, 'formats', params={'pk': assignment2.pk}, user=teacher)['format']['templates'][0]['id'] before_from_id = api.get(self, 'formats', params={'pk': assignment.pk}, user=teacher)['format']['templates'][0]['id'] resp = api.update(self, 'formats/copy', params={ 'pk': assignment2.pk, 'from_assignment_id': assignment.pk }, user=teacher) after_id = api.get(self, 'formats', params={'pk': assignment2.pk}, user=teacher)['format']['templates'][0]['id'] after_from_id = api.get(self, 'formats', params={'pk': assignment.pk}, user=teacher)['format']['templates'][0]['id'] assert before_id != after_id, 'Assignment should be changed' assert before_from_id == after_from_id, 'From assignment templates should be unchanged' assert len(utils.get_journal_entries( journal)) == 4, 'Old entries should not be removed'
def test_get(self): api.get(self, 'nodes', params={'journal_id': self.journal.pk}, user=self.student) api.get(self, 'nodes', params={'journal_id': self.journal.pk}, user=factory.Admin()) api.get(self, 'nodes', params={'journal_id': self.journal.pk}, user=factory.Teacher(), status=403) api.get(self, 'nodes', params={'journal_id': self.journal.pk}, user=self.teacher)
def setUp(self): self.teacher = factory.Teacher() self.course = factory.Course(author=self.teacher) factory.Assignment(courses=[self.course]) participation = factory.Participation(course=self.course) self.student = participation.user # Username is 4 chartacters for the unenrolled check self.not_connected = factory.Student(username='******', full_name='Not Connected') self.create_params = { 'course_id': self.course.pk, 'user_id': self.not_connected.pk } self.group1 = factory.Group(course=self.course) self.group2 = factory.Group(course=self.course) self.update_params = { 'pk': self.course.pk, 'user_id': self.student.pk, 'role': 'Teacher' }
def test_rest(self): # Test the basic rest functionality as a superuser api.test_rest(self, 'courses', create_params=self.create_params, update_params={'abbreviation': 'TC2'}, user=factory.Admin()) # Test the basic rest functionality as a teacher api.test_rest(self, 'courses', create_params=self.create_params, update_params={'abbreviation': 'TC2'}, user=factory.Teacher()) # Test the basic rest functionality as a student api.test_rest(self, 'courses', create_params=self.create_params, create_status=403, user=factory.Student())
def setUp(self): self.teacher = factory.Teacher() self.admin = factory.Admin() self.course = factory.Course(author=self.teacher) self.assignment = factory.Assignment(courses=[self.course]) self.format = factory.Format(assignment=self.assignment) self.template = factory.Template(format=self.format) self.update_dict = { 'assignment_details': { 'name': 'Colloq', 'description': 'description1', 'is_published': True }, 'templates': serialize.TemplateSerializer( self.format.template_set.filter(archived=False), many=True).data, 'removed_presets': [], 'removed_templates': [], 'presets': [] }
def test_lti_update(self): # Valid LTI coupling to pre-existing account user = factory.Student(verified_email=False) resp = api.update(self, 'users', user=user, params={ **gen_jwt_params(params={ 'user_id': 'valid_id1', 'custom_user_full_name': 'new full name', 'custom_user_email': '*****@*****.**', 'custom_user_image': 'https://new.com/img.png', }, user=user), 'pk': user.pk, })['user'] user = User.objects.get(pk=user.pk) assert user.lti_id, 'Pre-existing user should now be linked via LTI' assert resp[ 'full_name'] == 'new full name' and user.full_name == 'new full name', 'Full name should be updated' assert user.verified_email, 'Updating email via LTI should also verify it' assert resp[ 'email'] == '*****@*****.**' and user.email == '*****@*****.**', 'Email should be updated' assert user.profile_picture == 'https://new.com/img.png', 'Profile picture should be updated.' # Cannot couple an account using an already known LTI id user2 = factory.Student() resp = api.update(self, 'users', user=user2, params={ **gen_jwt_params(params={'user_id': user.lti_id}, user=user2), 'pk': user2.pk, }, status=400) assert 'lti id already exists' in resp['description'] # Cannot link to a user when the email address is already claimed resp = api.update( self, 'users', user=user2, params={ **gen_jwt_params(params={'custom_user_email': user.email}), 'pk': user2.pk, }, status=400) assert 'is taken' in resp[ 'description'], 'Cannot link to a user when the email address is already claimed' # It is forbidden to link a test account to an existing account lti_teacher = factory.LtiTeacher() resp = api.update( self, 'users', user=lti_teacher, params={ **gen_jwt_params(params=factory.JWTTestUserParams()), 'pk': 0, }, status=403) teacher = factory.Teacher() resp = api.update( self, 'users', user=teacher, params={ **gen_jwt_params(params=factory.JWTTestUserParams()), 'pk': 0, }, status=403)