From a450de8b02babd29508317ef482a536ab0535e32 Mon Sep 17 00:00:00 2001 From: liangliangyy Date: Mon, 24 Apr 2023 22:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=AE=A1=E6=A0=B8=E5=90=8E?= =?UTF-8?q?=E6=89=8D=E8=83=BD=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comments/tests.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/comments/tests.py b/comments/tests.py index b9d9fde..c34eb5b 100644 --- a/comments/tests.py +++ b/comments/tests.py @@ -17,6 +17,12 @@ class CommentsTest(TestCase): self.client = Client() self.factory = RequestFactory() + def update_article_comment_status(self, article): + comments = article.comment_set.all() + for comment in comments: + comment.is_enable = True + comment.save() + def test_validate_comment(self): site = get_current_site().domain user = BlogUser.objects.create_superuser( @@ -53,6 +59,9 @@ class CommentsTest(TestCase): self.assertEqual(response.status_code, 302) article = Article.objects.get(pk=article.pk) + self.assertEqual(len(article.comment_list()), 0) + self.update_article_comment_status(article) + self.assertEqual(len(article.comment_list()), 1) response = self.client.post(comment_url, @@ -63,6 +72,7 @@ class CommentsTest(TestCase): self.assertEqual(response.status_code, 302) article = Article.objects.get(pk=article.pk) + self.update_article_comment_status(article) self.assertEqual(len(article.comment_list()), 2) parent_comment_id = article.comment_list()[0].id @@ -85,7 +95,7 @@ class CommentsTest(TestCase): }) self.assertEqual(response.status_code, 302) - + self.update_article_comment_status(article) article = Article.objects.get(pk=article.pk) self.assertEqual(len(article.comment_list()), 3) comment = Comment.objects.get(id=parent_comment_id)