Add category taxonomy and navigation integration
Implements Issue #35 with category snippets, article category routing, category-aware templates, and category RSS feeds with tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from taggit.models import Tag
|
||||
|
||||
from apps.blog.models import ArticleIndexPage, ArticlePage
|
||||
from apps.blog.models import ArticleIndexPage, ArticlePage, Category
|
||||
from apps.blog.tests.factories import AuthorFactory
|
||||
from apps.comments.models import Comment
|
||||
|
||||
@@ -161,3 +161,75 @@ def test_article_index_renders_tag_filter_controls(client, home_page):
|
||||
html = resp.content.decode()
|
||||
assert resp.status_code == 200
|
||||
assert "/articles/?tag=tag-one" in html
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_article_index_category_route_filters_articles(client, home_page):
|
||||
index = ArticleIndexPage(title="Articles", slug="articles")
|
||||
home_page.add_child(instance=index)
|
||||
author = AuthorFactory()
|
||||
reviews = Category.objects.create(name="Reviews", slug="reviews")
|
||||
tutorials = Category.objects.create(name="Tutorials", slug="tutorials")
|
||||
review_article = ArticlePage(
|
||||
title="Review A",
|
||||
slug="review-a",
|
||||
author=author,
|
||||
summary="summary",
|
||||
body=[("rich_text", "<p>body</p>")],
|
||||
category=reviews,
|
||||
)
|
||||
tutorial_article = ArticlePage(
|
||||
title="Tutorial A",
|
||||
slug="tutorial-a",
|
||||
author=author,
|
||||
summary="summary",
|
||||
body=[("rich_text", "<p>body</p>")],
|
||||
category=tutorials,
|
||||
)
|
||||
index.add_child(instance=review_article)
|
||||
review_article.save_revision().publish()
|
||||
index.add_child(instance=tutorial_article)
|
||||
tutorial_article.save_revision().publish()
|
||||
|
||||
resp = client.get("/articles/category/reviews/")
|
||||
html = resp.content.decode()
|
||||
assert resp.status_code == 200
|
||||
assert "Review A" in html
|
||||
assert "Tutorial A" not in html
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_article_index_category_route_supports_tag_filter(client, home_page):
|
||||
index = ArticleIndexPage(title="Articles", slug="articles")
|
||||
home_page.add_child(instance=index)
|
||||
author = AuthorFactory()
|
||||
reviews = Category.objects.create(name="Reviews", slug="reviews")
|
||||
keep = ArticlePage(
|
||||
title="Keep Me",
|
||||
slug="keep-me",
|
||||
author=author,
|
||||
summary="summary",
|
||||
body=[("rich_text", "<p>body</p>")],
|
||||
category=reviews,
|
||||
)
|
||||
drop = ArticlePage(
|
||||
title="Drop Me",
|
||||
slug="drop-me",
|
||||
author=author,
|
||||
summary="summary",
|
||||
body=[("rich_text", "<p>body</p>")],
|
||||
category=reviews,
|
||||
)
|
||||
index.add_child(instance=keep)
|
||||
keep.save_revision().publish()
|
||||
index.add_child(instance=drop)
|
||||
drop.save_revision().publish()
|
||||
target_tag = Tag.objects.create(name="Python", slug="python")
|
||||
keep.tags.add(target_tag)
|
||||
keep.save_revision().publish()
|
||||
|
||||
resp = client.get("/articles/category/reviews/?tag=python")
|
||||
html = resp.content.decode()
|
||||
assert resp.status_code == 200
|
||||
assert "Keep Me" in html
|
||||
assert "Drop Me" not in html
|
||||
|
||||
Reference in New Issue
Block a user