forked from mirrors/bookwyrm
Merge pull request #1272 from bookwyrm-social/rss
Updates rss feed view
This commit is contained in:
commit
c1afd3f852
2 changed files with 66 additions and 38 deletions
|
@ -1,5 +1,4 @@
|
||||||
""" testing import """
|
""" testing import """
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from django.test import RequestFactory, TestCase
|
from django.test import RequestFactory, TestCase
|
||||||
|
|
||||||
|
@ -7,59 +6,77 @@ from bookwyrm import models
|
||||||
from bookwyrm.views import rss_feed
|
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):
|
class RssFeedView(TestCase):
|
||||||
"""rss feed behaves as expected"""
|
"""rss feed behaves as expected"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""test data"""
|
|
||||||
self.site = models.SiteSettings.objects.create()
|
|
||||||
|
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"rss_user", "rss@test.rss", "password", local=True
|
"rss_user", "rss@test.rss", "password", local=True
|
||||||
)
|
)
|
||||||
|
|
||||||
work = models.Work.objects.create(title="Test Work")
|
work = models.Work.objects.create(title="Test Work")
|
||||||
self.book = models.Edition.objects.create(
|
self.book = models.Edition.objects.create(
|
||||||
title="Example Edition",
|
title="Example Edition",
|
||||||
remote_id="https://example.com/book/1",
|
remote_id="https://example.com/book/1",
|
||||||
parent_work=work,
|
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.quote = models.Quotation.objects.create(
|
|
||||||
quote="a sickening sense",
|
|
||||||
content="test content",
|
|
||||||
user=self.user,
|
|
||||||
book=self.book,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.generatednote = models.GeneratedNote.objects.create(
|
|
||||||
content="test content", user=self.user
|
|
||||||
)
|
|
||||||
|
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
|
models.SiteSettings.objects.create()
|
||||||
def test_rss_feed(self, _):
|
|
||||||
|
def test_rss_empty(self, *_):
|
||||||
"""load an rss feed"""
|
"""load an rss feed"""
|
||||||
view = rss_feed.RssFeed()
|
view = rss_feed.RssFeed()
|
||||||
request = self.factory.get("/user/rss_user/rss")
|
request = self.factory.get("/user/rss_user/rss")
|
||||||
request.user = self.user
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.models.SiteSettings.objects.get") as site:
|
result = view(request, username=self.local_user.username)
|
||||||
site.return_value = self.site
|
self.assertEqual(result.status_code, 200)
|
||||||
result = view(request, username=self.user.username)
|
self.assertIn(b"Status updates from rss_user", result.content)
|
||||||
|
|
||||||
|
def test_rss_comment(self, *_):
|
||||||
|
"""load an rss feed"""
|
||||||
|
models.Comment.objects.create(
|
||||||
|
content="comment test content",
|
||||||
|
user=self.local_user,
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
view = rss_feed.RssFeed()
|
||||||
|
request = self.factory.get("/user/rss_user/rss")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request, username=self.local_user.username)
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
self.assertIn(b"Example Edition", result.content)
|
||||||
|
|
||||||
|
def test_rss_review(self, *_):
|
||||||
|
"""load an rss feed"""
|
||||||
|
models.Review.objects.create(
|
||||||
|
name="Review name",
|
||||||
|
content="test content",
|
||||||
|
rating=3,
|
||||||
|
user=self.local_user,
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
view = rss_feed.RssFeed()
|
||||||
|
request = self.factory.get("/user/rss_user/rss")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request, username=self.local_user.username)
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_rss_quotation(self, *_):
|
||||||
|
"""load an rss feed"""
|
||||||
|
models.Quotation.objects.create(
|
||||||
|
quote="a sickening sense",
|
||||||
|
content="test content",
|
||||||
|
user=self.local_user,
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
view = rss_feed.RssFeed()
|
||||||
|
request = self.factory.get("/user/rss_user/rss")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request, username=self.local_user.username)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
self.assertIn(b"Status updates from rss_user", result.content)
|
|
||||||
self.assertIn(b"a sickening sense", result.content)
|
self.assertIn(b"a sickening sense", result.content)
|
||||||
self.assertIn(b"Example Edition", result.content)
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
""" serialize user's posts in rss feed """
|
""" serialize user's posts in rss feed """
|
||||||
|
|
||||||
from django.contrib.syndication.views import 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
|
from .helpers import get_user_from_username, privacy_filter
|
||||||
|
|
||||||
# pylint: disable=no-self-use, unused-argument
|
# pylint: disable=no-self-use, unused-argument
|
||||||
|
@ -8,7 +11,15 @@ class RssFeed(Feed):
|
||||||
"""serialize user's posts in rss feed"""
|
"""serialize user's posts in rss feed"""
|
||||||
|
|
||||||
description_template = "rss/content.html"
|
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
|
def get_object(self, request, username): # pylint: disable=arguments-differ
|
||||||
"""the user who's posts get serialized"""
|
"""the user who's posts get serialized"""
|
||||||
|
@ -20,7 +31,7 @@ class RssFeed(Feed):
|
||||||
|
|
||||||
def title(self, obj):
|
def title(self, obj):
|
||||||
"""title of the rss feed entry"""
|
"""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):
|
def items(self, obj):
|
||||||
"""the user's activity feed"""
|
"""the user's activity feed"""
|
||||||
|
|
Loading…
Reference in a new issue