def create_comment(post, text='a comment', author=None): if author is None: author, is_created = User.objects.get_or_create( username='guset', password='guestpassword' ) comment = Comment.objects.create( post = post, text = text, author = author ) return comment def test_comment(self): post_000 = create_post( title="The first post", content="Hello World. We are the world.", author=self.author_000, ) self.assertEqual(Comment.objects.count(), 0) comment_000 = create_comment( post=post_000 ) comment_001 = create_comment( post=post_000, text='second comment' ) self.assertEqual(Comment.objects.count(), 2) self.assertEqual(post_000.comment_set.count(), 2)
|