def test_get_active_course(self): future_course = factory.Course(startdate=timezone.now() + datetime.timedelta(weeks=2)) later_future_course = factory.Course(startdate=timezone.now() + datetime.timedelta(weeks=5)) assignment = factory.Assignment( courses=[future_course, later_future_course]) assert assignment.get_active_course() == future_course, \ 'Select first upcomming course as there is no LTI course or course that has already started' past_course = factory.Course(startdate=timezone.now() - datetime.timedelta(weeks=5)) assignment.courses.add(past_course) recent_course = factory.Course(startdate=timezone.now() - datetime.timedelta(weeks=3)) assignment.courses.add(recent_course) assert assignment.get_active_course() == recent_course, \ 'Select most recent course as there is no LTI course' lti_course = factory.LtiCourseFactory(startdate=timezone.now() + datetime.timedelta(weeks=1)) assignment.courses.add(lti_course) assignment.active_lti_id = 'lti_id' lti_course.assignment_lti_id_set.append('lti_id') lti_course.save() assignment.save() assert assignment.get_active_course( ) == lti_course, 'Select LTI course above all other courses'
def test_delete(self): teach_course = factory.Course(author=self.teacher) other_course = factory.Course() assignment = factory.Assignment( courses=[self.course, teach_course, other_course]) # Test no course specified api.delete(self, 'assignments', params={'pk': assignment.pk}, user=self.teacher, status=400) # Test normal removal resp = api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': teach_course.id }, user=self.teacher) assert 'removed' in resp['description'] and 'deleted' not in resp['description'], \ 'The assignment should be removed from the course, not deleted' # Test if only admins can delete assignments they are not part of resp = api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': other_course.id }, user=self.teacher, status=403) resp = api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': other_course.id }, user=self.teacher, status=403) resp = api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': other_course.id }, user=self.admin, status=200) # Test delete resp = api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': self.course.id }, user=self.teacher) assert 'removed' not in resp['description'] and 'deleted' in resp['description'], \ 'The assignment should be deleted from the course, not removed'
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 test_list(self): course2 = factory.Course(author=self.teacher) factory.Assignment(courses=[self.course]) factory.Assignment(courses=[self.course, course2]) assignment = factory.Assignment() resp = api.get(self, 'assignments', params={'course_id': self.course.pk}, user=self.teacher)['assignments'] assert len(resp) == 2, 'All connected courses should be returned' resp = api.get(self, 'assignments', params={'course_id': course2.pk}, user=self.teacher)['assignments'] assert len(resp) == 1, 'Not connected courses should not be returned' # Connected assignment course = assignment.courses.first() factory.Participation(user=self.teacher, course=course) # Not connected assignment factory.Assignment() resp = api.get(self, 'assignments', user=self.teacher)['assignments'] assert len( resp ) == 3, 'Without a course supplied, it should return all assignments connected to user'
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 test_delete_test_user_participation(self): test_user = factory.TestUser() factory.Participation(user=test_user, course=self.course) api.delete(self, 'participations', params={ 'pk': self.course.pk, 'user_id': test_user.pk }, user=self.teacher) assert not User.objects.filter(pk=test_user.pk).exists(), 'A test user should be deleted upon removal from a ' \ 'course, if the test user has no remaining participations.' test_user = factory.TestUser() factory.Participation(user=test_user, course=self.course) factory.Participation(user=test_user, course=factory.Course()) api.delete(self, 'participations', params={ 'pk': self.course.pk, 'user_id': test_user.pk }, user=self.teacher) assert User.objects.filter(pk=test_user.pk).exists(), 'A test user should not be deleted upon removal from a ' \ 'course, if the test user has remaining participations.'
def test_functions(self): course = factory.Course() course.set_assignment_lti_id_set('lti_id1') assert 'lti_id1' in course.assignment_lti_id_set, 'test if set_assignment_lti_id_set works' course.set_assignment_lti_id_set('lti_id2') course.set_assignment_lti_id_set('lti_id2') assert len( course.assignment_lti_id_set ) == 2, 'test if set_assignment_lti_id_set does not add duplicates'
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_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 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 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_create(self): api.create(self, 'roles', user=self.teacher, status=400) # Test not author of course api.create(self, 'roles', params={ 'course_id': factory.Course().pk, 'name': 'name' }, user=self.teacher, status=403) api.create(self, 'roles', params={ 'course_id': self.course.pk, 'name': 'name' }, user=self.student, status=403) api.create(self, 'roles', params={ 'course_id': self.course.pk, 'name': 'name' }, user=self.teacher) # TODO: Test same name # api.create(self, 'roles', params={'course_id': self.course.pk, 'name': 'name'}, user=self.teacher, # status=400) # Test invalid permissions api.create(self, 'roles', params={ 'course_id': self.course.pk, 'name': 'name', 'permissions': 'invalid_string' }, user=self.teacher, status=400) api.create(self, 'roles', params={ 'course_id': self.course.pk, 'name': 'name', 'permissions': ['invalid', 'list'] }, user=self.teacher, status=400) api.create(self, 'roles', params={ 'course_id': self.course.pk, 'name': 'name', 'permissions': { 'invalid': 'object' } }, user=self.teacher, status=400) resp = api.create(self, 'roles', params={ 'course_id': self.course.pk, 'name': 'name2', 'permissions': { 'can_edit_course_roles': True } }, user=self.teacher) assert resp['role'][ 'can_edit_course_roles'], 'Check if extra permission is also set'