def test_get_user_student(self): view = UsersDetail.as_view() request = self.factory.get(self.getApiUrl() + str(self.admin.id) + '/') self.loginStudent(request) response = view(request, pk=self.admin.id) self.assertEqual(response.status_code, 403)
def test_get_user_unauthenticated(self): view = UsersDetail.as_view() request = self.factory.get(self.getApiUrl() + str(self.student.id) + '/') response = view(request, pk=self.student.id) self.assertEqual(response.status_code, 401)
def test_delete_user_unauthenticated(self): view = UsersDetail.as_view() request = self.factory.delete(self.getApiUrl() + str(self.student.id) + '/') response = view(request, pk=self.student.id) self.assertEqual(len(User.objects.all()), 3) self.assertEqual(response.status_code, 401)
def test_update_user_unauthenticated(self): view = UsersDetail.as_view() data = {'name': 'NewName'} request = self.factory.patch( self.getApiUrl() + str(self.student.id) + '/', data) response = view(request, pk=self.student.id) self.assertEqual(response.status_code, 401)
def test_get_user(self): view = UsersDetail.as_view() request = self.factory.get(self.getApiUrl() + str(self.student.id) + '/') force_authenticate(request, user=self.professor, token=self.professor.auth_token) response = view(request, pk=self.student.id) self.assertEqual(response.status_code, 200)
def test_delete_user(self): self.assertEqual(len(User.objects.all()), 3) view = UsersDetail.as_view() request = self.factory.delete(self.getApiUrl() + str(self.student.id) + '/') self.loginProfessor(request) response = view(request, pk=self.student.id) self.assertEqual(len(User.objects.all()), 2) self.assertEqual(response.status_code, 204)
def test_update_user(self): view = UsersDetail.as_view() data = {'username': '******'} request = self.factory.patch( self.getApiUrl() + str(self.student.id) + '/', data) force_authenticate(request, user=self.professor, token=self.professor.auth_token) response = view(request, pk=self.student.id) user = User.objects.get(pk=self.student.id) self.assertEqual(response.status_code, 200) self.assertEqual(user.username, 'NewName')