def test_api_delete_existing(self): request = self.factory.delete(self.path) force_authenticate(request, user=ADMIN) response = request_detail(request, pk=1) self.assertEqual(response.status_code, 200) ## Double Check Deletion with Get Test get_request = self.factory.get(self.path) response = request_detail(get_request, pk=1) self.assertEqual(response.status_code, 404)
def test_api_post_success(self): request = self.factory.post(self.path, {'comment': 'test comment'}) force_authenticate(request, user=ADMIN) response = request_detail(request, pk=1) ## Status Code self.assertEqual(response.status_code, 200) ## Comment Value self.assertEqual(response.data['comment'], 'test comment')
def test_api_delete_nonexisting(self): request = self.factory.delete(self.path) force_authenticate(request, user=ADMIN) response = request_detail(request, pk=2) self.assertEqual(response.status_code, 400)
def test_api_put_no_content(self): request = self.factory.put(self.path) force_authenticate(request, user=ADMIN) response = request_detail(request, pk=1) self.assertEqual(response.status_code, 405)
def test_api_post_failure(self): ## Attempt to update nonexistent field request = self.factory.post(self.path, {'comment1': 'test comment'}) force_authenticate(request, user=ADMIN) response = request_detail(request, pk=1) self.assertEqual(response.status_code, 400)
def test_api_get_not_found(self): request = self.factory.get(self.path) response = request_detail(request, pk=2) self.assertEqual(response.status_code, 404)
def test_api_get_found_comment(self): request = self.factory.get(self.path) response = request_detail(request, pk=1) assert 'comment' in response.data self.assertEqual(response.data['comment'], None)