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])
def test_by_tags(self): article = test_utils.create_article() tag1 = test_utils.create_tag(article, content="spam") tag2 = test_utils.create_tag(article, content="eggs") tags = "{},{}".format(tag1.content, tag2.content) response = self.client.get(reverse("blog_search"), {"tags": tags}) found_articles = response.context[-1]["found_articles"] self.assertEqual(list(found_articles), [article])
def test_blog_tags(self): tag1 = test_utils.create_tag() tag2 = test_utils.create_tag() test_utils.create_tag(content=tag2.content) response = self.client.get(reverse("blog_tags")) tags = response.context[-1]["tags"] tag1 = {"content": tag1.content, "priority": 1} tag2 = {"content": tag2.content, "priority": 2} # The order is randomed. try: self.assertEqual(tags, [tag1, tag2]) except AssertionError: self.assertEqual(tags, [tag2, tag1])
def test_by_tag(self): article = test_utils.create_article() tag = test_utils.create_tag(article, content="spam") response = self.client.get(reverse("blog_search"), {"tags": tag.content}) found_articles = response.context[-1]["found_articles"] self.assertEqual(list(found_articles), [article])
def test_by_phrase_and_tags(self): article_content = "spam" tag_content1 = "eggs" tag_content2 = "cheese" article1 = test_utils.create_article(content=article_content) article2 = test_utils.create_article(content=article_content) test_utils.create_tag(article1, content=tag_content1) test_utils.create_tag(article2, content=tag_content1) test_utils.create_tag(article2, content=tag_content2) response = self.client.get(reverse("blog_search"), { "phrase": article_content, "tags": "{}, {}".format(tag_content1, tag_content2) }) found_articles = response.context[-1]["found_articles"] self.assertEqual(list(found_articles), [article2])
def test_drafts_excluded(self): article = test_utils.create_article(is_draft=True) test_utils.create_tag(article) response = self.client.get(reverse("blog_tags")) tags = response.context[-1]["tags"] self.assertEqual(0, len(tags))
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)
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)