Merge branch 'main' into move-ratings-and-reviews-when-switching-editions
This commit is contained in:
commit
e6b6bd648d
285 changed files with 27986 additions and 5453 deletions
|
@ -11,9 +11,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class AnnouncementViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -27,6 +27,10 @@ class AnnouncementViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_announcements_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
models.Announcement.objects.create(preview="hi", user=self.local_user)
|
||||
|
|
|
@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class AutomodViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -35,6 +34,10 @@ class AutomodViews(TestCase):
|
|||
self.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_automod_rules_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
schedule = IntervalSchedule.objects.create(every=1, period="days")
|
||||
|
|
|
@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class CeleryStatusViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +33,10 @@ class CeleryStatusViews(TestCase):
|
|||
self.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_celery_status_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.CeleryStatus.as_view()
|
||||
|
|
|
@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class DashboardViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +34,10 @@ class DashboardViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_dashboard(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Dashboard.as_view()
|
||||
|
|
|
@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class EmailBlocklistViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +34,10 @@ class EmailBlocklistViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_blocklist_page_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.EmailBlocklist.as_view()
|
||||
|
|
|
@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class EmailConfigViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +33,10 @@ class EmailConfigViews(TestCase):
|
|||
self.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_email_config_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.EmailConfig.as_view()
|
||||
|
|
|
@ -17,10 +17,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class FederationViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -48,6 +47,10 @@ class FederationViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_federation_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Federation.as_view()
|
||||
|
|
|
@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ImportsAdminViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +33,10 @@ class ImportsAdminViews(TestCase):
|
|||
self.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_celery_status_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ImportList.as_view()
|
||||
|
|
|
@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class IPBlocklistViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +34,10 @@ class IPBlocklistViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_blocklist_page_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.IPBlocklist.as_view()
|
||||
|
|
|
@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class LinkDomainViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -41,6 +41,10 @@ class LinkDomainViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_domain_page_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.LinkDomain.as_view()
|
||||
|
|
|
@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ReportViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -42,6 +41,10 @@ class ReportViews(TestCase):
|
|||
self.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_reports_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ReportsAdmin.as_view()
|
||||
|
|
|
@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class SiteSettingsViews(TestCase):
|
||||
"""Edit site settings"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -35,6 +34,10 @@ class SiteSettingsViews(TestCase):
|
|||
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_site_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Site.as_view()
|
||||
|
|
|
@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class AdminThemesViews(TestCase):
|
||||
"""Edit site settings"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -43,6 +42,10 @@ class AdminThemesViews(TestCase):
|
|||
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_themes_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Themes.as_view()
|
||||
|
@ -86,3 +89,25 @@ class AdminThemesViews(TestCase):
|
|||
|
||||
with self.assertRaises(PermissionDenied):
|
||||
view(request)
|
||||
|
||||
def test_test_theme(self):
|
||||
"""Testing testing testing test"""
|
||||
theme = models.Theme.objects.first()
|
||||
self.assertIsNone(theme.loads)
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
|
||||
views.test_theme(request, theme.id)
|
||||
theme.refresh_from_db()
|
||||
self.assertTrue(theme.loads)
|
||||
|
||||
def test_test_theme_broken(self):
|
||||
"""Testing test for testing when it's a bad theme"""
|
||||
theme = models.Theme.objects.create(name="bad theme", path="dsf/sdf/sdf.sdf")
|
||||
self.assertIsNone(theme.loads)
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
|
||||
views.test_theme(request, theme.id)
|
||||
theme.refresh_from_db()
|
||||
self.assertIs(False, theme.loads)
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class UserAdminViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +34,10 @@ class UserAdminViews(TestCase):
|
|||
self.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_user_admin_list_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.UserAdminList.as_view()
|
||||
|
|
|
@ -23,9 +23,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class BookViews(TestCase):
|
||||
"""books books books"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -54,6 +54,10 @@ class BookViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_book_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Book.as_view()
|
||||
|
@ -268,8 +272,8 @@ class BookViews(TestCase):
|
|||
book=self.book,
|
||||
content="hi",
|
||||
quote="wow",
|
||||
position=12,
|
||||
endposition=13,
|
||||
position="12",
|
||||
endposition="13",
|
||||
)
|
||||
|
||||
request = self.factory.get("")
|
||||
|
@ -282,7 +286,9 @@ class BookViews(TestCase):
|
|||
validate_html(result.render())
|
||||
print(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.context_data["statuses"].object_list[0].endposition, 13)
|
||||
self.assertEqual(
|
||||
result.context_data["statuses"].object_list[0].endposition, "13"
|
||||
)
|
||||
|
||||
|
||||
def _setup_cover_url():
|
||||
|
|
|
@ -19,9 +19,9 @@ from bookwyrm.tests.views.books.test_book import _setup_cover_url
|
|||
class EditBookViews(TestCase):
|
||||
"""books books books"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -47,10 +47,13 @@ class EditBookViews(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
# pylint: disable=line-too-long
|
||||
self.authors_body = "<?xml version='1.0' encoding='UTF-8' ?><?xml-stylesheet type='text/xsl' href='http://isni.oclc.org/sru/DB=1.2/?xsl=searchRetrieveResponse' ?><srw:searchRetrieveResponse xmlns:srw='http://www.loc.gov/zing/srw/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:diag='http://www.loc.gov/zing/srw/diagnostic/' xmlns:xcql='http://www.loc.gov/zing/cql/xcql/'><srw:version>1.1</srw:version><srw:records><srw:record><isniUnformatted>0000000084510024</isniUnformatted></srw:record></srw:records></srw:searchRetrieveResponse>"
|
||||
|
||||
# pylint: disable=line-too-long
|
||||
self.author_body = "<?xml version='1.0' encoding='UTF-8' ?><?xml-stylesheet type='text/xsl' href='http://isni.oclc.org/sru/DB=1.2/?xsl=searchRetrieveResponse' ?><srw:searchRetrieveResponse xmlns:srw='http://www.loc.gov/zing/srw/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:diag='http://www.loc.gov/zing/srw/diagnostic/' xmlns:xcql='http://www.loc.gov/zing/cql/xcql/'><srw:records><srw:record><srw:recordData><responseRecord><ISNIAssigned><isniUnformatted>0000000084510024</isniUnformatted><isniURI>https://isni.org/isni/0000000084510024</isniURI><dataConfidence>60</dataConfidence><ISNIMetadata><identity><personOrFiction><personalName><surname>Catherine Amy Dawson Scott</surname><nameTitle>poet and novelist</nameTitle><nameUse>public</nameUse><source>VIAF</source><source>WKP</source><subsourceIdentifier>Q544961</subsourceIdentifier></personalName><personalName><forename>C. A.</forename><surname>Dawson Scott</surname><marcDate>1865-1934</marcDate><nameUse>public</nameUse><source>VIAF</source><source>NLP</source><subsourceIdentifier>a28927850</subsourceIdentifier></personalName><sources><codeOfSource>VIAF</codeOfSource><sourceIdentifier>45886165</sourceIdentifier><reference><class>ALL</class><role>CRE</role><URI>http://viaf.org/viaf/45886165</URI></reference></sources><externalInformation><information>Wikipedia</information><URI>https://en.wikipedia.org/wiki/Catherine_Amy_Dawson_Scott</URI></externalInformation></ISNIMetadata></ISNIAssigned></responseRecord></srw:recordData></srw:record></srw:records></srw:searchRetrieveResponse>"
|
||||
|
||||
responses.get(
|
||||
|
@ -86,8 +89,6 @@ class EditBookViews(TestCase):
|
|||
body=self.author_body,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_edit_book_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.EditBook.as_view()
|
||||
|
|
|
@ -13,9 +13,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class BookViews(TestCase):
|
||||
"""books books books"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -37,6 +37,10 @@ class BookViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_editions_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Editions.as_view()
|
||||
|
|
|
@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class LinkViews(TestCase):
|
||||
"""books books books"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
|
@ -49,6 +48,10 @@ class LinkViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_add_link_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.AddFileLink.as_view()
|
||||
|
|
|
@ -16,10 +16,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ImportViews(TestCase):
|
||||
"""goodreads import views"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -32,6 +31,10 @@ class ImportViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_import_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Import.as_view()
|
||||
|
|
|
@ -11,10 +11,9 @@ from bookwyrm import models, views
|
|||
class ImportManualReviewViews(TestCase):
|
||||
"""goodreads import views"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -35,6 +34,10 @@ class ImportManualReviewViews(TestCase):
|
|||
parent_work=work,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_import_troubleshoot_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ImportManualReview.as_view()
|
||||
|
|
|
@ -12,10 +12,9 @@ from bookwyrm import models, views
|
|||
class ImportTroubleshootViews(TestCase):
|
||||
"""goodreads import views"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -28,6 +27,10 @@ class ImportTroubleshootViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_import_troubleshoot_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ImportTroubleshoot.as_view()
|
||||
|
|
68
bookwyrm/tests/views/imports/test_user_import.py
Normal file
68
bookwyrm/tests/views/imports/test_user_import.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
""" test for app action functionality """
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import forms, models, views
|
||||
from bookwyrm.tests.validate_html import validate_html
|
||||
|
||||
|
||||
class ImportUserViews(TestCase):
|
||||
"""user import views"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_get_user_import_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.UserImport.as_view()
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_user_import_post(self):
|
||||
"""does the import job start?"""
|
||||
|
||||
view = views.UserImport.as_view()
|
||||
form = forms.ImportUserForm()
|
||||
archive_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../data/bookwyrm_account_export.tar.gz"
|
||||
)
|
||||
|
||||
form.data["archive_file"] = SimpleUploadedFile(
|
||||
# pylint: disable=consider-using-with
|
||||
archive_file,
|
||||
open(archive_file, "rb").read(),
|
||||
content_type="application/gzip",
|
||||
)
|
||||
|
||||
form.data["include_user_settings"] = ""
|
||||
form.data["include_goals"] = "on"
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
with patch("bookwyrm.models.bookwyrm_import_job.BookwyrmImportJob.start_job"):
|
||||
view(request)
|
||||
job = models.BookwyrmImportJob.objects.get()
|
||||
self.assertEqual(job.required, ["include_goals"])
|
|
@ -15,12 +15,22 @@ from bookwyrm import models, views
|
|||
class Inbox(TestCase):
|
||||
"""readthrough tests"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
"""individual test setup"""
|
||||
self.client = Client()
|
||||
self.factory = RequestFactory()
|
||||
self.create_json = {
|
||||
"id": "hi",
|
||||
"type": "Create",
|
||||
"actor": "hi",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"object": {},
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -43,14 +53,6 @@ class Inbox(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.create_json = {
|
||||
"id": "hi",
|
||||
"type": "Create",
|
||||
"actor": "hi",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"object": {},
|
||||
}
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_inbox_invalid_get(self):
|
||||
|
|
|
@ -11,7 +11,8 @@ from bookwyrm import models, views
|
|||
class InboxAdd(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
|
|
@ -11,7 +11,8 @@ from bookwyrm import models, views
|
|||
class InboxActivities(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
@ -44,6 +45,10 @@ class InboxActivities(TestCase):
|
|||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.create_json = {
|
||||
"id": "hi",
|
||||
"type": "Create",
|
||||
|
@ -53,8 +58,6 @@ class InboxActivities(TestCase):
|
|||
"object": {},
|
||||
}
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
def test_boost(self, _):
|
||||
"""boost a status"""
|
||||
|
|
|
@ -10,7 +10,8 @@ from bookwyrm import models, views
|
|||
class InboxBlock(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
|
|
@ -9,7 +9,7 @@ from bookwyrm import models, views
|
|||
from bookwyrm.activitypub import ActivitySerializerError
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods, invalid-name
|
||||
# pylint: disable=too-many-public-methods
|
||||
class TransactionInboxCreate(TransactionTestCase):
|
||||
"""readthrough tests"""
|
||||
|
||||
|
@ -71,7 +71,8 @@ class TransactionInboxCreate(TransactionTestCase):
|
|||
class InboxCreate(TestCase):
|
||||
"""readthrough tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
@ -96,6 +97,10 @@ class InboxCreate(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.create_json = {
|
||||
"id": "hi",
|
||||
"type": "Create",
|
||||
|
@ -104,7 +109,6 @@ class InboxCreate(TestCase):
|
|||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"object": {},
|
||||
}
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_create_status(self, *_):
|
||||
"""the "it justs works" mode"""
|
||||
|
|
|
@ -11,8 +11,8 @@ from bookwyrm import models, views
|
|||
class InboxActivities(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
|
|
@ -11,7 +11,8 @@ from bookwyrm import models, views
|
|||
class InboxRelationships(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
|
|
@ -10,7 +10,8 @@ from bookwyrm import models, views
|
|||
class InboxActivities(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
@ -43,6 +44,10 @@ class InboxActivities(TestCase):
|
|||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.create_json = {
|
||||
"id": "hi",
|
||||
"type": "Create",
|
||||
|
@ -52,8 +57,6 @@ class InboxActivities(TestCase):
|
|||
"object": {},
|
||||
}
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_favorite(self):
|
||||
"""fav a status"""
|
||||
activity = {
|
||||
|
|
|
@ -10,7 +10,8 @@ from bookwyrm import models, views
|
|||
class InboxRemove(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
|
|
@ -12,7 +12,8 @@ from bookwyrm import models, views
|
|||
class InboxUpdate(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
|
@ -37,6 +38,10 @@ class InboxUpdate(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.update_json = {
|
||||
"id": "hi",
|
||||
"type": "Update",
|
||||
|
@ -46,8 +51,6 @@ class InboxUpdate(TestCase):
|
|||
"object": {},
|
||||
}
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_update_list(self):
|
||||
"""a new list"""
|
||||
with patch(
|
||||
|
|
|
@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class InviteViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -30,6 +29,10 @@ class InviteViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_invite_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Invite.as_view()
|
||||
|
|
|
@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class LandingViews(TestCase):
|
||||
"""pages you land on without really trying"""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -27,9 +27,13 @@ class LandingViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
|
||||
def test_home_page(self, _):
|
||||
|
|
|
@ -17,10 +17,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class LoginViews(TestCase):
|
||||
"""login and password management"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -47,9 +46,13 @@ class LoginViews(TestCase):
|
|||
localname="badger",
|
||||
two_factor_auth=True,
|
||||
)
|
||||
models.SiteSettings.objects.create(id=1, require_confirm_email=False)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create(id=1, require_confirm_email=False)
|
||||
|
||||
def test_login_get(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -16,9 +16,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class PasswordViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -29,9 +29,13 @@ class PasswordViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create(id=1)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create(id=1)
|
||||
|
||||
def test_password_reset_request(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -20,10 +20,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class RegisterViews(TestCase):
|
||||
"""login and password management"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,13 +33,16 @@ class RegisterViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
self.settings = models.SiteSettings.objects.create(
|
||||
id=1, require_confirm_email=False, allow_registration=True
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
def test_get_redirect(self, *_):
|
||||
"""there's no dedicated registration page"""
|
||||
view = views.Register.as_view()
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ListViews(TestCase):
|
||||
"""list view"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -42,11 +42,15 @@ class ListViews(TestCase):
|
|||
self.list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user
|
||||
)
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
def test_curate_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Curate.as_view()
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ListViews(TestCase):
|
||||
"""list view"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -42,11 +42,15 @@ class ListViews(TestCase):
|
|||
self.list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user
|
||||
)
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
def test_embed_call_without_key(self):
|
||||
"""there are so many views, this just makes sure it DOESN’T load"""
|
||||
view = views.unsafe_embed_list
|
||||
|
|
|
@ -18,9 +18,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ListViews(TestCase):
|
||||
"""list view"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -71,11 +71,15 @@ class ListViews(TestCase):
|
|||
self.list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user
|
||||
)
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
def test_list_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.List.as_view()
|
||||
|
|
|
@ -12,9 +12,9 @@ from bookwyrm import models, views
|
|||
class ListItemViews(TestCase):
|
||||
"""list view"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -41,6 +41,10 @@ class ListItemViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_add_list_item_notes(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ListItem.as_view()
|
||||
|
|
|
@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ListViews(TestCase):
|
||||
"""lists of lists"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -33,11 +32,15 @@ class ListViews(TestCase):
|
|||
self.another_user = models.User.objects.create_user(
|
||||
"rat@local.com", "rat@rat.com", "ratword", local=True, localname="rat"
|
||||
)
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
@patch("bookwyrm.lists_stream.ListsStream.get_list_stream")
|
||||
def test_lists_page(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -13,9 +13,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class BlockViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -39,6 +39,10 @@ class BlockViews(TestCase):
|
|||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_block_get(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Block.as_view()
|
||||
|
|
|
@ -12,9 +12,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ChangePasswordViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -27,6 +27,10 @@ class ChangePasswordViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create(id=1)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_password_change_get(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.ChangePassword.as_view()
|
||||
|
|
|
@ -16,10 +16,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class DeleteUserViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -50,9 +49,13 @@ class DeleteUserViews(TestCase):
|
|||
shelf=self.local_user.shelf_set.first(),
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_delete_user_page(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -18,9 +18,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class EditUserViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -48,6 +48,10 @@ class EditUserViews(TestCase):
|
|||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
|
|
|
@ -17,9 +17,11 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ExportViews(TestCase):
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(
|
||||
self,
|
||||
): # pylint: disable=bad-classmethod-argument, disable=invalid-name
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
|
@ -40,6 +42,11 @@ class ExportViews(TestCase):
|
|||
bnf_id="beep",
|
||||
)
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def tst_export_get(self, *_):
|
||||
"""request export"""
|
||||
request = self.factory.get("")
|
||||
|
@ -49,11 +56,12 @@ class ExportViews(TestCase):
|
|||
|
||||
def test_export_file(self, *_):
|
||||
"""simple export"""
|
||||
models.ShelfBook.objects.create(
|
||||
shelfbook = models.ShelfBook.objects.create(
|
||||
shelf=self.local_user.shelf_set.first(),
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
)
|
||||
book_date = str.encode(f"{shelfbook.shelved_date.date()}")
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
export = views.Export.as_view()(request)
|
||||
|
@ -62,7 +70,7 @@ class ExportViews(TestCase):
|
|||
# pylint: disable=line-too-long
|
||||
self.assertEqual(
|
||||
export.content,
|
||||
b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,rating,review_name,review_cw,review_content\r\nTest Book,,"
|
||||
+ self.book.remote_id.encode("utf-8")
|
||||
+ b",,,,,beep,,,,,,123456789X,9781234567890,,,,,\r\n",
|
||||
b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content,review_published,shelf,shelf_name,shelf_date\r\n"
|
||||
+ b"Test Book,,%b,,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,,,to-read,To Read,%b\r\n"
|
||||
% (self.book.remote_id.encode("utf-8"), book_date),
|
||||
)
|
||||
|
|
50
bookwyrm/tests/views/preferences/test_export_user.py
Normal file
50
bookwyrm/tests/views/preferences/test_export_user.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
""" test for user export app functionality """
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm.tests.validate_html import validate_html
|
||||
|
||||
|
||||
class ExportUserViews(TestCase):
|
||||
"""exporting user data"""
|
||||
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
models.SiteSettings.objects.create()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"hugh@example.com",
|
||||
"hugh@example.com",
|
||||
"password",
|
||||
local=True,
|
||||
localname="Hugh",
|
||||
summary="just a test account",
|
||||
remote_id="https://example.com/users/hugh",
|
||||
preferred_timezone="Australia/Broken_Hill",
|
||||
)
|
||||
|
||||
def test_export_user_get(self, *_):
|
||||
"""request export"""
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = views.ExportUser.as_view()(request)
|
||||
validate_html(result.render())
|
||||
|
||||
def test_trigger_export_user_file(self, *_):
|
||||
"""simple user export"""
|
||||
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.models.bookwyrm_export_job.start_export_task.delay"):
|
||||
export = views.ExportUser.as_view()(request)
|
||||
self.assertIsInstance(export, HttpResponse)
|
||||
self.assertEqual(export.status_code, 302)
|
||||
|
||||
jobs = models.bookwyrm_export_job.BookwyrmExportJob.objects.count()
|
||||
self.assertEqual(jobs, 1)
|
|
@ -17,9 +17,9 @@ from bookwyrm import forms, models, views
|
|||
class TwoFactorViews(TestCase):
|
||||
"""Two Factor Authentication management"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +34,10 @@ class TwoFactorViews(TestCase):
|
|||
hotp_secret="DRMNMOU7ZRKH5YPW7PADOEYUF7MRIH46",
|
||||
hotp_count=0,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ShelfViews(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -46,6 +46,9 @@ class ShelfViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
|
@ -216,3 +219,48 @@ class ShelfViews(TestCase):
|
|||
view(request, request.user.username, shelf.identifier)
|
||||
|
||||
self.assertEqual(shelf.name, "To Read")
|
||||
|
||||
def test_filter_shelf_found(self, *_):
|
||||
"""display books that match a filter keyword"""
|
||||
models.ShelfBook.objects.create(
|
||||
book=self.book,
|
||||
shelf=self.shelf,
|
||||
user=self.local_user,
|
||||
)
|
||||
shelf_book = models.ShelfBook.objects.create(
|
||||
book=self.book,
|
||||
shelf=self.local_user.shelf_set.first(),
|
||||
user=self.local_user,
|
||||
)
|
||||
view = views.Shelf.as_view()
|
||||
request = self.factory.get("", {"filter": shelf_book.book.title})
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.shelf.shelf.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, self.local_user.username)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(len(result.context_data["books"].object_list), 1)
|
||||
self.assertEqual(
|
||||
result.context_data["books"].object_list[0].title,
|
||||
shelf_book.book.title,
|
||||
)
|
||||
|
||||
def test_filter_shelf_none(self, *_):
|
||||
"""display a message when no books match a filter keyword"""
|
||||
models.ShelfBook.objects.create(
|
||||
book=self.book,
|
||||
shelf=self.shelf,
|
||||
user=self.local_user,
|
||||
)
|
||||
view = views.Shelf.as_view()
|
||||
request = self.factory.get("", {"filter": "NOPE"})
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.views.shelf.shelf.is_api_request") as is_api:
|
||||
is_api.return_value = False
|
||||
result = view(request, self.local_user.username)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(len(result.context_data["books"].object_list), 0)
|
||||
|
|
|
@ -18,9 +18,9 @@ from bookwyrm import forms, models, views
|
|||
class ShelfActionViews(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -52,6 +52,10 @@ class ShelfActionViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_shelve(self, *_):
|
||||
"""shelve a book"""
|
||||
request = self.factory.post(
|
||||
|
|
|
@ -21,10 +21,9 @@ def make_date(*args):
|
|||
class AnnualSummary(TestCase):
|
||||
"""views"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -44,13 +43,15 @@ class AnnualSummary(TestCase):
|
|||
parent_work=self.work,
|
||||
pages=300,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.year = "2020"
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
self.year = "2020"
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_annual_summary_not_authenticated(self, *_):
|
||||
"""there are so many views, this just makes sure it DOESN’T LOAD"""
|
||||
view = views.AnnualSummary.as_view()
|
||||
|
|
|
@ -16,9 +16,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class AuthorViews(TestCase):
|
||||
"""author views"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -44,10 +44,13 @@ class AuthorViews(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_author_page(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -13,9 +13,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class DirectoryViews(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -27,8 +27,11 @@ class DirectoryViews(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
|
|
|
@ -11,10 +11,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class DiscoverViews(TestCase):
|
||||
"""pages you land on without really trying"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -25,9 +24,13 @@ class DiscoverViews(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_discover_page_empty(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -24,9 +24,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class FeedViews(TestCase):
|
||||
"""activity feed, statuses, dms"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -51,6 +51,10 @@ class FeedViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
|
||||
def test_feed(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
|
|
|
@ -17,10 +17,10 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class FollowViews(TestCase):
|
||||
"""follows"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
models.SiteSettings.objects.create()
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -57,6 +57,10 @@ class FollowViews(TestCase):
|
|||
parent_work=self.work,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_handle_follow_remote(self, *_):
|
||||
"""send a follow request"""
|
||||
request = self.factory.post("", {"user": self.remote_user.username})
|
||||
|
@ -173,13 +177,39 @@ class FollowViews(TestCase):
|
|||
user_subject=self.remote_user, user_object=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
) as broadcast_mock:
|
||||
views.delete_follow_request(request)
|
||||
# did we send the reject activity?
|
||||
activity = json.loads(broadcast_mock.call_args[1]["args"][1])
|
||||
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
||||
self.assertEqual(activity["object"]["object"], rel.user_object.remote_id)
|
||||
self.assertEqual(activity["type"], "Reject")
|
||||
# request should be deleted
|
||||
self.assertEqual(models.UserFollowRequest.objects.filter(id=rel.id).count(), 0)
|
||||
# follow relationship should not exist
|
||||
self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0)
|
||||
|
||||
def test_handle_reject_existing(self, *_):
|
||||
"""reject a follow previously approved"""
|
||||
request = self.factory.post("", {"user": self.remote_user.username})
|
||||
request.user = self.local_user
|
||||
rel = models.UserFollows.objects.create(
|
||||
user_subject=self.remote_user, user_object=self.local_user
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
) as broadcast_mock:
|
||||
views.remove_follow(request, self.remote_user.id)
|
||||
# did we send the reject activity?
|
||||
activity = json.loads(broadcast_mock.call_args[1]["args"][1])
|
||||
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
||||
self.assertEqual(activity["object"]["object"], rel.user_object.remote_id)
|
||||
self.assertEqual(activity["type"], "Reject")
|
||||
# follow relationship should not exist
|
||||
self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0)
|
||||
|
||||
def test_ostatus_follow_request(self, *_):
|
||||
"""check ostatus subscribe template loads"""
|
||||
request = self.factory.get(
|
||||
|
|
|
@ -12,9 +12,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class GetStartedViews(TestCase):
|
||||
"""helping new users get oriented"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -39,6 +39,10 @@ class GetStartedViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_profile_view(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.GetStartedProfile.as_view()
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class GoalViews(TestCase):
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -41,10 +41,14 @@ class GoalViews(TestCase):
|
|||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.year = timezone.now().year
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
self.year = timezone.now().year
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_goal_page_no_goal(self):
|
||||
"""view a reading goal page for another's unset goal"""
|
||||
|
|
|
@ -16,9 +16,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class GroupViews(TestCase):
|
||||
"""view group and edit details"""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -46,11 +46,14 @@ class GroupViews(TestCase):
|
|||
self.membership = models.GroupMember.objects.create(
|
||||
group=self.testgroup, user=self.local_user
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_group_get(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Group.as_view()
|
||||
|
|
|
@ -14,8 +14,8 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class HashtagView(TestCase):
|
||||
"""hashtag view"""
|
||||
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -64,9 +64,13 @@ class HashtagView(TestCase):
|
|||
for status in self.statuses_bookclub:
|
||||
status.mention_hashtags.add(self.hashtag_bookclub)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_hashtag_page(self):
|
||||
"""just make sure it loads"""
|
||||
|
|
|
@ -15,13 +15,12 @@ from bookwyrm.settings import USER_AGENT, DOMAIN
|
|||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||
class ViewsHelpers(TestCase):
|
||||
class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -53,14 +52,18 @@ class ViewsHelpers(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
self.userdata = json.loads(datafile.read_bytes())
|
||||
del self.userdata["icon"]
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
self.shelf = models.Shelf.objects.create(
|
||||
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
self.userdata = json.loads(datafile.read_bytes())
|
||||
del self.userdata["icon"]
|
||||
|
||||
def test_get_edition(self, *_):
|
||||
"""given an edition or a work, returns an edition"""
|
||||
self.assertEqual(views.helpers.get_edition(self.book.id), self.book)
|
||||
|
|
|
@ -12,9 +12,9 @@ from bookwyrm import models, views
|
|||
class InteractionViews(TestCase):
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -36,7 +36,6 @@ class InteractionViews(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
@ -44,6 +43,10 @@ class InteractionViews(TestCase):
|
|||
parent_work=work,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_favorite(self, *_):
|
||||
"""create and broadcast faving a status"""
|
||||
view = views.Favorite.as_view()
|
||||
|
|
|
@ -14,9 +14,9 @@ from bookwyrm.settings import DOMAIN
|
|||
class IsbnViews(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -37,6 +37,10 @@ class IsbnViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_isbn_json_response(self):
|
||||
"""searches local data only and returns book data in json format"""
|
||||
view = views.Isbn.as_view()
|
||||
|
|
|
@ -12,9 +12,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class NotificationViews(TestCase):
|
||||
"""notifications"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -34,6 +34,10 @@ class NotificationViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_notifications_page_empty(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Notifications.as_view()
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm.settings import USER_AGENT
|
|||
class OutboxView(TestCase):
|
||||
"""sends out activities"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we'll need some data"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -36,6 +36,10 @@ class OutboxView(TestCase):
|
|||
parent_work=work,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_outbox(self, _):
|
||||
"""returns user's statuses"""
|
||||
request = self.factory.get("")
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm import models, views
|
|||
class ReadingViews(TestCase):
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -46,6 +46,10 @@ class ReadingViews(TestCase):
|
|||
parent_work=self.work,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_start_reading(self, *_):
|
||||
"""begin a book"""
|
||||
shelf = self.local_user.shelf_set.get(identifier=models.Shelf.READING)
|
||||
|
|
|
@ -15,10 +15,9 @@ from bookwyrm import models
|
|||
class ReadThrough(TestCase):
|
||||
"""readthrough tests"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""basic user and book data"""
|
||||
self.client = Client()
|
||||
|
||||
self.work = models.Work.objects.create(title="Example Work")
|
||||
|
||||
self.edition = models.Edition.objects.create(
|
||||
|
@ -32,6 +31,9 @@ class ReadThrough(TestCase):
|
|||
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.client = Client()
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
self.client.force_login(self.user)
|
||||
|
||||
|
|
|
@ -11,10 +11,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class ReportViews(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -41,6 +40,10 @@ class ReportViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_report_modal_view(self):
|
||||
"""a user reports another user"""
|
||||
request = self.factory.get("")
|
||||
|
|
|
@ -12,7 +12,8 @@ from bookwyrm.views import rss_feed
|
|||
class RssFeedView(TestCase):
|
||||
"""rss feed behaves as expected"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -25,10 +26,12 @@ class RssFeedView(TestCase):
|
|||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
)
|
||||
self.factory = RequestFactory()
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_rss_empty(self, *_):
|
||||
"""load an rss feed"""
|
||||
view = rss_feed.RssFeed()
|
||||
|
|
|
@ -17,9 +17,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class Views(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -39,6 +39,10 @@ class Views(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_search_json_response(self):
|
||||
"""searches local data only and returns book data in json format"""
|
||||
view = views.Search.as_view()
|
||||
|
|
|
@ -13,11 +13,15 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class SetupViews(TestCase):
|
||||
"""activity feed, statuses, dms"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
self.site = models.SiteSettings.objects.create(install_mode=True)
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_instance_config_permission_denied(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
self.site.install_mode = False
|
||||
|
|
|
@ -11,7 +11,7 @@ from bookwyrm.settings import DOMAIN
|
|||
|
||||
from bookwyrm.tests.validate_html import validate_html
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
class StatusTransactions(TransactionTestCase):
|
||||
"""Test full database transactions"""
|
||||
|
@ -74,9 +74,9 @@ class StatusTransactions(TransactionTestCase):
|
|||
class StatusViews(TestCase):
|
||||
"""viewing and creating statuses"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -106,7 +106,6 @@ class StatusViews(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
|
@ -115,6 +114,10 @@ class StatusViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_create_status_comment(self, *_):
|
||||
"""create a status"""
|
||||
view = views.CreateStatus.as_view()
|
||||
|
@ -323,14 +326,14 @@ class StatusViews(TestCase):
|
|||
|
||||
def test_find_mentions_unknown_remote(self, *_):
|
||||
"""mention a user that isn't in the database"""
|
||||
with patch("bookwyrm.views.status.handle_remote_webfinger") as rw:
|
||||
rw.return_value = self.another_user
|
||||
with patch("bookwyrm.views.status.handle_remote_webfinger") as rwf:
|
||||
rwf.return_value = self.another_user
|
||||
result = find_mentions(self.local_user, "@beep@beep.com")
|
||||
self.assertEqual(result["@nutria"], self.another_user)
|
||||
self.assertEqual(result[f"@nutria@{DOMAIN}"], self.another_user)
|
||||
|
||||
with patch("bookwyrm.views.status.handle_remote_webfinger") as rw:
|
||||
rw.return_value = None
|
||||
with patch("bookwyrm.views.status.handle_remote_webfinger") as rwf:
|
||||
rwf.return_value = None
|
||||
result = find_mentions(self.local_user, "@beep@beep.com")
|
||||
self.assertEqual(result, {})
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ from bookwyrm import models, views
|
|||
class UpdateViews(TestCase):
|
||||
"""lets the ui check for unread notification"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -27,6 +27,10 @@ class UpdateViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_get_notification_count(self):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
request = self.factory.get("")
|
||||
|
|
|
@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html
|
|||
class UserViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -44,8 +44,11 @@ class UserViews(TestCase):
|
|||
user=self.local_user,
|
||||
shelf=self.local_user.shelf_set.first(),
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ from bookwyrm import models, views
|
|||
class WellknownViews(TestCase):
|
||||
"""view user and edit profile"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
|
@ -40,6 +40,10 @@ class WellknownViews(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
self.factory = RequestFactory()
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue