def test_comment_author_xor_guest_name_is_null(self): create_user() create_post().save() comment = create_comment() self.assertTrue( comment.author is None and comment.guest_name is not None or comment.author is not None and comment.guest_name is None)
def test_create_comment(self): create_user() post = create_post() post.save() comment = create_comment() now = timezone.now() self.assertEqual(comment.post, post) self.assertLessEqual(comment.created_at, now)
def handle(self, *args, **kwargs): post_count = kwargs["post_count"] if "post_count" in kwargs else 100 user_count = kwargs["user_count"] if "user_count" in kwargs else 10 comment_count = kwargs["comment_count"] if "comment_count" in kwargs else 100 page_count = kwargs["page_count"] if "page_count" in kwargs else 5 [create_user() for _ in xrange(user_count)] [create_post().save() for _ in xrange(post_count)] [create_comment().save() for _ in xrange(comment_count)] [create_page().save() for _ in xrange(page_count)]
def test_post_with_multiple_comments(self): comment_count = 2 [create_comment().save() for i in xrange(comment_count)] response = self.client.get( reverse(POST_DETAIL_URL, args=(self.post.slug, ))) comments = Comment.objects.filter( post=self.post).order_by('created_at') self.assertQuerysetEqual( response.context['object'].comment_set.all(), [repr(comment) for comment in comments])
def test_create_comment_without_posts_in_database(self): with self.assertRaises(IndexError): create_comment()