예제 #1
0
 def test_drafts_article_not_found(self):
     article = test_utils.create_article()
     response = test_utils.request_article(self.client, article)
     self.assertEqual(response.status_code, 200)
     article = test_utils.create_article(is_draft=True)
     response = test_utils.request_article(self.client, article)
     self.assertEqual(response.status_code, 404)
예제 #2
0
 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)
예제 #3
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)
예제 #4
0
    def test_single_article(self):
        # Wrong PK.
        response = self.client.get(reverse("blog_article",
                                   kwargs={"article_pk": 9999}))
        self.assertEqual(404, response.status_code)

        article = test_utils.create_article()

        # No slug.
        response = self.client.get(reverse("blog_article",
                                   kwargs={"article_pk": article.pk}))
        self.assertEqual(301, response.status_code)

        # Wrong slug.
        response = self.client.get(reverse(
            "blog_article",
            kwargs={
                "article_pk": article.pk,
                "slug": slugify(test_utils.get_data()),
            },
        ))
        self.assertEqual(301, response.status_code)

        # All OK.
        response = test_utils.request_article(self.client, article)
        self.assertEqual(200, response.status_code)
        self.assertIn(article.title, response.content)
        self.assertIn(article.content, response.content)
예제 #5
0
 def test_has_tags(self):
     article = test_utils.create_article()
     tag1 = test_utils.create_tag(article)
     tag2 = test_utils.create_tag(article)
     response = test_utils.request_article(self.client, article)
     tags = response.context[-1]["article"].tag_set.all()
     self.assertEqual(tag1, tags[0])
     self.assertEqual(tag2, tags[1])
예제 #6
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.
예제 #7
0
 def test_tweet_link(self):
     article = test_utils.create_article(tweet_id=42)
     response = test_utils.request_article(self.client, article)
     expected = article.get_tweet_link()
     actual = response.content
     self.assertIn(expected, actual)
예제 #8
0
 def test_tag_has_link_to_blog_search(self):
     article = test_utils.create_article()
     tag = test_utils.create_tag(article)
     response = test_utils.request_article(self.client, article)
     link = "{}?tags={}".format(reverse("blog_search"), tag.content)
     self.assertIn(link, response.content)
예제 #9
0
 def test_tags_displayed(self):
     article = test_utils.create_article()
     tag = test_utils.create_tag(article)
     response = test_utils.request_article(self.client, article)
     self.assertIn(tag.content, response.content)
예제 #10
0
 def test_no_tags(self):
     article = test_utils.create_article()
     response = test_utils.request_article(self.client, article)
     tags = response.context[-1]["article"].tag_set.all()
     self.assertEqual(0, len(tags))
예제 #11
0
 def test_no_comments(self):
     article = test_utils.create_article()
     response = test_utils.request_article(self.client, article)
     expected = "No comments."
     self.assertIn(expected, response.content)