Write a unit test for the post create view

This commit is contained in:
Maximilian Friedersdorff 2022-07-07 22:01:50 +01:00
parent 4180203bd1
commit 4e8af9b0a5

View file

@ -106,3 +106,15 @@ class PostViewsTests(TestCase):
url = reverse("posts:post_detail", kwargs={"pk": self.post.pk})
c.post(url, {"comment": ""})
self.assertFalse(self.post.comments.all().exists())
def test_can_post_a_post(self):
c = Client()
c.login(username="someone", password="secret")
url = reverse("posts:post_create")
with open(
os.path.join(os.path.dirname(__file__), "test_data", "test_img.png"),
mode="rb",
) as f:
c.post(url, {"title": "title", "body": "body", "img": File(f)})
self.assertEqual(Post.objects.count(), 2)