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-01-28 02:23:20 +00:00
|
|
|
class RssFeedView(TestCase):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" rss feed behaves as expected """
|
|
|
|
|
2021-01-20 22:15:15 +00:00
|
|
|
def setUp(self):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" test data """
|
2021-01-28 03:13:35 +00:00
|
|
|
self.site = models.SiteSettings.objects.create()
|
|
|
|
|
2021-01-20 22:15:15 +00:00
|
|
|
self.user = models.User.objects.create_user(
|
2021-03-08 16:49:10 +00:00
|
|
|
"rss_user", "rss@test.rss", "password", local=True
|
|
|
|
)
|
2021-01-20 22:15:15 +00:00
|
|
|
|
2021-03-08 16:49:10 +00:00
|
|
|
work = models.Work.objects.create(title="Test Work")
|
2021-01-20 22:15:15 +00:00
|
|
|
self.book = models.Edition.objects.create(
|
2021-03-08 16:49:10 +00:00
|
|
|
title="Example Edition",
|
|
|
|
remote_id="https://example.com/book/1",
|
|
|
|
parent_work=work,
|
2021-01-20 22:15:15 +00:00
|
|
|
)
|
|
|
|
|
2021-03-08 16:49:10 +00:00
|
|
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
2021-02-10 01:26:27 +00:00
|
|
|
self.review = models.Review.objects.create(
|
2021-03-08 16:49:10 +00:00
|
|
|
name="Review name",
|
|
|
|
content="test content",
|
|
|
|
rating=3,
|
|
|
|
user=self.user,
|
|
|
|
book=self.book,
|
|
|
|
)
|
2021-01-20 22:15:15 +00:00
|
|
|
|
2021-02-10 01:26:27 +00:00
|
|
|
self.quote = models.Quotation.objects.create(
|
2021-03-08 16:49:10 +00:00
|
|
|
quote="a sickening sense",
|
|
|
|
content="test content",
|
|
|
|
user=self.user,
|
|
|
|
book=self.book,
|
|
|
|
)
|
2021-02-07 06:37:19 +00:00
|
|
|
|
2021-02-10 01:26:27 +00:00
|
|
|
self.generatednote = models.GeneratedNote.objects.create(
|
2021-03-08 16:49:10 +00:00
|
|
|
content="test content", user=self.user
|
|
|
|
)
|
2021-01-20 22:15:15 +00:00
|
|
|
|
|
|
|
self.factory = RequestFactory()
|
2021-02-07 06:37:19 +00:00
|
|
|
|
2021-01-20 22:15:15 +00:00
|
|
|
def test_rss_feed(self):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" load an rss feed """
|
2021-01-28 02:23:20 +00:00
|
|
|
view = rss_feed.RssFeed()
|
2021-03-08 16:49:10 +00:00
|
|
|
request = self.factory.get("/user/rss_user/rss")
|
2021-02-23 21:26:44 +00:00
|
|
|
request.user = self.user
|
2021-01-28 03:13:35 +00:00
|
|
|
with patch("bookwyrm.models.SiteSettings.objects.get") as site:
|
|
|
|
site.return_value = self.site
|
|
|
|
result = view(request, username=self.user.username)
|
2021-01-28 02:23:20 +00:00
|
|
|
self.assertEqual(result.status_code, 200)
|
2021-01-28 03:13:35 +00:00
|
|
|
|
|
|
|
self.assertIn(b"Status updates from rss_user", result.content)
|
2021-02-07 06:37:19 +00:00
|
|
|
self.assertIn(b"a sickening sense", result.content)
|
2021-01-28 03:13:35 +00:00
|
|
|
self.assertIn(b"Example Edition", result.content)
|