mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-19 06:36:35 +00:00
Updates rss feed view
This commit is contained in:
parent
187e2e0d08
commit
fd56379518
2 changed files with 42 additions and 38 deletions
|
@ -1,5 +1,4 @@
|
|||
""" testing import """
|
||||
|
||||
from unittest.mock import patch
|
||||
from django.test import RequestFactory, TestCase
|
||||
|
||||
|
@ -7,57 +6,51 @@ from bookwyrm import models
|
|||
from bookwyrm.views import rss_feed
|
||||
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
class RssFeedView(TestCase):
|
||||
"""rss feed behaves as expected"""
|
||||
|
||||
def setUp(self):
|
||||
"""test data"""
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
def test_rss_feed(self, *_):
|
||||
"""load an rss feed"""
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.user = models.User.objects.create_user(
|
||||
user = models.User.objects.create_user(
|
||||
"rss_user", "rss@test.rss", "password", local=True
|
||||
)
|
||||
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
self.review = models.Review.objects.create(
|
||||
models.Review.objects.create(
|
||||
name="Review name",
|
||||
content="test content",
|
||||
rating=3,
|
||||
user=self.user,
|
||||
book=self.book,
|
||||
user=user,
|
||||
book=book,
|
||||
)
|
||||
|
||||
self.quote = models.Quotation.objects.create(
|
||||
models.Quotation.objects.create(
|
||||
quote="a sickening sense",
|
||||
content="test content",
|
||||
user=self.user,
|
||||
book=self.book,
|
||||
user=user,
|
||||
book=book,
|
||||
)
|
||||
|
||||
self.generatednote = models.GeneratedNote.objects.create(
|
||||
content="test content", user=self.user
|
||||
)
|
||||
models.ReadStatus.objects.create(content="test content", user=user)
|
||||
|
||||
self.factory = RequestFactory()
|
||||
factory = RequestFactory()
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
|
||||
def test_rss_feed(self, _):
|
||||
"""load an rss feed"""
|
||||
view = rss_feed.RssFeed()
|
||||
request = self.factory.get("/user/rss_user/rss")
|
||||
request.user = self.user
|
||||
with patch("bookwyrm.models.SiteSettings.objects.get") as site:
|
||||
site.return_value = self.site
|
||||
result = view(request, username=self.user.username)
|
||||
request = factory.get("/user/rss_user/rss")
|
||||
request.user = user
|
||||
|
||||
result = view(request, username=user.username)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
self.assertIn(b"Status updates from rss_user", result.content)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
""" serialize user's posts in rss feed """
|
||||
|
||||
from django.contrib.syndication.views import Feed
|
||||
from django.template.loader import get_template
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .helpers import get_user_from_username, privacy_filter
|
||||
|
||||
# pylint: disable=no-self-use, unused-argument
|
||||
|
@ -8,7 +11,15 @@ class RssFeed(Feed):
|
|||
"""serialize user's posts in rss feed"""
|
||||
|
||||
description_template = "rss/content.html"
|
||||
title_template = "rss/title.html"
|
||||
|
||||
def item_title(self, item):
|
||||
"""render the item title"""
|
||||
if hasattr(item, "pure_name") and item.pure_name:
|
||||
return item.pure_name
|
||||
title_template = get_template("snippets/status/header_content.html")
|
||||
title = title_template.render({"status": item})
|
||||
template = get_template("rss/title.html")
|
||||
return template.render({"user": item.user, "item_title": title}).strip()
|
||||
|
||||
def get_object(self, request, username): # pylint: disable=arguments-differ
|
||||
"""the user who's posts get serialized"""
|
||||
|
@ -20,7 +31,7 @@ class RssFeed(Feed):
|
|||
|
||||
def title(self, obj):
|
||||
"""title of the rss feed entry"""
|
||||
return f"Status updates from {obj.display_name}"
|
||||
return _(f"Status updates from {obj.display_name}")
|
||||
|
||||
def items(self, obj):
|
||||
"""the user's activity feed"""
|
||||
|
|
Loading…
Reference in a new issue