Example #1
0
 def test_get_post(self):
     test_fields = ["author", "title", "body"]
     post_id = "1"
     data = PostSerializer(Post.objects.get(pk=post_id), context={"request": self.request}).data
     url = reverse("post-detail", kwargs={"pk": post_id})
     response = self.client.get(url, format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK, msg=(url, response.status_code, data))
     self.assertEqual(
         [response.data.get(field) for field in test_fields],
         [data.get(field) for field in test_fields],
         msg=(response.data, data),
     )
Example #2
0
 def test_create_post(self):
     test_fields = ["author", "title", "body"]
     post_id = "1"
     data = PostSerializer(Post.objects.get(pk=post_id), context={"request": self.request}).data
     url = reverse("post-list")
     response = self.client.post(url, data, format="json")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED, msg=(url, response.status_code, data))
     self.assertEqual(
         [response.data.get(field) for field in test_fields],
         [data.get(field) for field in test_fields],
         msg=(response.data, data),
     )