def test_comment_draft(self): article = test_utils.create_article(is_draft=True) test_utils.create_and_login_user(self.client) response = self.client.post(article.get_absolute_url(), { "article": article.pk, "content": test_utils.get_data(), }) self.assertEqual(response.status_code, 404)
def test_show_or_hide_form(self): article = test_utils.create_article() # As anonymous. response = test_utils.request_article(self.client, article) expected = "login" self.assertIn(expected, response.content) # As member. test_utils.create_and_login_user(self.client) response = test_utils.request_article(self.client, article) self.assertIn("<button>Add comment</button>", response.content)
def test_max_depth(self): """Tests that comment nesting isn't deeper than defined.""" article = test_utils.create_article() comment1 = test_utils.create_comment(article=article) comment2 = test_utils.create_comment(article=article, parent=comment1) test_utils.create_and_login_user(self.client) self.client.post(article.get_absolute_url(), { "article": article.pk, "content": test_utils.get_data(), "parent": comment2.pk, }) self.assertEqual(Comment.objects.count(), settings.MAX_DEPTH_FOR_COMMENT)
def test_duplicate_comment(self): user = test_utils.create_and_login_user(self.client) comment = test_utils.create_comment(author=user) self.client.post(comment.article.get_absolute_url(), { "article": comment.article.pk, "content": comment.content, }) self.assertEqual(Comment.objects.count(), 1)
def test_moderated(self): article = test_utils.create_article(is_comments_moderated=True) user = test_utils.create_and_login_user(self.client) comment = test_utils.create_comment(article=article, author=user, is_moderated=False) response = test_utils.request_article(self.client, article) self.assertIn(comment.content, response.content) self.assertIn("waiting_approval", response.content) self.client.logout() response = test_utils.request_article(self.client, article) self.assertNotIn(comment.content, response.content) self.assertNotIn("waiting_approval", response.content)
def test_add_comment(self): article = test_utils.create_article() # As anonymous. response = self.client.post( article.get_absolute_url(), { "article": article.pk, "content": test_utils.get_data(), } ) self.assertEqual(response.status_code, 403) self.assertFalse(Article.objects.get(pk=article.pk).comment_set .exists()) # As member. test_utils.create_and_login_user(self.client) response = self.client.post( article.get_absolute_url(), { "article": article.pk, "content": test_utils.get_data(), } ) self.assertTrue(Article.objects.get(pk=article.pk).comment_set .exists())
def test_moderated_automatically(self): article = test_utils.create_article(is_comments_moderated=True) user = test_utils.create_and_login_user(self.client) # Special cases aren't special enough. user.is_staff = True user.is_superuser = True user.save() self.client.post( article.get_absolute_url(), { "article": article.pk, "content": test_utils.get_data(), } ) self.assertTrue(Comment.objects.get(article=article).is_moderated)