moviewyrm/bookwyrm/tests/views/test_rss_feed.py

51 lines
1.7 KiB
Python
Raw Normal View History

2021-01-20 22:15:15 +00:00
''' testing import '''
from unittest.mock import patch
from django.test import RequestFactory, TestCase
from bookwyrm import models
from bookwyrm.views import rss_feed
2021-01-28 02:23:20 +00:00
class RssFeedView(TestCase):
2021-01-20 22:15:15 +00:00
''' rss feed behaves as expected '''
def setUp(self):
2021-02-07 06:37:19 +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(
'rss_user', 'rss@test.rss', 'password', local=True)
work = models.Work.objects.create(title='Test Work')
self.book = models.Edition.objects.create(
title='Example Edition',
remote_id='https://example.com/book/1',
parent_work=work
)
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)
2021-02-07 06:37:19 +00:00
2021-01-20 22:15:15 +00:00
self.generatednote = models.GeneratedNote.objects.create(
content='test content', user=self.user)
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-02-07 06:37:19 +00:00
''' load an rss feed '''
2021-01-28 02:23:20 +00:00
view = rss_feed.RssFeed()
2021-01-20 22:15:15 +00:00
request = self.factory.get('/user/rss_user/rss')
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)