Write a unit test for the post create view
This commit is contained in:
parent
4180203bd1
commit
4e8af9b0a5
1 changed files with 12 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue