2021-03-08 16:49:10 +00:00
|
|
|
""" testing import """
|
2021-01-20 22:15:15 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
from django.test import RequestFactory, TestCase
|
|
|
|
|
|
|
|
from bookwyrm import models
|
|
|
|
from bookwyrm.views import rss_feed
|
|
|
|
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2021-08-09 14:38:43 +00:00
|
|
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
|
|
|
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
|
2021-09-06 20:53:49 +00:00
|
|
|
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
2021-01-28 02:23:20 +00:00
|
|
|
class RssFeedView(TestCase):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""rss feed behaves as expected"""
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2021-08-16 17:25:21 +00:00
|
|
|
def setUp(self):
|
2021-09-06 21:48:45 +00:00
|
|
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
|
|
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
|
|
|
):
|
2021-08-16 17:25:21 +00:00
|
|
|
self.local_user = models.User.objects.create_user(
|
|
|
|
"rss_user", "rss@test.rss", "password", local=True
|
|
|
|
)
|
2021-08-02 23:05:40 +00:00
|
|
|
work = models.Work.objects.create(title="Test Work")
|
2021-08-16 17:25:21 +00:00
|
|
|
self.book = models.Edition.objects.create(
|
2021-08-02 23:05:40 +00:00
|
|
|
title="Example Edition",
|
|
|
|
remote_id="https://example.com/book/1",
|
|
|
|
parent_work=work,
|
|
|
|
)
|
2021-08-16 17:25:21 +00:00
|
|
|
self.factory = RequestFactory()
|
|
|
|
|
|
|
|
models.SiteSettings.objects.create()
|
|
|
|
|
|
|
|
def test_rss_empty(self, *_):
|
|
|
|
"""load an rss feed"""
|
|
|
|
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"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"""
|
2021-08-09 14:38:43 +00:00
|
|
|
models.Review.objects.create(
|
|
|
|
name="Review name",
|
|
|
|
content="test content",
|
|
|
|
rating=3,
|
2021-08-16 17:25:21 +00:00
|
|
|
user=self.local_user,
|
|
|
|
book=self.book,
|
2021-08-09 14:38:43 +00:00
|
|
|
)
|
2021-08-16 17:25:21 +00:00
|
|
|
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)
|
2021-03-23 18:27:00 +00:00
|
|
|
|
2021-08-16 17:25:21 +00:00
|
|
|
def test_rss_quotation(self, *_):
|
|
|
|
"""load an rss feed"""
|
2021-08-09 14:38:43 +00:00
|
|
|
models.Quotation.objects.create(
|
|
|
|
quote="a sickening sense",
|
|
|
|
content="test content",
|
2021-08-16 17:25:21 +00:00
|
|
|
user=self.local_user,
|
|
|
|
book=self.book,
|
2021-08-09 14:38:43 +00:00
|
|
|
)
|
2021-01-28 02:23:20 +00:00
|
|
|
view = rss_feed.RssFeed()
|
2021-08-16 17:25:21 +00:00
|
|
|
request = self.factory.get("/user/rss_user/rss")
|
|
|
|
request.user = self.local_user
|
|
|
|
result = view(request, username=self.local_user.username)
|
2021-01-28 02:23:20 +00:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-01-28 03:13:35 +00:00
|
|
|
|
2021-02-07 06:37:19 +00:00
|
|
|
self.assertIn(b"a sickening sense", result.content)
|