Пример #1
0
 def test_get_depth(self):
     comment1 = test_utils.create_comment()
     comment2 = test_utils.create_comment(article=comment1.article,
                                          parent=comment1)
     comment3 = test_utils.create_comment(article=comment2.article,
                                          parent=comment2)
     self.assertEqual(1, comment1.get_depth())
     self.assertEqual(3, comment3.get_depth())
Пример #2
0
 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)
Пример #3
0
 def test_nested_comments(self):
     """Testing order and depth of comments."""
     article = test_utils.create_article()
     comment1 = test_utils.create_comment(article=article)
     comment2 = test_utils.create_comment(article=article)
     comment3 = test_utils.create_comment(article=article, parent=comment1)
     comment4 = test_utils.create_comment(article=article, parent=comment3)
     response = test_utils.request_article(self.client, article)
     expected_comments = [comment1, comment3, comment4, comment2]
     actual_comments = list(response.context[-1]["article"].get_comments())
     self.assertEqual(expected_comments, actual_comments)  # Order.
     expected_depth = [1, 2, 3, 1]
     actual_depth = [comment.depth for comment in actual_comments]
     self.assertEqual(expected_depth, actual_depth)  # Depth.
Пример #4
0
 def test_xss_vulnerability(self):
     content = "<script>alert('foo')</script>"
     comment = test_utils.create_comment(content=content)
     expected = ("<p>&lt;script&gt;alert(&#8216;foo&#8217;)"
                 "&lt;/script&gt;</p>")
     actual = comment.get_content_as_html()
     self.assertEqual(expected, actual)
Пример #5
0
 def test_comment_count(self):
     article = test_utils.create_article()
     test_utils.create_comment(article=article)
     test_utils.create_comment(article=article)
     self.assertEqual(article.get_comment_count(), 2)
     article = test_utils.create_article(is_comments_moderated=True)
     test_utils.create_comment(article=article, is_moderated=True)
     test_utils.create_comment(article=article)
     self.assertEqual(article.get_comment_count(), 1)
Пример #6
0
 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)
Пример #7
0
 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)
Пример #8
0
 def test_feed_moderation(self):
     article = test_utils.create_article(is_comments_moderated=True)
     comment = test_utils.create_comment(article=article, is_moderated=True)
     response = self.client.get(reverse("blog_comments_rss_feed"))
     self.assertIn(comment.content, response.content)
     comment.is_moderated = False
     comment.save()
     response = self.client.get(reverse("blog_comments_rss_feed"))
     self.assertNotIn(comment.content, response.content)
     article.is_comments_moderated = False
     article.save()
     comment.is_moderated = False
     comment.save()
     response = self.client.get(reverse("blog_comments_rss_feed"))
     self.assertIn(comment.content, response.content)
Пример #9
0
 def test_comments_feed_drafts_excluded(self):
     article = test_utils.create_article(is_draft=True)
     comment = test_utils.create_comment(article=article)
     response = self.client.get(reverse("blog_comments_rss_feed"))
     self.assertNotIn(comment.content, response.content)
Пример #10
0
 def test_comments_feed(self):
     comment = test_utils.create_comment()
     response = self.client.get(reverse("blog_comments_rss_feed"))
     self.assertIn(comment.content, response.content)