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_delete(self): api.delete(self, 'participations', params={'pk': self.course.pk}, user=self.teacher, status=400) api.delete(self, 'participations', params={ 'pk': self.course.pk, 'user_id': self.student.pk }, user=self.student, status=403) api.delete(self, 'participations', params={ 'pk': self.course.pk, 'user_id': self.student.pk }, user=self.teacher) api.delete(self, 'participations', params={ 'pk': self.course.pk, 'user_id': self.student.pk }, user=self.teacher, status=404)
def check_comment_delete(self, comment, user, should_succeed): comment_before_op = Comment.objects.get(pk=comment.pk) api.delete(self, 'comments', params={'pk': comment.pk}, user=user, status=200 if should_succeed else 403) if should_succeed: assert not Comment.objects.filter( pk=comment.pk).exists(), 'Comment was not succesfully deleted' comment_before_op.save() else: comment_after_op = Comment.objects.get(pk=comment.pk) assert_comments_are_equal(comment_before_op, comment_after_op)
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 test_delete(self): # Test not can_edit_course_roles api.delete(self, 'roles', params={ 'pk': self.course.pk, 'name': self.roles.first().name }, user=self.student, status=403) # Test delete main role should not be possible api.delete(self, 'roles', params={ 'pk': self.course.pk, 'name': self.roles.filter(name='TA').first().name }, user=self.teacher, status=400) role = factory.Role(course=self.course) api.delete(self, 'roles', params={ 'pk': self.course.pk, 'name': role.name }, user=self.teacher)
def test_delete(self): # Test if only authors and superusers can delete courses api.delete(self, 'courses', params={'pk': self.course1.pk}, user=self.teacher2, status=403) api.delete(self, 'courses', params={'pk': self.course1.pk}, user=self.teacher1) api.delete(self, 'courses', params={'pk': self.course2.pk}, user=self.admin)
def test_lti_delete(self): assignment = factory.LtiAssignment() course = assignment.courses.first() assert assignment.active_lti_id in course.assignment_lti_id_set, \ 'assignment lti_id should be in assignment_lti_id_set of course before anything is deleted' # Test if deletion is possible to delete assignment if it has only one lti id api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': course.pk }, user=factory.Admin()) assert assignment.active_lti_id not in Course.objects.get(pk=course.pk).assignment_lti_id_set, \ 'assignment lti_id should get removed from the assignment_lti_id_set from the course' assignment = factory.LtiAssignment() course = assignment.courses.first() course2 = factory.LtiCourse() assignment.courses.add(course2) assignment.lti_id_set.append('second' + assignment.active_lti_id) assignment.save() # Test is deletion is not possible from connected LTI course api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': course.pk }, user=factory.Admin(), status=400) # Test is deletion is possible from other course api.delete(self, 'assignments', params={ 'pk': assignment.pk, 'course_id': course2.pk }, user=factory.Admin())
def test_delete(self): user = factory.Student() user2 = factory.Student() user3 = factory.Student() admin = factory.Admin() admin2 = factory.Admin() # Test to delete user as other user api.delete(self, 'users', params={'pk': user2.pk}, user=user, status=403) # Test to delete own user api.delete(self, 'users', params={'pk': user.pk}, user=user) api.get(self, 'users', params={'pk': user.pk}, user=admin, status=404) api.delete(self, 'users', params={'pk': 0}, user=user2) api.get(self, 'users', params={'pk': user2.pk}, user=admin, status=404) # Test to delete user as admin api.delete(self, 'users', params={'pk': user3.pk}, user=admin) api.get(self, 'users', params={'pk': user3.pk}, user=admin, status=404) # Test to see if the last admin cannot be removed api.delete(self, 'users', params={'pk': admin2.pk}, user=admin) api.delete(self, 'users', params={'pk': admin.pk}, user=admin, status=400) api.get(self, 'users', params={'pk': admin2.pk}, user=admin, status=404)