コード例 #1
0
 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)
コード例 #2
0
    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')
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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)