Test feed views
This commit is contained in:
parent
7d4e11b096
commit
b30901af69
3 changed files with 34 additions and 1 deletions
32
articles/tests/test_feed_views.py
Normal file
32
articles/tests/test_feed_views.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import pytest
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
from model_bakery import baker
|
||||
|
||||
from articles.models import Article, Page, User
|
||||
from articles.views.feeds import CompleteFeed
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_can_access_feed(client: Client, published_article):
|
||||
res = client.get(reverse("complete-feed"))
|
||||
assert res.status_code == 200
|
||||
assert "application/rss+xml" in res["content-type"]
|
||||
content = res.content.decode("utf-8")
|
||||
assert published_article.title in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_feed_limits_number_of_articles(client: Client, author: User):
|
||||
baker.make(Article, 100, status=Article.PUBLISHED, author=author)
|
||||
res = client.get(reverse("complete-feed"))
|
||||
content = res.content.decode("utf-8")
|
||||
assert content.count("<item>") == CompleteFeed.FEED_LIMIT
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_page_not_rendered_in_feed(client: Client, published_page: Page):
|
||||
res = client.get(reverse("complete-feed"))
|
||||
assert res.status_code == 200
|
||||
content = res.content.decode("utf-8")
|
||||
assert published_page.title not in content
|
|
@ -5,6 +5,7 @@ from blog import settings
|
|||
|
||||
|
||||
class CompleteFeed(Feed):
|
||||
FEED_LIMIT = 15
|
||||
title = "Gab's Notes"
|
||||
link = settings.BLOG["base_url"]
|
||||
description = settings.BLOG["description"]
|
||||
|
@ -12,7 +13,7 @@ class CompleteFeed(Feed):
|
|||
def items(self):
|
||||
return Article.without_pages.filter(status=Article.PUBLISHED).order_by(
|
||||
"-published_at"
|
||||
)[:15]
|
||||
)[: self.FEED_LIMIT]
|
||||
|
||||
def item_title(self, item: Article):
|
||||
return item.title
|
||||
|
|
Reference in a new issue