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>
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import pytest
|
|
|
|
from apps.blog.feeds import AllArticlesFeed
|
|
from apps.blog.models import ArticleIndexPage, ArticlePage, Category
|
|
from apps.blog.tests.factories import AuthorFactory
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_all_feed_methods(article_page):
|
|
feed = AllArticlesFeed()
|
|
assert feed.item_title(article_page) == article_page.title
|
|
assert article_page.summary in feed.item_description(article_page)
|
|
assert article_page.author.name == feed.item_author_name(article_page)
|
|
assert feed.item_link(article_page).startswith("http")
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_tag_feed_not_found(client):
|
|
resp = client.get("/feed/tag/does-not-exist/")
|
|
assert resp.status_code == 404
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_category_feed_endpoint(client, home_page):
|
|
index = ArticleIndexPage(title="Articles", slug="articles")
|
|
home_page.add_child(instance=index)
|
|
category = Category.objects.create(name="Reviews", slug="reviews")
|
|
author = AuthorFactory()
|
|
article = ArticlePage(
|
|
title="Feed Review",
|
|
slug="feed-review",
|
|
author=author,
|
|
summary="summary",
|
|
body=[("rich_text", "<p>Body</p>")],
|
|
category=category,
|
|
)
|
|
index.add_child(instance=article)
|
|
article.save_revision().publish()
|
|
|
|
resp = client.get("/feed/category/reviews/")
|
|
assert resp.status_code == 200
|
|
assert resp["Content-Type"].startswith("application/rss+xml")
|
|
assert "Feed Review" in resp.content.decode()
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_category_feed_not_found(client):
|
|
resp = client.get("/feed/category/does-not-exist/")
|
|
assert resp.status_code == 404
|