From fd56379518f93aa56dcb2e1a64f51fc2a400cc47 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 9 Aug 2021 07:38:43 -0700 Subject: [PATCH] Updates rss feed view --- bookwyrm/tests/views/test_rss_feed.py | 65 ++++++++++++--------------- bookwyrm/views/rss_feed.py | 15 ++++++- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index 3608b043a..715add3f2 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -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( - "rss_user", "rss@test.rss", "password", local=True - ) + 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( - name="Review name", - content="test content", - rating=3, - user=self.user, - book=self.book, - ) + models.Review.objects.create( + name="Review name", + content="test content", + rating=3, + user=user, + book=book, + ) - self.quote = models.Quotation.objects.create( - quote="a sickening sense", - content="test content", - user=self.user, - book=self.book, - ) + models.Quotation.objects.create( + quote="a sickening sense", + content="test content", + 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) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index 0d3a8902e..5faa16243 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -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"""