Granular RSS tests

This commit is contained in:
Mouse Reeve 2021-08-16 10:25:21 -07:00
parent fd56379518
commit 7345b85ebd

View file

@ -12,47 +12,76 @@ from bookwyrm.views import rss_feed
class RssFeedView(TestCase):
"""rss feed behaves as expected"""
def test_rss_feed(self, *_):
"""load an rss feed"""
models.SiteSettings.objects.create()
user = models.User.objects.create_user(
"rss_user", "rss@test.rss", "password", local=True
)
def setUp(self):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
self.local_user = models.User.objects.create_user(
"rss_user", "rss@test.rss", "password", local=True
)
work = models.Work.objects.create(title="Test Work")
book = models.Edition.objects.create(
self.book = models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
parent_work=work,
)
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)
result.render()
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)
result.render()
def test_rss_review(self, *_):
"""load an rss feed"""
models.Review.objects.create(
name="Review name",
content="test content",
rating=3,
user=user,
book=book,
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)
result.render()
def test_rss_quotation(self, *_):
"""load an rss feed"""
models.Quotation.objects.create(
quote="a sickening sense",
content="test content",
user=user,
book=book,
user=self.local_user,
book=self.book,
)
models.ReadStatus.objects.create(content="test content", user=user)
factory = RequestFactory()
view = rss_feed.RssFeed()
request = factory.get("/user/rss_user/rss")
request.user = user
result = view(request, username=user.username)
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)
result.render()
self.assertIn(b"Status updates from rss_user", result.content)
self.assertIn(b"a sickening sense", result.content)
self.assertIn(b"Example Edition", result.content)