From accb3273f1f1a2f2465aee39ba9b3ddeecb5e4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Fri, 26 Jan 2024 06:42:25 -0300 Subject: [PATCH 01/10] When determining privacy, check for unlisted early If `followers_url` is found in `to`, the post may still be _unlisted_ if `"https://www.w3.org/ns/activitystreams#Public"` appears in `cc`. Hence this should be checked earlier. --- bookwyrm/models/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 4bd580705..107f4055a 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -260,12 +260,12 @@ class PrivacyField(ActivitypubFieldMixin, models.CharField): if to == [self.public]: setattr(instance, self.name, "public") + elif self.public in cc: + setattr(instance, self.name, "unlisted") elif to == [user.followers_url]: setattr(instance, self.name, "followers") elif cc == []: setattr(instance, self.name, "direct") - elif self.public in cc: - setattr(instance, self.name, "unlisted") else: setattr(instance, self.name, "followers") return original == getattr(instance, self.name) From 1b9e0546e64dd0306c3389034fa0df8127d22e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 17 Mar 2024 19:46:30 -0300 Subject: [PATCH 02/10] Bracket-wrap calls to `patch()` for better readability --- .../tests/activitypub/test_base_activity.py | 8 +- bookwyrm/tests/activitypub/test_note.py | 8 +- .../activitystreams/test_abstractstream.py | 16 ++- .../tests/activitystreams/test_booksstream.py | 8 +- .../tests/activitystreams/test_homestream.py | 8 +- .../tests/activitystreams/test_localstream.py | 8 +- .../tests/activitystreams/test_signals.py | 8 +- bookwyrm/tests/activitystreams/test_tasks.py | 8 +- .../connectors/test_inventaire_connector.py | 13 ++- .../tests/importers/test_calibre_import.py | 8 +- .../tests/importers/test_goodreads_import.py | 8 +- bookwyrm/tests/importers/test_importer.py | 8 +- .../importers/test_librarything_import.py | 8 +- .../importers/test_openlibrary_import.py | 8 +- .../tests/importers/test_storygraph_import.py | 8 +- bookwyrm/tests/lists_stream/test_signals.py | 8 +- bookwyrm/tests/lists_stream/test_stream.py | 8 +- bookwyrm/tests/lists_stream/test_tasks.py | 15 ++- .../management/test_populate_lists_streams.py | 8 +- .../tests/management/test_populate_streams.py | 17 +-- .../tests/models/test_activitypub_mixin.py | 8 +- bookwyrm/tests/models/test_automod.py | 8 +- bookwyrm/tests/models/test_base_model.py | 8 +- .../tests/models/test_bookwyrm_export_job.py | 18 ++- .../tests/models/test_bookwyrm_import_job.py | 110 +++++++++++------- bookwyrm/tests/models/test_group.py | 22 ++-- bookwyrm/tests/models/test_import_model.py | 8 +- bookwyrm/tests/models/test_list.py | 8 +- bookwyrm/tests/models/test_notification.py | 24 ++-- .../tests/models/test_readthrough_model.py | 8 +- .../tests/models/test_relationship_models.py | 8 +- bookwyrm/tests/models/test_shelf_model.py | 8 +- bookwyrm/tests/models/test_site.py | 8 +- bookwyrm/tests/models/test_status_model.py | 8 +- bookwyrm/tests/models/test_user_model.py | 37 +++--- .../templatetags/test_book_display_tags.py | 8 +- .../tests/templatetags/test_feed_page_tags.py | 8 +- .../tests/templatetags/test_interaction.py | 8 +- .../test_notification_page_tags.py | 8 +- .../tests/templatetags/test_rating_tags.py | 8 +- .../tests/templatetags/test_shelf_tags.py | 8 +- .../tests/templatetags/test_status_display.py | 8 +- bookwyrm/tests/templatetags/test_utilities.py | 8 +- bookwyrm/tests/test_context_processors.py | 8 +- bookwyrm/tests/test_emailing.py | 8 +- bookwyrm/tests/test_preview_images.py | 24 ++-- bookwyrm/tests/test_signing.py | 8 +- bookwyrm/tests/test_suggested_users.py | 8 +- .../tests/views/admin/test_announcements.py | 8 +- bookwyrm/tests/views/admin/test_automod.py | 8 +- bookwyrm/tests/views/admin/test_celery.py | 8 +- bookwyrm/tests/views/admin/test_dashboard.py | 8 +- .../tests/views/admin/test_email_blocks.py | 8 +- .../tests/views/admin/test_email_config.py | 8 +- bookwyrm/tests/views/admin/test_federation.py | 8 +- bookwyrm/tests/views/admin/test_imports.py | 8 +- .../tests/views/admin/test_ip_blocklist.py | 8 +- .../tests/views/admin/test_link_domains.py | 8 +- bookwyrm/tests/views/admin/test_reports.py | 8 +- bookwyrm/tests/views/admin/test_site.py | 8 +- bookwyrm/tests/views/admin/test_themes.py | 8 +- bookwyrm/tests/views/admin/test_user_admin.py | 8 +- bookwyrm/tests/views/books/test_book.py | 8 +- bookwyrm/tests/views/books/test_edit_book.py | 8 +- bookwyrm/tests/views/books/test_editions.py | 8 +- bookwyrm/tests/views/books/test_links.py | 5 +- bookwyrm/tests/views/imports/test_import.py | 8 +- .../tests/views/imports/test_import_review.py | 8 +- .../views/imports/test_import_troubleshoot.py | 8 +- .../tests/views/imports/test_user_import.py | 8 +- bookwyrm/tests/views/inbox/test_inbox.py | 8 +- bookwyrm/tests/views/inbox/test_inbox_add.py | 8 +- .../tests/views/inbox/test_inbox_announce.py | 8 +- .../tests/views/inbox/test_inbox_block.py | 17 ++- .../tests/views/inbox/test_inbox_create.py | 16 ++- .../tests/views/inbox/test_inbox_delete.py | 8 +- .../tests/views/inbox/test_inbox_follow.py | 8 +- bookwyrm/tests/views/inbox/test_inbox_like.py | 8 +- .../tests/views/inbox/test_inbox_remove.py | 15 ++- .../tests/views/inbox/test_inbox_update.py | 15 ++- bookwyrm/tests/views/landing/test_invite.py | 8 +- bookwyrm/tests/views/landing/test_landing.py | 8 +- bookwyrm/tests/views/landing/test_login.py | 8 +- bookwyrm/tests/views/landing/test_password.py | 8 +- bookwyrm/tests/views/landing/test_register.py | 8 +- bookwyrm/tests/views/lists/test_curate.py | 15 ++- bookwyrm/tests/views/lists/test_embed.py | 15 ++- bookwyrm/tests/views/lists/test_list.py | 33 ++++-- bookwyrm/tests/views/lists/test_list_item.py | 15 ++- bookwyrm/tests/views/lists/test_lists.py | 46 +++++--- .../tests/views/preferences/test_block.py | 18 +-- .../views/preferences/test_change_password.py | 8 +- .../views/preferences/test_delete_user.py | 15 ++- .../tests/views/preferences/test_edit_user.py | 15 ++- .../tests/views/preferences/test_export.py | 5 +- .../views/preferences/test_export_user.py | 5 +- .../views/preferences/test_two_factor_auth.py | 13 ++- bookwyrm/tests/views/shelf/test_shelf.py | 8 +- .../tests/views/shelf/test_shelf_actions.py | 8 +- bookwyrm/tests/views/test_annual_summary.py | 8 +- bookwyrm/tests/views/test_author.py | 8 +- bookwyrm/tests/views/test_directory.py | 8 +- bookwyrm/tests/views/test_discover.py | 8 +- bookwyrm/tests/views/test_feed.py | 8 +- bookwyrm/tests/views/test_follow.py | 24 ++-- bookwyrm/tests/views/test_get_started.py | 8 +- bookwyrm/tests/views/test_goal.py | 8 +- bookwyrm/tests/views/test_group.py | 8 +- bookwyrm/tests/views/test_hashtag.py | 36 +++--- bookwyrm/tests/views/test_helpers.py | 8 +- bookwyrm/tests/views/test_interaction.py | 8 +- bookwyrm/tests/views/test_isbn.py | 8 +- bookwyrm/tests/views/test_notifications.py | 15 ++- bookwyrm/tests/views/test_outbox.py | 8 +- bookwyrm/tests/views/test_reading.py | 8 +- bookwyrm/tests/views/test_readthrough.py | 8 +- bookwyrm/tests/views/test_report.py | 15 ++- bookwyrm/tests/views/test_rss_feed.py | 8 +- bookwyrm/tests/views/test_search.py | 15 ++- bookwyrm/tests/views/test_status.py | 16 ++- bookwyrm/tests/views/test_updates.py | 34 +++--- bookwyrm/tests/views/test_user.py | 16 +-- bookwyrm/tests/views/test_wellknown.py | 8 +- 123 files changed, 883 insertions(+), 559 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index a0d10019f..8f2cd7fb2 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -31,9 +31,11 @@ class BaseActivity(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we're probably going to re-use this so why copy/paste""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/activitypub/test_note.py b/bookwyrm/tests/activitypub/test_note.py index fd5467f01..65502c70a 100644 --- a/bookwyrm/tests/activitypub/test_note.py +++ b/bookwyrm/tests/activitypub/test_note.py @@ -13,9 +13,11 @@ class Note(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create a shared user""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/activitystreams/test_abstractstream.py b/bookwyrm/tests/activitystreams/test_abstractstream.py index 83985efdc..acdd5529c 100644 --- a/bookwyrm/tests/activitystreams/test_abstractstream.py +++ b/bookwyrm/tests/activitystreams/test_abstractstream.py @@ -18,9 +18,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) @@ -105,9 +107,11 @@ class Activitystreams(TestCase): privacy="direct", book=self.book, ) - with patch("bookwyrm.activitystreams.r.set"), patch( - "bookwyrm.activitystreams.r.delete" - ), patch("bookwyrm.activitystreams.ActivityStream.get_store") as redis_mock: + with ( + patch("bookwyrm.activitystreams.r.set"), + patch("bookwyrm.activitystreams.r.delete"), + patch("bookwyrm.activitystreams.ActivityStream.get_store") as redis_mock, + ): redis_mock.return_value = [status.id, status2.id] result = self.test_stream.get_activity_stream(self.local_user) self.assertEqual(result.count(), 2) diff --git a/bookwyrm/tests/activitystreams/test_booksstream.py b/bookwyrm/tests/activitystreams/test_booksstream.py index 71d7ce531..eb61cc203 100644 --- a/bookwyrm/tests/activitystreams/test_booksstream.py +++ b/bookwyrm/tests/activitystreams/test_booksstream.py @@ -17,9 +17,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/activitystreams/test_homestream.py b/bookwyrm/tests/activitystreams/test_homestream.py index 3312f20ee..0baf1d1b8 100644 --- a/bookwyrm/tests/activitystreams/test_homestream.py +++ b/bookwyrm/tests/activitystreams/test_homestream.py @@ -15,9 +15,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/activitystreams/test_localstream.py b/bookwyrm/tests/activitystreams/test_localstream.py index f4ca13395..92ec2b069 100644 --- a/bookwyrm/tests/activitystreams/test_localstream.py +++ b/bookwyrm/tests/activitystreams/test_localstream.py @@ -15,9 +15,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/activitystreams/test_signals.py b/bookwyrm/tests/activitystreams/test_signals.py index db16a0081..b9fb75ade 100644 --- a/bookwyrm/tests/activitystreams/test_signals.py +++ b/bookwyrm/tests/activitystreams/test_signals.py @@ -17,9 +17,11 @@ class ActivitystreamsSignals(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/activitystreams/test_tasks.py b/bookwyrm/tests/activitystreams/test_tasks.py index 39a240e92..cf2ee40e6 100644 --- a/bookwyrm/tests/activitystreams/test_tasks.py +++ b/bookwyrm/tests/activitystreams/test_tasks.py @@ -10,9 +10,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/connectors/test_inventaire_connector.py b/bookwyrm/tests/connectors/test_inventaire_connector.py index c4ea1a595..874d64862 100644 --- a/bookwyrm/tests/connectors/test_inventaire_connector.py +++ b/bookwyrm/tests/connectors/test_inventaire_connector.py @@ -212,11 +212,14 @@ class Inventaire(TestCase): json={"entities": {}}, ) data = {"uri": "blah"} - with patch( - "bookwyrm.connectors.inventaire.Connector.load_edition_data" - ) as loader_mock, patch( - "bookwyrm.connectors.inventaire.Connector.get_book_data" - ) as getter_mock: + with ( + patch( + "bookwyrm.connectors.inventaire.Connector.load_edition_data" + ) as loader_mock, + patch( + "bookwyrm.connectors.inventaire.Connector.get_book_data" + ) as getter_mock, + ): loader_mock.return_value = {"uris": ["hello"]} self.connector.get_edition_from_work_data(data) self.assertTrue(getter_mock.called) diff --git a/bookwyrm/tests/importers/test_calibre_import.py b/bookwyrm/tests/importers/test_calibre_import.py index d549a75ed..6bfa754af 100644 --- a/bookwyrm/tests/importers/test_calibre_import.py +++ b/bookwyrm/tests/importers/test_calibre_import.py @@ -25,9 +25,11 @@ class CalibreImport(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """populate database""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index 0b5fd5e2d..deb41a1df 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -32,9 +32,11 @@ class GoodreadsImport(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """populate database""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index eb3041dc6..494d28ad0 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -35,9 +35,11 @@ class GenericImporter(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """populate database""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index c2fe7a9a8..ba86721de 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -34,9 +34,11 @@ class LibrarythingImport(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """populate database""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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( "mmai", "mmai@mmai.mmai", "password", local=True ) diff --git a/bookwyrm/tests/importers/test_openlibrary_import.py b/bookwyrm/tests/importers/test_openlibrary_import.py index 2712930d9..e0e6135c9 100644 --- a/bookwyrm/tests/importers/test_openlibrary_import.py +++ b/bookwyrm/tests/importers/test_openlibrary_import.py @@ -32,9 +32,11 @@ class OpenLibraryImport(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """populate database""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/importers/test_storygraph_import.py b/bookwyrm/tests/importers/test_storygraph_import.py index edc484629..180cd8ad4 100644 --- a/bookwyrm/tests/importers/test_storygraph_import.py +++ b/bookwyrm/tests/importers/test_storygraph_import.py @@ -32,9 +32,11 @@ class StorygraphImport(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """populate database""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/lists_stream/test_signals.py b/bookwyrm/tests/lists_stream/test_signals.py index 51f0709b0..923d19a2f 100644 --- a/bookwyrm/tests/lists_stream/test_signals.py +++ b/bookwyrm/tests/lists_stream/test_signals.py @@ -11,9 +11,11 @@ class ListsStreamSignals(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """database setup""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/lists_stream/test_stream.py b/bookwyrm/tests/lists_stream/test_stream.py index 6dd6a1c8e..fcac04d19 100644 --- a/bookwyrm/tests/lists_stream/test_stream.py +++ b/bookwyrm/tests/lists_stream/test_stream.py @@ -18,9 +18,11 @@ class ListsStream(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """database setup""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/lists_stream/test_tasks.py b/bookwyrm/tests/lists_stream/test_tasks.py index 18ddecf18..fe3cb319d 100644 --- a/bookwyrm/tests/lists_stream/test_tasks.py +++ b/bookwyrm/tests/lists_stream/test_tasks.py @@ -13,9 +13,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """database setup""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) @@ -36,9 +38,10 @@ class Activitystreams(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): self.list = models.List.objects.create( user=self.local_user, name="hi", privacy="public" ) diff --git a/bookwyrm/tests/management/test_populate_lists_streams.py b/bookwyrm/tests/management/test_populate_lists_streams.py index 5990da4e3..f098c2b11 100644 --- a/bookwyrm/tests/management/test_populate_lists_streams.py +++ b/bookwyrm/tests/management/test_populate_lists_streams.py @@ -15,9 +15,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need some stuff""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index 4d6bf688f..034222b29 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -13,9 +13,11 @@ class Activitystreams(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need some stuff""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) @@ -53,11 +55,10 @@ class Activitystreams(TestCase): user=self.local_user, content="hi", book=self.book ) - with patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ) as redis_mock, patch( - "bookwyrm.lists_stream.populate_lists_task.delay" - ) as list_mock: + with ( + patch("bookwyrm.activitystreams.populate_stream_task.delay") as redis_mock, + patch("bookwyrm.lists_stream.populate_lists_task.delay") as list_mock, + ): populate_streams() self.assertEqual(redis_mock.call_count, 6) # 2 users x 3 streams self.assertEqual(list_mock.call_count, 2) # 2 users diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 2f6fad76d..b59088f91 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -29,9 +29,11 @@ class ActivitypubMixins(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """shared 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"): + 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", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_automod.py b/bookwyrm/tests/models/test_automod.py index 1ad139886..ed3133cdc 100644 --- a/bookwyrm/tests/models/test_automod.py +++ b/bookwyrm/tests/models/test_automod.py @@ -17,9 +17,11 @@ class AutomodModel(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index f1f465b73..d0e441cef 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -15,9 +15,11 @@ class BaseModel(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """shared 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"): + 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", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_bookwyrm_export_job.py b/bookwyrm/tests/models/test_bookwyrm_export_job.py index b5f2520a9..be6bda3cc 100644 --- a/bookwyrm/tests/models/test_bookwyrm_export_job.py +++ b/bookwyrm/tests/models/test_bookwyrm_export_job.py @@ -16,16 +16,14 @@ class BookwyrmExport(TestCase): def setUp(self): """lots of stuff to set up for a user export""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"), patch( - "bookwyrm.suggested_users.rerank_user_task.delay" - ), patch( - "bookwyrm.lists_stream.remove_list_task.delay" - ), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch( - "bookwyrm.activitystreams.add_book_statuses_task" + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + patch("bookwyrm.suggested_users.rerank_user_task.delay"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_book_statuses_task"), ): self.local_user = models.User.objects.create_user( diff --git a/bookwyrm/tests/models/test_bookwyrm_import_job.py b/bookwyrm/tests/models/test_bookwyrm_import_job.py index adc04706c..50c136f21 100644 --- a/bookwyrm/tests/models/test_bookwyrm_import_job.py +++ b/bookwyrm/tests/models/test_bookwyrm_import_job.py @@ -18,10 +18,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods def setUp(self): """setting stuff up""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"), patch( - "bookwyrm.suggested_users.rerank_user_task.delay" + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): self.local_user = models.User.objects.create_user( @@ -78,9 +79,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods def test_update_user_profile(self): """Test update the user's profile from import data""" - with patch("bookwyrm.suggested_users.remove_user_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.suggested_users.rerank_user_task.delay"): + with ( + patch("bookwyrm.suggested_users.remove_user_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.suggested_users.rerank_user_task.delay"), + ): with open(self.archive_file, "rb") as fileobj: with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile: @@ -103,9 +106,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods def test_update_user_settings(self): """Test updating the user's settings from import data""" - with patch("bookwyrm.suggested_users.remove_user_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.suggested_users.rerank_user_task.delay"): + with ( + patch("bookwyrm.suggested_users.remove_user_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.suggested_users.rerank_user_task.delay"), + ): models.bookwyrm_import_job.update_user_settings( self.local_user, self.json_data @@ -145,8 +150,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods def test_upsert_saved_lists_existing(self): """Test upserting an existing saved list""" - with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.lists_stream.remove_list_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): book_list = models.List.objects.create( name="My cool list", @@ -172,8 +178,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods def test_upsert_saved_lists_not_existing(self): """Test upserting a new saved list""" - with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.lists_stream.remove_list_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): book_list = models.List.objects.create( name="My cool list", @@ -199,9 +206,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods self.assertFalse(before_follow) - with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"), patch( - "bookwyrm.lists_stream.add_user_lists_task.delay" - ), patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): + with ( + patch("bookwyrm.activitystreams.add_user_statuses_task.delay"), + patch("bookwyrm.lists_stream.add_user_lists_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + ): models.bookwyrm_import_job.upsert_follows( self.local_user, self.json_data.get("follows") ) @@ -222,10 +231,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods ).exists() self.assertFalse(blocked_before) - with patch("bookwyrm.suggested_users.remove_suggestion_task.delay"), patch( - "bookwyrm.activitystreams.remove_user_statuses_task.delay" - ), patch("bookwyrm.lists_stream.remove_user_lists_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.suggested_users.remove_suggestion_task.delay"), + patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"), + patch("bookwyrm.lists_stream.remove_user_lists_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): models.bookwyrm_import_job.upsert_user_blocks( self.local_user, self.json_data.get("blocks") @@ -312,9 +322,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods self.assertEqual(models.Review.objects.filter(user=self.local_user).count(), 0) reviews = self.json_data["books"][0]["reviews"] - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True), + ): bookwyrm_import_job.upsert_statuses( self.local_user, models.Review, reviews, self.book.remote_id @@ -349,9 +360,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods self.assertEqual(models.Comment.objects.filter(user=self.local_user).count(), 0) comments = self.json_data["books"][1]["comments"] - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True), + ): bookwyrm_import_job.upsert_statuses( self.local_user, models.Comment, comments, self.book.remote_id @@ -378,9 +390,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods models.Quotation.objects.filter(user=self.local_user).count(), 0 ) quotes = self.json_data["books"][1]["quotations"] - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True), + ): bookwyrm_import_job.upsert_statuses( self.local_user, models.Quotation, quotes, self.book.remote_id @@ -411,9 +424,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods models.Quotation.objects.filter(user=self.local_user).count(), 0 ) quotes = self.json_data["books"][1]["quotations"] - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=False): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=False), + ): bookwyrm_import_job.upsert_statuses( self.local_user, models.Quotation, quotes, self.book.remote_id @@ -432,8 +446,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods title="Another Book", remote_id="https://example.com/book/9876" ) - with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.lists_stream.remove_list_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): book_list = models.List.objects.create( name="my list of books", user=self.local_user @@ -452,8 +467,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods 1, ) - with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.lists_stream.remove_list_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): bookwyrm_import_job.upsert_lists( self.local_user, @@ -479,8 +495,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods self.assertEqual(models.List.objects.filter(user=self.local_user).count(), 0) self.assertFalse(models.ListItem.objects.filter(book=self.book.id).exists()) - with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.lists_stream.remove_list_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): bookwyrm_import_job.upsert_lists( self.local_user, @@ -503,16 +520,18 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods shelf = models.Shelf.objects.get(name="Read", user=self.local_user) - with patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): models.ShelfBook.objects.create( book=self.book, shelf=shelf, user=self.local_user ) book_data = self.json_data["books"][0] - with patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): bookwyrm_import_job.upsert_shelves(self.book, self.local_user, book_data) @@ -530,8 +549,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods book_data = self.json_data["books"][0] - with patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + with ( + patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), ): bookwyrm_import_job.upsert_shelves(self.book, self.local_user, book_data) diff --git a/bookwyrm/tests/models/test_group.py b/bookwyrm/tests/models/test_group.py index 6f5388b19..3ea424333 100644 --- a/bookwyrm/tests/models/test_group.py +++ b/bookwyrm/tests/models/test_group.py @@ -13,9 +13,11 @@ class Group(TestCase): def setUpTestData(self): # pylint: disable=bad-classmethod-argument """Set up for tests""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.owner_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) @@ -81,9 +83,10 @@ class Group(TestCase): """follower-only group booklists should not be excluded from group booklist listing for group members who do not follower list owner""" - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): followers_list = models.List.objects.create( name="Followers List", curation="group", @@ -104,9 +107,10 @@ class Group(TestCase): """private group booklists should not be excluded from group booklist listing for group members""" - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): private_list = models.List.objects.create( name="Private List", privacy="direct", diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index 7ca36d223..e5be01464 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -19,9 +19,11 @@ class ImportJob(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """data is from a goodreads export of The Raven Tower""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/models/test_list.py b/bookwyrm/tests/models/test_list.py index 83d7ed6a5..b1b756cab 100644 --- a/bookwyrm/tests/models/test_list.py +++ b/bookwyrm/tests/models/test_list.py @@ -14,9 +14,11 @@ class List(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """look, a list""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_notification.py b/bookwyrm/tests/models/test_notification.py index 93422640b..a9ed8b661 100644 --- a/bookwyrm/tests/models/test_notification.py +++ b/bookwyrm/tests/models/test_notification.py @@ -10,9 +10,11 @@ class Notification(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """useful things for creating a notification""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) @@ -201,9 +203,11 @@ class NotifyInviteRequest(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """ensure there is one admin""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -264,9 +268,11 @@ class NotifyInviteRequest(TestCase): def test_notify_multiple_admins(self): """all admins are notified""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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( "admin@local.com", "admin@example.com", diff --git a/bookwyrm/tests/models/test_readthrough_model.py b/bookwyrm/tests/models/test_readthrough_model.py index d34a06aaf..0da87f67b 100644 --- a/bookwyrm/tests/models/test_readthrough_model.py +++ b/bookwyrm/tests/models/test_readthrough_model.py @@ -14,9 +14,11 @@ class ReadThrough(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """look, a shelf""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_relationship_models.py b/bookwyrm/tests/models/test_relationship_models.py index 8f849bc3b..dbb0ac8bb 100644 --- a/bookwyrm/tests/models/test_relationship_models.py +++ b/bookwyrm/tests/models/test_relationship_models.py @@ -27,9 +27,11 @@ class Relationship(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 88b1fad06..2d45dadbc 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -18,9 +18,11 @@ class Shelf(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """look, a shelf""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_site.py b/bookwyrm/tests/models/test_site.py index f4accc04b..8cf15ad6f 100644 --- a/bookwyrm/tests/models/test_site.py +++ b/bookwyrm/tests/models/test_site.py @@ -15,9 +15,11 @@ class SiteModels(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 9899f6bf3..32ccc2c57 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -27,9 +27,11 @@ class Status(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """useful things for creating a status""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index 47a662e49..a47896269 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -20,9 +20,11 @@ class User(TestCase): @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"): + 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.user = models.User.objects.create_user( f"mouse@{DOMAIN}", "mouse@mouse.mouse", @@ -122,9 +124,11 @@ class User(TestCase): site.default_user_auth_group = Group.objects.get(name="editor") site.save() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): user = models.User.objects.create_user( f"test2{DOMAIN}", "test2@bookwyrm.test", @@ -135,9 +139,11 @@ class User(TestCase): site.default_user_auth_group = None site.save() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): user = models.User.objects.create_user( f"test1{DOMAIN}", "test1@bookwyrm.test", @@ -228,11 +234,14 @@ class User(TestCase): self.assertEqual(self.user.name, "hi") self.assertEqual(self.user.summary, "a summary") self.assertEqual(self.user.email, "mouse@mouse.mouse") - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ) as broadcast_mock, patch( - "bookwyrm.models.user.User.erase_user_statuses" - ) as erase_statuses_mock: + with ( + patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ) as broadcast_mock, + patch( + "bookwyrm.models.user.User.erase_user_statuses" + ) as erase_statuses_mock, + ): self.user.delete() self.assertEqual(erase_statuses_mock.call_count, 1) diff --git a/bookwyrm/tests/templatetags/test_book_display_tags.py b/bookwyrm/tests/templatetags/test_book_display_tags.py index dcff01a80..77d6fee54 100644 --- a/bookwyrm/tests/templatetags/test_book_display_tags.py +++ b/bookwyrm/tests/templatetags/test_book_display_tags.py @@ -16,9 +16,11 @@ class BookDisplayTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_feed_page_tags.py b/bookwyrm/tests/templatetags/test_feed_page_tags.py index d0a895f36..891bfc32c 100644 --- a/bookwyrm/tests/templatetags/test_feed_page_tags.py +++ b/bookwyrm/tests/templatetags/test_feed_page_tags.py @@ -15,9 +15,11 @@ class FeedPageTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_interaction.py b/bookwyrm/tests/templatetags/test_interaction.py index a9d1267c0..bd66575ff 100644 --- a/bookwyrm/tests/templatetags/test_interaction.py +++ b/bookwyrm/tests/templatetags/test_interaction.py @@ -15,9 +15,11 @@ class InteractionTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_notification_page_tags.py b/bookwyrm/tests/templatetags/test_notification_page_tags.py index 94f839ec5..df2805828 100644 --- a/bookwyrm/tests/templatetags/test_notification_page_tags.py +++ b/bookwyrm/tests/templatetags/test_notification_page_tags.py @@ -15,9 +15,11 @@ class NotificationPageTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_rating_tags.py b/bookwyrm/tests/templatetags/test_rating_tags.py index 5225d57a6..f50236262 100644 --- a/bookwyrm/tests/templatetags/test_rating_tags.py +++ b/bookwyrm/tests/templatetags/test_rating_tags.py @@ -15,9 +15,11 @@ class RatingTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_shelf_tags.py b/bookwyrm/tests/templatetags/test_shelf_tags.py index 7c456c815..47e86d9ef 100644 --- a/bookwyrm/tests/templatetags/test_shelf_tags.py +++ b/bookwyrm/tests/templatetags/test_shelf_tags.py @@ -18,9 +18,11 @@ class ShelfTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index a9bab0b68..af125fd06 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -17,9 +17,11 @@ class StatusDisplayTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/templatetags/test_utilities.py b/bookwyrm/tests/templatetags/test_utilities.py index 1bf98fda8..6fade22a7 100644 --- a/bookwyrm/tests/templatetags/test_utilities.py +++ b/bookwyrm/tests/templatetags/test_utilities.py @@ -17,9 +17,11 @@ class UtilitiesTags(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/test_context_processors.py b/bookwyrm/tests/test_context_processors.py index 614db681c..e5290f312 100644 --- a/bookwyrm/tests/test_context_processors.py +++ b/bookwyrm/tests/test_context_processors.py @@ -14,9 +14,11 @@ class ContextProcessor(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/test_emailing.py b/bookwyrm/tests/test_emailing.py index 119941e85..8a5b543d5 100644 --- a/bookwyrm/tests/test_emailing.py +++ b/bookwyrm/tests/test_emailing.py @@ -14,9 +14,11 @@ class Emailing(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/test_preview_images.py b/bookwyrm/tests/test_preview_images.py index d1998bf3c..4f711b38b 100644 --- a/bookwyrm/tests/test_preview_images.py +++ b/bookwyrm/tests/test_preview_images.py @@ -31,9 +31,11 @@ class PreviewImages(TestCase): avatar_file = pathlib.Path(__file__).parent.joinpath( "../static/images/no_cover.jpg" ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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( "possum@local.com", "possum@possum.possum", @@ -47,9 +49,11 @@ class PreviewImages(TestCase): ), ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", @@ -60,9 +64,11 @@ class PreviewImages(TestCase): outbox="https://example.com/users/rat/outbox", ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.remote_user_with_preview = models.User.objects.create_user( "badger@your.domain.here", "badger@badger.com", diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index b539f089b..80a35b94d 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -38,9 +38,11 @@ class Signature(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create users and test 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"): + 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.mouse = models.User.objects.create_user( f"mouse@{DOMAIN}", "mouse@example.com", diff --git a/bookwyrm/tests/test_suggested_users.py b/bookwyrm/tests/test_suggested_users.py index 77b82e7ee..0a6dd8abe 100644 --- a/bookwyrm/tests/test_suggested_users.py +++ b/bookwyrm/tests/test_suggested_users.py @@ -22,9 +22,11 @@ class SuggestedUsers(TestCase): def setUp(self): """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/views/admin/test_announcements.py b/bookwyrm/tests/views/admin/test_announcements.py index 30bc94a1f..958d78fc4 100644 --- a/bookwyrm/tests/views/admin/test_announcements.py +++ b/bookwyrm/tests/views/admin/test_announcements.py @@ -14,9 +14,11 @@ class AnnouncementViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_automod.py b/bookwyrm/tests/views/admin/test_automod.py index 1835a24ee..332410eba 100644 --- a/bookwyrm/tests/views/admin/test_automod.py +++ b/bookwyrm/tests/views/admin/test_automod.py @@ -18,9 +18,11 @@ class AutomodViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_celery.py b/bookwyrm/tests/views/admin/test_celery.py index d215a9657..577d312b1 100644 --- a/bookwyrm/tests/views/admin/test_celery.py +++ b/bookwyrm/tests/views/admin/test_celery.py @@ -17,9 +17,11 @@ class CeleryStatusViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_dashboard.py b/bookwyrm/tests/views/admin/test_dashboard.py index 8eeb754a8..a68b046e3 100644 --- a/bookwyrm/tests/views/admin/test_dashboard.py +++ b/bookwyrm/tests/views/admin/test_dashboard.py @@ -17,9 +17,11 @@ class DashboardViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_email_blocks.py b/bookwyrm/tests/views/admin/test_email_blocks.py index 75c0be929..b37166d3c 100644 --- a/bookwyrm/tests/views/admin/test_email_blocks.py +++ b/bookwyrm/tests/views/admin/test_email_blocks.py @@ -17,9 +17,11 @@ class EmailBlocklistViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_email_config.py b/bookwyrm/tests/views/admin/test_email_config.py index 63d85cbef..374c2402e 100644 --- a/bookwyrm/tests/views/admin/test_email_config.py +++ b/bookwyrm/tests/views/admin/test_email_config.py @@ -17,9 +17,11 @@ class EmailConfigViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_federation.py b/bookwyrm/tests/views/admin/test_federation.py index 1a5067299..8244e8335 100644 --- a/bookwyrm/tests/views/admin/test_federation.py +++ b/bookwyrm/tests/views/admin/test_federation.py @@ -20,9 +20,11 @@ class FederationViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_imports.py b/bookwyrm/tests/views/admin/test_imports.py index 5a5599519..acb769546 100644 --- a/bookwyrm/tests/views/admin/test_imports.py +++ b/bookwyrm/tests/views/admin/test_imports.py @@ -17,9 +17,11 @@ class ImportsAdminViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_ip_blocklist.py b/bookwyrm/tests/views/admin/test_ip_blocklist.py index 06c110a06..b34828622 100644 --- a/bookwyrm/tests/views/admin/test_ip_blocklist.py +++ b/bookwyrm/tests/views/admin/test_ip_blocklist.py @@ -17,9 +17,11 @@ class IPBlocklistViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_link_domains.py b/bookwyrm/tests/views/admin/test_link_domains.py index 14eed419b..fabb7511a 100644 --- a/bookwyrm/tests/views/admin/test_link_domains.py +++ b/bookwyrm/tests/views/admin/test_link_domains.py @@ -17,9 +17,11 @@ class LinkDomainViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_reports.py b/bookwyrm/tests/views/admin/test_reports.py index 4334eeed9..7ce665451 100644 --- a/bookwyrm/tests/views/admin/test_reports.py +++ b/bookwyrm/tests/views/admin/test_reports.py @@ -18,9 +18,11 @@ class ReportViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_site.py b/bookwyrm/tests/views/admin/test_site.py index b7c687e09..ec5b07e3a 100644 --- a/bookwyrm/tests/views/admin/test_site.py +++ b/bookwyrm/tests/views/admin/test_site.py @@ -17,9 +17,11 @@ class SiteSettingsViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_themes.py b/bookwyrm/tests/views/admin/test_themes.py index 66384f5fc..b931ea561 100644 --- a/bookwyrm/tests/views/admin/test_themes.py +++ b/bookwyrm/tests/views/admin/test_themes.py @@ -18,9 +18,11 @@ class AdminThemesViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/admin/test_user_admin.py b/bookwyrm/tests/views/admin/test_user_admin.py index 99c630526..5247ff70f 100644 --- a/bookwyrm/tests/views/admin/test_user_admin.py +++ b/bookwyrm/tests/views/admin/test_user_admin.py @@ -18,9 +18,11 @@ class UserAdminViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/books/test_book.py b/bookwyrm/tests/views/books/test_book.py index 4d41eaa5d..68a114fb9 100644 --- a/bookwyrm/tests/views/books/test_book.py +++ b/bookwyrm/tests/views/books/test_book.py @@ -26,9 +26,11 @@ class BookViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/books/test_edit_book.py b/bookwyrm/tests/views/books/test_edit_book.py index 169112bab..0bd962de5 100644 --- a/bookwyrm/tests/views/books/test_edit_book.py +++ b/bookwyrm/tests/views/books/test_edit_book.py @@ -22,9 +22,11 @@ class EditBookViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/books/test_editions.py b/bookwyrm/tests/views/books/test_editions.py index e89fd521b..b829d471b 100644 --- a/bookwyrm/tests/views/books/test_editions.py +++ b/bookwyrm/tests/views/books/test_editions.py @@ -16,9 +16,11 @@ class BookViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/books/test_links.py b/bookwyrm/tests/views/books/test_links.py index 817463656..d1040a591 100644 --- a/bookwyrm/tests/views/books/test_links.py +++ b/bookwyrm/tests/views/books/test_links.py @@ -18,8 +18,9 @@ class LinkViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), ): self.local_user = models.User.objects.create_user( "mouse@local.com", diff --git a/bookwyrm/tests/views/imports/test_import.py b/bookwyrm/tests/views/imports/test_import.py index d0612ee68..c3b2795b1 100644 --- a/bookwyrm/tests/views/imports/test_import.py +++ b/bookwyrm/tests/views/imports/test_import.py @@ -19,9 +19,11 @@ class ImportViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/imports/test_import_review.py b/bookwyrm/tests/views/imports/test_import_review.py index 27bb3f9d1..5da02a56a 100644 --- a/bookwyrm/tests/views/imports/test_import_review.py +++ b/bookwyrm/tests/views/imports/test_import_review.py @@ -14,9 +14,11 @@ class ImportManualReviewViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/imports/test_import_troubleshoot.py b/bookwyrm/tests/views/imports/test_import_troubleshoot.py index 0e12c406a..9ddc99785 100644 --- a/bookwyrm/tests/views/imports/test_import_troubleshoot.py +++ b/bookwyrm/tests/views/imports/test_import_troubleshoot.py @@ -15,9 +15,11 @@ class ImportTroubleshootViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/imports/test_user_import.py b/bookwyrm/tests/views/imports/test_user_import.py index db5837101..4a676a57f 100644 --- a/bookwyrm/tests/views/imports/test_user_import.py +++ b/bookwyrm/tests/views/imports/test_user_import.py @@ -18,9 +18,11 @@ class ImportUserViews(TestCase): 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"): + 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", diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py index 1c05806a5..af85e84d4 100644 --- a/bookwyrm/tests/views/inbox/test_inbox.py +++ b/bookwyrm/tests/views/inbox/test_inbox.py @@ -31,9 +31,11 @@ class Inbox(TestCase): @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"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_add.py b/bookwyrm/tests/views/inbox/test_inbox_add.py index 5fbeaa33a..2bd5faf6a 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_add.py +++ b/bookwyrm/tests/views/inbox/test_inbox_add.py @@ -14,9 +14,11 @@ class InboxAdd(TestCase): @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"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index e6fdf9375..53555f213 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -14,9 +14,11 @@ class InboxActivities(TestCase): @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"): + 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@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index 9fef621ea..9cdf7eba3 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -13,9 +13,11 @@ class InboxBlock(TestCase): @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"): + 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@example.com", "mouse@mouse.com", @@ -56,9 +58,12 @@ class InboxBlock(TestCase): "object": "https://example.com/user/mouse", } - with patch( - "bookwyrm.activitystreams.remove_user_statuses_task.delay" - ) as redis_mock, patch("bookwyrm.lists_stream.remove_user_lists_task.delay"): + with ( + patch( + "bookwyrm.activitystreams.remove_user_statuses_task.delay" + ) as redis_mock, + patch("bookwyrm.lists_stream.remove_user_lists_task.delay"), + ): views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) views.inbox.activity_task(activity) diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index c2045b092..7f5be5b65 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -15,9 +15,11 @@ class TransactionInboxCreate(TransactionTestCase): def setUp(self): """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"): + 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@example.com", "mouse@mouse.com", @@ -74,9 +76,11 @@ class InboxCreate(TestCase): @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"): + 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@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 8023308be..9c2b589e2 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -14,9 +14,11 @@ class InboxActivities(TestCase): @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"): + 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@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index 180a57176..8ccffe1db 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -14,9 +14,11 @@ class InboxRelationships(TestCase): @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"): + 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@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index 34c8c830b..4a397dcf8 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -13,9 +13,11 @@ class InboxActivities(TestCase): @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"): + 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@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_remove.py b/bookwyrm/tests/views/inbox/test_inbox_remove.py index d80a4fdd7..f0be2b17a 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_remove.py +++ b/bookwyrm/tests/views/inbox/test_inbox_remove.py @@ -13,9 +13,11 @@ class InboxRemove(TestCase): @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"): + 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@example.com", "mouse@mouse.com", @@ -76,9 +78,10 @@ class InboxRemove(TestCase): def test_handle_remove_book_from_list(self): """listing a book""" - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): booklist = models.List.objects.create( name="test list", user=self.local_user, diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index b9f924bad..fb2c85a88 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -15,9 +15,11 @@ class InboxUpdate(TestCase): @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"): + 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@example.com", "mouse@mouse.com", @@ -53,9 +55,10 @@ class InboxUpdate(TestCase): def test_update_list(self): """a new list""" - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): book_list = models.List.objects.create( name="hi", remote_id="https://example.com/list/22", user=self.local_user ) diff --git a/bookwyrm/tests/views/landing/test_invite.py b/bookwyrm/tests/views/landing/test_invite.py index f7ec73cf4..5a76f578b 100644 --- a/bookwyrm/tests/views/landing/test_invite.py +++ b/bookwyrm/tests/views/landing/test_invite.py @@ -17,9 +17,11 @@ class InviteViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/landing/test_landing.py b/bookwyrm/tests/views/landing/test_landing.py index b67857da8..c0581d893 100644 --- a/bookwyrm/tests/views/landing/test_landing.py +++ b/bookwyrm/tests/views/landing/test_landing.py @@ -17,9 +17,11 @@ class LandingViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/landing/test_login.py b/bookwyrm/tests/views/landing/test_login.py index 19ad1d2a0..283890e3e 100644 --- a/bookwyrm/tests/views/landing/test_login.py +++ b/bookwyrm/tests/views/landing/test_login.py @@ -20,9 +20,11 @@ class LoginViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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@your.domain.here", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/landing/test_password.py b/bookwyrm/tests/views/landing/test_password.py index ceceeb3e4..8f322b3cb 100644 --- a/bookwyrm/tests/views/landing/test_password.py +++ b/bookwyrm/tests/views/landing/test_password.py @@ -19,9 +19,11 @@ class PasswordViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/landing/test_register.py b/bookwyrm/tests/views/landing/test_register.py index 381a35a32..4b3d46673 100644 --- a/bookwyrm/tests/views/landing/test_register.py +++ b/bookwyrm/tests/views/landing/test_register.py @@ -23,9 +23,11 @@ class RegisterViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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@your.domain.here", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/lists/test_curate.py b/bookwyrm/tests/views/lists/test_curate.py index 7fa48f915..59d73cefd 100644 --- a/bookwyrm/tests/views/lists/test_curate.py +++ b/bookwyrm/tests/views/lists/test_curate.py @@ -18,9 +18,11 @@ class ListViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -36,9 +38,10 @@ class ListViews(TestCase): parent_work=work, ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): self.list = models.List.objects.create( name="Test List", user=self.local_user ) diff --git a/bookwyrm/tests/views/lists/test_embed.py b/bookwyrm/tests/views/lists/test_embed.py index 40c51f5df..9c1d3846d 100644 --- a/bookwyrm/tests/views/lists/test_embed.py +++ b/bookwyrm/tests/views/lists/test_embed.py @@ -18,9 +18,11 @@ class ListViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -36,9 +38,10 @@ class ListViews(TestCase): parent_work=work, ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): self.list = models.List.objects.create( name="Test List", user=self.local_user ) diff --git a/bookwyrm/tests/views/lists/test_list.py b/bookwyrm/tests/views/lists/test_list.py index b1e7e2acc..dc144c134 100644 --- a/bookwyrm/tests/views/lists/test_list.py +++ b/bookwyrm/tests/views/lists/test_list.py @@ -21,9 +21,11 @@ class ListViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -65,9 +67,10 @@ class ListViews(TestCase): parent_work=work_four, ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): self.list = models.List.objects.create( name="Test List", user=self.local_user ) @@ -248,9 +251,12 @@ class ListViews(TestCase): ) request.user = self.local_user - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ) as mock, patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ) as mock, + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): result = view(request, self.list.id) self.assertEqual(mock.call_count, 1) @@ -286,9 +292,12 @@ class ListViews(TestCase): ) request = self.factory.post("") request.user = self.local_user - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ) as mock, patch("bookwyrm.lists_stream.remove_list_task.delay") as redis_mock: + with ( + patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ) as mock, + patch("bookwyrm.lists_stream.remove_list_task.delay") as redis_mock, + ): views.delete_list(request, self.list.id) self.assertTrue(redis_mock.called) activity = json.loads(mock.call_args[1]["args"][1]) diff --git a/bookwyrm/tests/views/lists/test_list_item.py b/bookwyrm/tests/views/lists/test_list_item.py index ebdbdbc2e..e265d7ef5 100644 --- a/bookwyrm/tests/views/lists/test_list_item.py +++ b/bookwyrm/tests/views/lists/test_list_item.py @@ -15,9 +15,11 @@ class ListItemViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -32,9 +34,10 @@ class ListItemViews(TestCase): remote_id="https://example.com/book/1", parent_work=work, ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): self.list = models.List.objects.create( name="Test List", user=self.local_user ) diff --git a/bookwyrm/tests/views/lists/test_lists.py b/bookwyrm/tests/views/lists/test_lists.py index 0d2213ee7..88ea71360 100644 --- a/bookwyrm/tests/views/lists/test_lists.py +++ b/bookwyrm/tests/views/lists/test_lists.py @@ -18,9 +18,11 @@ class ListViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -45,10 +47,10 @@ class ListViews(TestCase): def test_lists_page(self, _): """there are so many views, this just makes sure it LOADS""" view = views.Lists.as_view() - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.add_list_task.delay"), patch( - "bookwyrm.lists_stream.remove_list_task.delay" + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.add_list_task.delay"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), ): models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create( @@ -72,9 +74,10 @@ class ListViews(TestCase): def test_saved_lists_page(self): """there are so many views, this just makes sure it LOADS""" view = views.SavedLists.as_view() - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): booklist = models.List.objects.create( name="Public list", user=self.local_user ) @@ -94,9 +97,10 @@ class ListViews(TestCase): def test_saved_lists_page_empty(self): """there are so many views, this just makes sure it LOADS""" view = views.SavedLists.as_view() - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create( name="Private list", privacy="direct", user=self.local_user @@ -122,9 +126,10 @@ class ListViews(TestCase): def test_user_lists_page(self): """there are so many views, this just makes sure it LOADS""" view = views.UserLists.as_view() - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create( name="Private list", privacy="direct", user=self.local_user @@ -160,9 +165,12 @@ class ListViews(TestCase): }, ) request.user = self.local_user - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ) as mock, patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ) as mock, + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): result = view(request) self.assertEqual(mock.call_count, 1) diff --git a/bookwyrm/tests/views/preferences/test_block.py b/bookwyrm/tests/views/preferences/test_block.py index 86ef95e7e..bc39d2f62 100644 --- a/bookwyrm/tests/views/preferences/test_block.py +++ b/bookwyrm/tests/views/preferences/test_block.py @@ -16,9 +16,11 @@ class BlockViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -65,8 +67,9 @@ class BlockViews(TestCase): request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"), patch( - "bookwyrm.lists_stream.remove_user_lists_task.delay" + with ( + patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"), + patch("bookwyrm.lists_stream.remove_user_lists_task.delay"), ): view(request, self.remote_user.id) block = models.UserBlocks.objects.get() @@ -82,8 +85,9 @@ class BlockViews(TestCase): request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"), patch( - "bookwyrm.lists_stream.add_user_lists_task.delay" + with ( + patch("bookwyrm.activitystreams.add_user_statuses_task.delay"), + patch("bookwyrm.lists_stream.add_user_lists_task.delay"), ): views.unblock(request, self.remote_user.id) diff --git a/bookwyrm/tests/views/preferences/test_change_password.py b/bookwyrm/tests/views/preferences/test_change_password.py index 49eac998c..1717204bd 100644 --- a/bookwyrm/tests/views/preferences/test_change_password.py +++ b/bookwyrm/tests/views/preferences/test_change_password.py @@ -15,9 +15,11 @@ class ChangePasswordViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/preferences/test_delete_user.py b/bookwyrm/tests/views/preferences/test_delete_user.py index d97ef0d38..94d8c4a69 100644 --- a/bookwyrm/tests/views/preferences/test_delete_user.py +++ b/bookwyrm/tests/views/preferences/test_delete_user.py @@ -19,9 +19,11 @@ class DeleteUserViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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@your.domain.here", "mouse@mouse.mouse", @@ -40,9 +42,10 @@ class DeleteUserViews(TestCase): self.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), + ): models.ShelfBook.objects.create( book=self.book, user=self.local_user, diff --git a/bookwyrm/tests/views/preferences/test_edit_user.py b/bookwyrm/tests/views/preferences/test_edit_user.py index 1ed4e3240..4b83f3b80 100644 --- a/bookwyrm/tests/views/preferences/test_edit_user.py +++ b/bookwyrm/tests/views/preferences/test_edit_user.py @@ -21,9 +21,11 @@ class EditUserViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -38,9 +40,10 @@ class EditUserViews(TestCase): self.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), + ): models.ShelfBook.objects.create( book=self.book, user=self.local_user, diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 3f758b2f7..128b8fc8b 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -22,8 +22,9 @@ class ExportViews(TestCase): self, ): # pylint: disable=bad-classmethod-argument, disable=invalid-name """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), ): self.local_user = models.User.objects.create_user( "mouse@local.com", diff --git a/bookwyrm/tests/views/preferences/test_export_user.py b/bookwyrm/tests/views/preferences/test_export_user.py index 654ed2a05..57a7c2ca5 100644 --- a/bookwyrm/tests/views/preferences/test_export_user.py +++ b/bookwyrm/tests/views/preferences/test_export_user.py @@ -15,8 +15,9 @@ class ExportUserViews(TestCase): 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" + 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", diff --git a/bookwyrm/tests/views/preferences/test_two_factor_auth.py b/bookwyrm/tests/views/preferences/test_two_factor_auth.py index dbd9c1f5b..8eb5e92c7 100644 --- a/bookwyrm/tests/views/preferences/test_two_factor_auth.py +++ b/bookwyrm/tests/views/preferences/test_two_factor_auth.py @@ -20,9 +20,11 @@ class TwoFactorViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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@your.domain.here", "mouse@mouse.com", @@ -130,8 +132,9 @@ class TwoFactorViews(TestCase): request.session["2fa_user"] = self.local_user.username request.session.save() - with patch("bookwyrm.views.preferences.two_factor_auth.LoginWith2FA"), patch( - "bookwyrm.views.preferences.two_factor_auth.login" + with ( + patch("bookwyrm.views.preferences.two_factor_auth.LoginWith2FA"), + patch("bookwyrm.views.preferences.two_factor_auth.login"), ): result = view(request) self.assertEqual(result.url, "/") diff --git a/bookwyrm/tests/views/shelf/test_shelf.py b/bookwyrm/tests/views/shelf/test_shelf.py index b96d0a9ed..57631974f 100644 --- a/bookwyrm/tests/views/shelf/test_shelf.py +++ b/bookwyrm/tests/views/shelf/test_shelf.py @@ -23,9 +23,11 @@ class ShelfViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/shelf/test_shelf_actions.py b/bookwyrm/tests/views/shelf/test_shelf_actions.py index eea17b62d..ee5854d18 100644 --- a/bookwyrm/tests/views/shelf/test_shelf_actions.py +++ b/bookwyrm/tests/views/shelf/test_shelf_actions.py @@ -21,9 +21,11 @@ class ShelfActionViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_annual_summary.py b/bookwyrm/tests/views/test_annual_summary.py index d51060a72..2fd7dc4eb 100644 --- a/bookwyrm/tests/views/test_annual_summary.py +++ b/bookwyrm/tests/views/test_annual_summary.py @@ -24,9 +24,11 @@ class AnnualSummary(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index 669149af2..bee057d0c 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -19,9 +19,11 @@ class AuthorViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index 7e9e97522..e2bef539e 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -16,9 +16,11 @@ class DirectoryViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_discover.py b/bookwyrm/tests/views/test_discover.py index 9aa139074..937039592 100644 --- a/bookwyrm/tests/views/test_discover.py +++ b/bookwyrm/tests/views/test_discover.py @@ -14,9 +14,11 @@ class DiscoverViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index 33dbd4ea5..fb2609575 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -27,9 +27,11 @@ class FeedViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index e70ace769..61a0a82ce 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -21,9 +21,11 @@ class FollowViews(TestCase): def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" models.SiteSettings.objects.create() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -78,9 +80,11 @@ class FollowViews(TestCase): def test_handle_follow_local_manually_approves(self, *_): """send a follow request""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): rat = models.User.objects.create_user( "rat@local.com", "rat@rat.com", @@ -104,9 +108,11 @@ class FollowViews(TestCase): def test_handle_follow_local(self, *_): """send a follow request""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): rat = models.User.objects.create_user( "rat@local.com", "rat@rat.com", diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 84a49cafc..5d6aa8782 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -15,9 +15,11 @@ class GetStartedViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index 3d87d8538..49227457b 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -18,9 +18,11 @@ class GoalViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_group.py b/bookwyrm/tests/views/test_group.py index 4d678c31a..ca9284686 100644 --- a/bookwyrm/tests/views/test_group.py +++ b/bookwyrm/tests/views/test_group.py @@ -19,9 +19,11 @@ class GroupViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", diff --git a/bookwyrm/tests/views/test_hashtag.py b/bookwyrm/tests/views/test_hashtag.py index 1c8b31dce..5979238d8 100644 --- a/bookwyrm/tests/views/test_hashtag.py +++ b/bookwyrm/tests/views/test_hashtag.py @@ -16,9 +16,11 @@ class HashtagView(TestCase): @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"): + 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.com", @@ -53,9 +55,10 @@ class HashtagView(TestCase): ) self.hashtag_bookclub = models.Hashtag.objects.create(name="#BookClub") - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_status_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): self.statuses_bookclub = [ models.Comment.objects.create( book=self.book, user=self.local_user, content="#BookClub" @@ -91,9 +94,10 @@ class HashtagView(TestCase): request = self.factory.get("") hashtag = models.Hashtag.objects.create(name="#test") - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_status_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): status = models.Comment.objects.create( user=self.local_user, book=self.book, content="#test", privacy="direct" ) @@ -115,9 +119,10 @@ class HashtagView(TestCase): request = self.factory.get("") hashtag = models.Hashtag.objects.create(name="#test") - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_status_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): status = models.Comment.objects.create( user=self.local_user, book=self.book, @@ -143,9 +148,10 @@ class HashtagView(TestCase): request = self.factory.get("") hashtag = models.Hashtag.objects.create(name="#test") - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_status_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): status = models.Comment.objects.create( user=self.local_user, book=self.book, diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index 9472cf762..2f2481931 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -21,9 +21,11 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + with ( + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.populate_stream_task.delay"), + patch("bookwyrm.lists_stream.populate_lists_task.delay"), + ): with patch("bookwyrm.suggested_users.rerank_user_task.delay"): self.local_user = models.User.objects.create_user( "mouse@local.com", diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 1565b96a8..95d7b5791 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -15,9 +15,11 @@ class InteractionViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index ca451bef8..bb66c8f3e 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -17,9 +17,11 @@ class IsbnViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_notifications.py b/bookwyrm/tests/views/test_notifications.py index 8d239d77a..c44940742 100644 --- a/bookwyrm/tests/views/test_notifications.py +++ b/bookwyrm/tests/views/test_notifications.py @@ -15,9 +15,11 @@ class NotificationViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -148,9 +150,10 @@ class NotificationViews(TestCase): def test_notifications_page_list(self): """Adding books to lists""" book = models.Edition.objects.create(title="shape") - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): book_list = models.List.objects.create(user=self.local_user, name="hi") item = models.ListItem.objects.create( book=book, user=self.another_user, book_list=book_list, order=1 diff --git a/bookwyrm/tests/views/test_outbox.py b/bookwyrm/tests/views/test_outbox.py index 78c4d0edc..ca289db3f 100644 --- a/bookwyrm/tests/views/test_outbox.py +++ b/bookwyrm/tests/views/test_outbox.py @@ -18,9 +18,11 @@ class OutboxView(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we'll need some 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"): + 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.com", diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index fab1c1fc9..39c611d6c 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -18,9 +18,11 @@ class ReadingViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index 4f5b1e478..113b3161d 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -24,9 +24,11 @@ class ReadThrough(TestCase): title="Example Edition", parent_work=self.work ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.user = models.User.objects.create_user( "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" ) diff --git a/bookwyrm/tests/views/test_report.py b/bookwyrm/tests/views/test_report.py index 3e4c64f68..65670dcbf 100644 --- a/bookwyrm/tests/views/test_report.py +++ b/bookwyrm/tests/views/test_report.py @@ -14,9 +14,11 @@ class ReportViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -31,9 +33,10 @@ class ReportViews(TestCase): local=True, localname="rat", ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.activitystreams.add_status_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): self.status = models.Status.objects.create( user=self.local_user, content="Test status", diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index a63bdea94..af5ad5301 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -14,9 +14,11 @@ class RssFeedView(TestCase): @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"): + 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( "rss_user", "rss@test.rss", "password", local=True ) diff --git a/bookwyrm/tests/views/test_search.py b/bookwyrm/tests/views/test_search.py index 425b96cd3..5e06e6f81 100644 --- a/bookwyrm/tests/views/test_search.py +++ b/bookwyrm/tests/views/test_search.py @@ -20,9 +20,11 @@ class Views(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", @@ -164,9 +166,10 @@ class Views(TestCase): def test_search_lists(self): """searches remote connectors""" - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.lists_stream.remove_list_task.delay"): + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.lists_stream.remove_list_task.delay"), + ): booklist = models.List.objects.create( user=self.local_user, name="test list" ) diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 7b0c39338..f5fe515f1 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -19,9 +19,11 @@ class StatusTransactions(TransactionTestCase): 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"): + 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.com", @@ -77,9 +79,11 @@ class StatusViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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.com", diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index 37cb2e6c6..129aa8d71 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -15,9 +15,11 @@ class UpdateViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -54,11 +56,14 @@ class UpdateViews(TestCase): request = self.factory.get("") request.user = self.local_user - with patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count" - ) as mock_count, patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" - ) as mock_count_by_status: + with ( + patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count" + ) as mock_count, + patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" + ) as mock_count_by_status, + ): mock_count.return_value = 3 mock_count_by_status.return_value = {"review": 5} result = views.get_unread_status_string(request, "home") @@ -73,11 +78,14 @@ class UpdateViews(TestCase): request = self.factory.get("") request.user = self.local_user - with patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count" - ) as mock_count, patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" - ) as mock_count_by_status: + with ( + patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count" + ) as mock_count, + patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" + ) as mock_count_by_status, + ): mock_count.return_value = 3 mock_count_by_status.return_value = { "generated_note": 1, diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index d4e11ff2e..4b49f120e 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -18,9 +18,11 @@ class UserViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", @@ -34,10 +36,10 @@ class UserViews(TestCase): self.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) - with patch( - "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" - ), patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.add_book_statuses_task.delay" + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), + patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), ): models.ShelfBook.objects.create( book=self.book, diff --git a/bookwyrm/tests/views/test_wellknown.py b/bookwyrm/tests/views/test_wellknown.py index 4617942fa..d8bf0d062 100644 --- a/bookwyrm/tests/views/test_wellknown.py +++ b/bookwyrm/tests/views/test_wellknown.py @@ -16,9 +16,11 @@ class WellknownViews(TestCase): @classmethod def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): + 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", From 4b9fe0af0c811c90415d099fa2e6973fe25e9152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 17 Mar 2024 20:36:48 -0300 Subject: [PATCH 03/10] Remove nesting in several with..patch calls --- .../tests/activitypub/test_base_activity.py | 10 ++-- bookwyrm/tests/importers/test_importer.py | 8 ++-- .../tests/models/test_bookwyrm_import_job.py | 46 +++++++++---------- bookwyrm/tests/models/test_import_model.py | 18 ++++---- bookwyrm/tests/test_signing.py | 8 ++-- .../tests/views/inbox/test_inbox_announce.py | 16 ++++--- bookwyrm/tests/views/inbox/test_inbox_like.py | 16 ++++--- bookwyrm/tests/views/test_helpers.py | 46 ++++++++++--------- bookwyrm/tests/views/test_updates.py | 26 ++++------- 9 files changed, 100 insertions(+), 94 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index 8f2cd7fb2..735353452 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -234,10 +234,12 @@ class BaseActivity(TestCase): ) # sets the celery task call to the function call - with patch("bookwyrm.activitypub.base_activity.set_related_field.delay"): - with patch("bookwyrm.models.status.Status.ignore_activity") as discarder: - discarder.return_value = False - update_data.to_model(model=models.Status, instance=status) + with ( + patch("bookwyrm.activitypub.base_activity.set_related_field.delay"), + patch("bookwyrm.models.status.Status.ignore_activity") as discarder, + ): + discarder.return_value = False + update_data.to_model(model=models.Status, instance=status) self.assertIsNone(status.attachments.first()) @responses.activate diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index 494d28ad0..a18aedd51 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -268,9 +268,11 @@ class GenericImporter(TestCase): import_item.book = self.book import_item.save() - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - with patch("bookwyrm.models.Status.broadcast") as broadcast_mock: - handle_imported_book(import_item) + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.models.Status.broadcast") as broadcast_mock, + ): + handle_imported_book(import_item) kwargs = broadcast_mock.call_args.kwargs self.assertEqual(kwargs["software"], "bookwyrm") review = models.Review.objects.get(book=self.book, user=self.local_user) diff --git a/bookwyrm/tests/models/test_bookwyrm_import_job.py b/bookwyrm/tests/models/test_bookwyrm_import_job.py index 50c136f21..259d8f5a4 100644 --- a/bookwyrm/tests/models/test_bookwyrm_import_job.py +++ b/bookwyrm/tests/models/test_bookwyrm_import_job.py @@ -24,7 +24,6 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.lists_stream.populate_lists_task.delay"), patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): - self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", @@ -84,13 +83,13 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): - - with open(self.archive_file, "rb") as fileobj: - with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile: - - models.bookwyrm_import_job.update_user_profile( - self.local_user, tarfile, self.json_data - ) + with ( + open(self.archive_file, "rb") as fileobj, + BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile, + ): + models.bookwyrm_import_job.update_user_profile( + self.local_user, tarfile, self.json_data + ) self.local_user.refresh_from_db() @@ -111,7 +110,6 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): - models.bookwyrm_import_job.update_user_settings( self.local_user, self.json_data ) @@ -256,14 +254,15 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods self.assertEqual(models.Edition.objects.count(), 1) - with open(self.archive_file, "rb") as fileobj: - with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile: + with ( + open(self.archive_file, "rb") as fileobj, + BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile, + ): + bookwyrm_import_job.get_or_create_edition( + self.json_data["books"][1], tarfile + ) # Sand Talk - bookwyrm_import_job.get_or_create_edition( - self.json_data["books"][1], tarfile - ) # Sand Talk - - self.assertEqual(models.Edition.objects.count(), 1) + self.assertEqual(models.Edition.objects.count(), 1) def test_get_or_create_edition_not_existing(self): """Test take a JSON string of books and editions, @@ -272,12 +271,13 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods self.assertEqual(models.Edition.objects.count(), 1) - with open(self.archive_file, "rb") as fileobj: - with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile: - - bookwyrm_import_job.get_or_create_edition( - self.json_data["books"][0], tarfile - ) # Seeing like a state + with ( + open(self.archive_file, "rb") as fileobj, + BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile, + ): + bookwyrm_import_job.get_or_create_edition( + self.json_data["books"][0], tarfile + ) # Seeing like a state self.assertTrue(models.Edition.objects.filter(isbn_13="9780300070163").exists()) self.assertEqual(models.Edition.objects.count(), 2) @@ -326,7 +326,6 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True), ): - bookwyrm_import_job.upsert_statuses( self.local_user, models.Review, reviews, self.book.remote_id ) @@ -364,7 +363,6 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True), ): - bookwyrm_import_job.upsert_statuses( self.local_user, models.Comment, comments, self.book.remote_id ) diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index e5be01464..aa7b5b132 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -194,14 +194,16 @@ class ImportJob(TestCase): status=200, ) - with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"): - with patch( + with ( + patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"), + patch( "bookwyrm.connectors.connector_manager.first_search_result" - ) as search: - search.return_value = result - with patch( - "bookwyrm.connectors.openlibrary.Connector.get_authors_from_data" - ): - book = item.get_book_from_identifier() + ) as search, + ): + search.return_value = result + with patch( + "bookwyrm.connectors.openlibrary.Connector.get_authors_from_data" + ): + book = item.get_book_from_identifier() self.assertEqual(book.title, "Sabriel") diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index 80a35b94d..70f8e47cf 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -91,9 +91,11 @@ class Signature(TestCase): signature = make_signature( "post", signer or sender, self.rat.inbox, now, digest=digest ) - with patch("bookwyrm.views.inbox.activity_task.apply_async"): - with patch("bookwyrm.models.user.set_remote_server.delay"): - return self.send(signature, now, send_data or data, digest) + with ( + patch("bookwyrm.views.inbox.activity_task.apply_async"), + patch("bookwyrm.models.user.set_remote_server.delay"), + ): + return self.send(signature, now, send_data or data, digest) def test_correct_signature(self): """this one should just work""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index 53555f213..d982a91c8 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -39,13 +39,15 @@ class InboxActivities(TestCase): outbox="https://example.com/users/rat/outbox", ) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - with patch("bookwyrm.activitystreams.add_status_task.delay"): - self.status = models.Status.objects.create( - user=self.local_user, - content="Test status", - remote_id="https://example.com/status/1", - ) + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): + self.status = models.Status.objects.create( + user=self.local_user, + content="Test status", + remote_id="https://example.com/status/1", + ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index 4a397dcf8..4efe4cb98 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -38,13 +38,15 @@ class InboxActivities(TestCase): outbox="https://example.com/users/rat/outbox", ) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - with patch("bookwyrm.activitystreams.add_status_task.delay"): - self.status = models.Status.objects.create( - user=self.local_user, - content="Test status", - remote_id="https://example.com/status/1", - ) + with ( + patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), + patch("bookwyrm.activitystreams.add_status_task.delay"), + ): + self.status = models.Status.objects.create( + user=self.local_user, + content="Test status", + remote_id="https://example.com/status/1", + ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index 2f2481931..e00e1d234 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -25,29 +25,31 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), + patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): - with patch("bookwyrm.suggested_users.rerank_user_task.delay"): - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - discoverable=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - with patch("bookwyrm.suggested_users.rerank_user_task.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - discoverable=True, - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + discoverable=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) + with ( + patch("bookwyrm.models.user.set_remote_server.delay"), + patch("bookwyrm.suggested_users.rerank_user_task.delay"), + ): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + discoverable=True, + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Test Book", diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index 129aa8d71..6f826b46f 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -56,14 +56,11 @@ class UpdateViews(TestCase): request = self.factory.get("") request.user = self.local_user - with ( - patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count" - ) as mock_count, - patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" - ) as mock_count_by_status, - ): + with patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count" + ) as mock_count, patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" + ) as mock_count_by_status: mock_count.return_value = 3 mock_count_by_status.return_value = {"review": 5} result = views.get_unread_status_string(request, "home") @@ -78,14 +75,11 @@ class UpdateViews(TestCase): request = self.factory.get("") request.user = self.local_user - with ( - patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count" - ) as mock_count, - patch( - "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" - ) as mock_count_by_status, - ): + with patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count" + ) as mock_count, patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" + ) as mock_count_by_status: mock_count.return_value = 3 mock_count_by_status.return_value = { "generated_note": 1, From e2c9ea3cd27769814603790e580d44246f3b9fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 17 Mar 2024 20:52:20 -0300 Subject: [PATCH 04/10] Fix instances of `bad-classmethod-argument` in recently edited files --- .../tests/activitypub/test_base_activity.py | 8 +++--- bookwyrm/tests/activitypub/test_note.py | 10 +++---- .../activitystreams/test_abstractstream.py | 10 +++---- .../tests/activitystreams/test_booksstream.py | 8 +++--- .../tests/activitystreams/test_homestream.py | 8 +++--- .../tests/activitystreams/test_localstream.py | 10 +++---- .../tests/activitystreams/test_signals.py | 6 ++-- bookwyrm/tests/activitystreams/test_tasks.py | 14 ++++------ .../connectors/test_inventaire_connector.py | 2 +- .../tests/importers/test_calibre_import.py | 6 ++-- .../tests/importers/test_goodreads_import.py | 6 ++-- bookwyrm/tests/importers/test_importer.py | 6 ++-- .../importers/test_librarything_import.py | 6 ++-- .../importers/test_openlibrary_import.py | 6 ++-- .../tests/importers/test_storygraph_import.py | 6 ++-- bookwyrm/tests/lists_stream/test_signals.py | 8 +++--- bookwyrm/tests/lists_stream/test_stream.py | 10 +++---- bookwyrm/tests/lists_stream/test_tasks.py | 12 ++++---- .../management/test_populate_lists_streams.py | 10 +++---- .../tests/management/test_populate_streams.py | 10 +++---- .../tests/models/test_activitypub_mixin.py | 10 +++---- bookwyrm/tests/models/test_automod.py | 4 +-- bookwyrm/tests/models/test_base_model.py | 6 ++-- bookwyrm/tests/models/test_group.py | 28 +++++++++---------- bookwyrm/tests/models/test_import_model.py | 4 +-- bookwyrm/tests/models/test_list.py | 6 ++-- bookwyrm/tests/models/test_notification.py | 20 ++++++------- .../tests/models/test_readthrough_model.py | 10 +++---- .../tests/models/test_relationship_models.py | 10 +++---- bookwyrm/tests/models/test_shelf_model.py | 6 ++-- bookwyrm/tests/models/test_site.py | 4 +-- bookwyrm/tests/models/test_status_model.py | 8 +++--- bookwyrm/tests/models/test_user_model.py | 6 ++-- .../templatetags/test_book_display_tags.py | 6 ++-- .../tests/templatetags/test_feed_page_tags.py | 6 ++-- .../tests/templatetags/test_interaction.py | 8 +++--- .../test_notification_page_tags.py | 4 +-- .../tests/templatetags/test_rating_tags.py | 8 +++--- .../tests/templatetags/test_shelf_tags.py | 8 +++--- .../tests/templatetags/test_status_display.py | 8 +++--- bookwyrm/tests/templatetags/test_utilities.py | 10 +++---- bookwyrm/tests/test_context_processors.py | 10 +++---- bookwyrm/tests/test_emailing.py | 4 +-- bookwyrm/tests/test_signing.py | 8 +++--- .../tests/views/admin/test_announcements.py | 4 +-- bookwyrm/tests/views/admin/test_automod.py | 6 ++-- bookwyrm/tests/views/admin/test_celery.py | 6 ++-- bookwyrm/tests/views/admin/test_dashboard.py | 6 ++-- .../tests/views/admin/test_email_blocks.py | 6 ++-- .../tests/views/admin/test_email_config.py | 6 ++-- bookwyrm/tests/views/admin/test_federation.py | 8 +++--- bookwyrm/tests/views/admin/test_imports.py | 6 ++-- .../tests/views/admin/test_ip_blocklist.py | 6 ++-- .../tests/views/admin/test_link_domains.py | 12 ++++---- bookwyrm/tests/views/admin/test_reports.py | 8 +++--- bookwyrm/tests/views/admin/test_site.py | 8 +++--- bookwyrm/tests/views/admin/test_themes.py | 10 +++---- bookwyrm/tests/views/admin/test_user_admin.py | 6 ++-- bookwyrm/tests/views/books/test_book.py | 14 +++++----- bookwyrm/tests/views/books/test_edit_book.py | 14 +++++----- bookwyrm/tests/views/books/test_editions.py | 10 +++---- bookwyrm/tests/views/books/test_links.py | 12 ++++---- bookwyrm/tests/views/imports/test_import.py | 4 +-- .../tests/views/imports/test_import_review.py | 8 +++--- .../views/imports/test_import_troubleshoot.py | 4 +-- bookwyrm/tests/views/inbox/test_inbox.py | 4 +-- bookwyrm/tests/views/inbox/test_inbox_add.py | 6 ++-- .../tests/views/inbox/test_inbox_announce.py | 14 +++++----- .../tests/views/inbox/test_inbox_block.py | 10 +++---- .../tests/views/inbox/test_inbox_create.py | 10 +++---- .../tests/views/inbox/test_inbox_delete.py | 14 +++++----- .../tests/views/inbox/test_inbox_follow.py | 10 +++---- bookwyrm/tests/views/inbox/test_inbox_like.py | 14 +++++----- .../tests/views/inbox/test_inbox_remove.py | 16 +++++------ .../tests/views/inbox/test_inbox_update.py | 10 +++---- bookwyrm/tests/views/landing/test_invite.py | 4 +-- bookwyrm/tests/views/landing/test_landing.py | 4 +-- bookwyrm/tests/views/landing/test_login.py | 8 +++--- bookwyrm/tests/views/landing/test_password.py | 4 +-- bookwyrm/tests/views/landing/test_register.py | 6 ++-- bookwyrm/tests/views/lists/test_curate.py | 10 +++---- bookwyrm/tests/views/lists/test_embed.py | 10 +++---- bookwyrm/tests/views/lists/test_list.py | 18 ++++++------ bookwyrm/tests/views/lists/test_list_item.py | 10 +++---- bookwyrm/tests/views/lists/test_lists.py | 6 ++-- .../tests/views/preferences/test_block.py | 6 ++-- .../views/preferences/test_change_password.py | 4 +-- .../views/preferences/test_delete_user.py | 14 +++++----- .../tests/views/preferences/test_edit_user.py | 14 +++++----- .../tests/views/preferences/test_export.py | 12 ++++---- .../views/preferences/test_two_factor_auth.py | 4 +-- bookwyrm/tests/views/shelf/test_shelf.py | 14 +++++----- .../tests/views/shelf/test_shelf_actions.py | 16 +++++------ bookwyrm/tests/views/test_annual_summary.py | 10 +++---- bookwyrm/tests/views/test_author.py | 14 +++++----- bookwyrm/tests/views/test_directory.py | 4 +-- bookwyrm/tests/views/test_discover.py | 4 +-- bookwyrm/tests/views/test_feed.py | 8 +++--- bookwyrm/tests/views/test_follow.py | 16 +++++------ bookwyrm/tests/views/test_get_started.py | 8 +++--- bookwyrm/tests/views/test_goal.py | 8 +++--- bookwyrm/tests/views/test_group.py | 14 +++++----- bookwyrm/tests/views/test_hashtag.py | 26 ++++++++--------- bookwyrm/tests/views/test_helpers.py | 16 +++++------ bookwyrm/tests/views/test_interaction.py | 8 +++--- bookwyrm/tests/views/test_isbn.py | 10 +++---- bookwyrm/tests/views/test_notifications.py | 10 +++---- bookwyrm/tests/views/test_outbox.py | 6 ++-- bookwyrm/tests/views/test_reading.py | 12 ++++---- bookwyrm/tests/views/test_readthrough.py | 10 +++---- bookwyrm/tests/views/test_report.py | 10 +++---- bookwyrm/tests/views/test_rss_feed.py | 6 ++-- bookwyrm/tests/views/test_search.py | 10 +++---- bookwyrm/tests/views/test_status.py | 12 ++++---- bookwyrm/tests/views/test_updates.py | 4 +-- bookwyrm/tests/views/test_user.py | 14 +++++----- bookwyrm/tests/views/test_wellknown.py | 4 +-- 117 files changed, 515 insertions(+), 529 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index 735353452..b529f6ae5 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -29,18 +29,18 @@ class BaseActivity(TestCase): """the super class for model-linked activitypub dataclasses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we're probably going to re-use this so why copy/paste""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) - self.user.remote_id = "http://example.com/a/b" - self.user.save(broadcast=False, update_fields=["remote_id"]) + cls.user.remote_id = "http://example.com/a/b" + cls.user.save(broadcast=False, update_fields=["remote_id"]) def setUp(self): datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") diff --git a/bookwyrm/tests/activitypub/test_note.py b/bookwyrm/tests/activitypub/test_note.py index 65502c70a..33fc04d91 100644 --- a/bookwyrm/tests/activitypub/test_note.py +++ b/bookwyrm/tests/activitypub/test_note.py @@ -11,20 +11,20 @@ class Note(TestCase): """the model-linked ActivityPub dataclass for Note-based types""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create a shared user""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) - self.user.remote_id = "https://test-instance.org/user/critic" - self.user.save(broadcast=False, update_fields=["remote_id"]) + cls.user.remote_id = "https://test-instance.org/user/critic" + cls.user.save(broadcast=False, update_fields=["remote_id"]) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Test Edition", remote_id="http://book.com/book" ) diff --git a/bookwyrm/tests/activitystreams/test_abstractstream.py b/bookwyrm/tests/activitystreams/test_abstractstream.py index acdd5529c..3a95e2efa 100644 --- a/bookwyrm/tests/activitystreams/test_abstractstream.py +++ b/bookwyrm/tests/activitystreams/test_abstractstream.py @@ -16,17 +16,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """use a test csv""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -34,7 +34,7 @@ class Activitystreams(TestCase): localname="nutria", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -44,7 +44,7 @@ class Activitystreams(TestCase): outbox="https://example.com/users/rat/outbox", ) work = models.Work.objects.create(title="test work") - self.book = models.Edition.objects.create(title="test book", parent_work=work) + cls.book = models.Edition.objects.create(title="test book", parent_work=work) def setUp(self): """per-test setUp""" diff --git a/bookwyrm/tests/activitystreams/test_booksstream.py b/bookwyrm/tests/activitystreams/test_booksstream.py index eb61cc203..07a4c52f4 100644 --- a/bookwyrm/tests/activitystreams/test_booksstream.py +++ b/bookwyrm/tests/activitystreams/test_booksstream.py @@ -15,18 +15,18 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """use a test csv""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -36,7 +36,7 @@ class Activitystreams(TestCase): outbox="https://example.com/users/rat/outbox", ) work = models.Work.objects.create(title="test work") - self.book = models.Edition.objects.create(title="test book", parent_work=work) + cls.book = models.Edition.objects.create(title="test book", parent_work=work) def test_get_statuses_for_user_books(self, *_): """create a stream for a user""" diff --git a/bookwyrm/tests/activitystreams/test_homestream.py b/bookwyrm/tests/activitystreams/test_homestream.py index 0baf1d1b8..feadaab1b 100644 --- a/bookwyrm/tests/activitystreams/test_homestream.py +++ b/bookwyrm/tests/activitystreams/test_homestream.py @@ -13,17 +13,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """use a test csv""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -31,7 +31,7 @@ class Activitystreams(TestCase): localname="nutria", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/activitystreams/test_localstream.py b/bookwyrm/tests/activitystreams/test_localstream.py index 92ec2b069..508a289b2 100644 --- a/bookwyrm/tests/activitystreams/test_localstream.py +++ b/bookwyrm/tests/activitystreams/test_localstream.py @@ -13,17 +13,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """use a test csv""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -31,7 +31,7 @@ class Activitystreams(TestCase): localname="nutria", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -41,7 +41,7 @@ class Activitystreams(TestCase): outbox="https://example.com/users/rat/outbox", ) work = models.Work.objects.create(title="test work") - self.book = models.Edition.objects.create(title="test book", parent_work=work) + cls.book = models.Edition.objects.create(title="test book", parent_work=work) def test_localstream_get_audience_remote_status(self, *_): """get a list of users that should see a status""" diff --git a/bookwyrm/tests/activitystreams/test_signals.py b/bookwyrm/tests/activitystreams/test_signals.py index b9fb75ade..77ac68e71 100644 --- a/bookwyrm/tests/activitystreams/test_signals.py +++ b/bookwyrm/tests/activitystreams/test_signals.py @@ -15,18 +15,18 @@ class ActivitystreamsSignals(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """use a test csv""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/activitystreams/test_tasks.py b/bookwyrm/tests/activitystreams/test_tasks.py index cf2ee40e6..28bd68bf2 100644 --- a/bookwyrm/tests/activitystreams/test_tasks.py +++ b/bookwyrm/tests/activitystreams/test_tasks.py @@ -8,17 +8,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """use a test csv""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -26,7 +26,7 @@ class Activitystreams(TestCase): localname="nutria", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -36,11 +36,9 @@ class Activitystreams(TestCase): outbox="https://example.com/users/rat/outbox", ) work = models.Work.objects.create(title="test work") - self.book = models.Edition.objects.create(title="test book", parent_work=work) + cls.book = models.Edition.objects.create(title="test book", parent_work=work) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - self.status = models.Status.objects.create( - content="hi", user=self.local_user - ) + cls.status = models.Status.objects.create(content="hi", user=cls.local_user) def test_add_book_statuses_task(self): """statuses related to a book""" diff --git a/bookwyrm/tests/connectors/test_inventaire_connector.py b/bookwyrm/tests/connectors/test_inventaire_connector.py index 874d64862..7844f3919 100644 --- a/bookwyrm/tests/connectors/test_inventaire_connector.py +++ b/bookwyrm/tests/connectors/test_inventaire_connector.py @@ -15,7 +15,7 @@ class Inventaire(TestCase): """test loading data from inventaire.io""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """creates the connector in the database""" models.Connector.objects.create( identifier="inventaire.io", diff --git a/bookwyrm/tests/importers/test_calibre_import.py b/bookwyrm/tests/importers/test_calibre_import.py index 6bfa754af..dcbe68c64 100644 --- a/bookwyrm/tests/importers/test_calibre_import.py +++ b/bookwyrm/tests/importers/test_calibre_import.py @@ -23,19 +23,19 @@ class CalibreImport(TestCase): self.csv = open(datafile, "r", encoding=self.importer.encoding) @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """populate database""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) models.SiteSettings.objects.create() work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index deb41a1df..f0b67cffd 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -30,19 +30,19 @@ class GoodreadsImport(TestCase): self.csv = open(datafile, "r", encoding=self.importer.encoding) @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """populate database""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) models.SiteSettings.objects.create() work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index a18aedd51..ea10d0f53 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -33,19 +33,19 @@ class GenericImporter(TestCase): self.csv = open(datafile, "r", encoding=self.importer.encoding) @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """populate database""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) models.SiteSettings.objects.create() work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index ba86721de..280131115 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -32,19 +32,19 @@ class LibrarythingImport(TestCase): self.csv = open(datafile, "r", encoding=self.importer.encoding) @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """populate database""" 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( + cls.local_user = models.User.objects.create_user( "mmai", "mmai@mmai.mmai", "password", local=True ) models.SiteSettings.objects.create() work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/importers/test_openlibrary_import.py b/bookwyrm/tests/importers/test_openlibrary_import.py index e0e6135c9..05bab0cc2 100644 --- a/bookwyrm/tests/importers/test_openlibrary_import.py +++ b/bookwyrm/tests/importers/test_openlibrary_import.py @@ -30,19 +30,19 @@ class OpenLibraryImport(TestCase): self.csv = open(datafile, "r", encoding=self.importer.encoding) @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """populate database""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) models.SiteSettings.objects.create() work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/importers/test_storygraph_import.py b/bookwyrm/tests/importers/test_storygraph_import.py index 180cd8ad4..eee27010c 100644 --- a/bookwyrm/tests/importers/test_storygraph_import.py +++ b/bookwyrm/tests/importers/test_storygraph_import.py @@ -30,19 +30,19 @@ class StorygraphImport(TestCase): self.csv = open(datafile, "r", encoding=self.importer.encoding) @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """populate database""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) models.SiteSettings.objects.create() work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/lists_stream/test_signals.py b/bookwyrm/tests/lists_stream/test_signals.py index 923d19a2f..f9e7e4d12 100644 --- a/bookwyrm/tests/lists_stream/test_signals.py +++ b/bookwyrm/tests/lists_stream/test_signals.py @@ -9,21 +9,21 @@ class ListsStreamSignals(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """database setup""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "fish", "fish@fish.fish", "password", local=True, localname="fish" ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/lists_stream/test_stream.py b/bookwyrm/tests/lists_stream/test_stream.py index fcac04d19..5d752dd57 100644 --- a/bookwyrm/tests/lists_stream/test_stream.py +++ b/bookwyrm/tests/lists_stream/test_stream.py @@ -16,17 +16,17 @@ class ListsStream(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """database setup""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -34,7 +34,7 @@ class ListsStream(TestCase): localname="nutria", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -43,7 +43,7 @@ class ListsStream(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.stream = lists_stream.ListsStream() + cls.stream = lists_stream.ListsStream() def test_lists_stream_ids(self, *_): """the abstract base class for stream objects""" diff --git a/bookwyrm/tests/lists_stream/test_tasks.py b/bookwyrm/tests/lists_stream/test_tasks.py index fe3cb319d..a127d363c 100644 --- a/bookwyrm/tests/lists_stream/test_tasks.py +++ b/bookwyrm/tests/lists_stream/test_tasks.py @@ -11,17 +11,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """database setup""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -29,7 +29,7 @@ class Activitystreams(TestCase): localname="nutria", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -42,8 +42,8 @@ class Activitystreams(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.lists_stream.remove_list_task.delay"), ): - self.list = models.List.objects.create( - user=self.local_user, name="hi", privacy="public" + cls.list = models.List.objects.create( + user=cls.local_user, name="hi", privacy="public" ) def test_populate_lists_task(self, *_): diff --git a/bookwyrm/tests/management/test_populate_lists_streams.py b/bookwyrm/tests/management/test_populate_lists_streams.py index f098c2b11..011011903 100644 --- a/bookwyrm/tests/management/test_populate_lists_streams.py +++ b/bookwyrm/tests/management/test_populate_lists_streams.py @@ -13,17 +13,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need some stuff""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -39,7 +39,7 @@ class Activitystreams(TestCase): is_active=False, ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -48,7 +48,7 @@ class Activitystreams(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.book = models.Edition.objects.create(title="test book") + cls.book = models.Edition.objects.create(title="test book") def test_populate_streams(self, *_): """make sure the function on the redis manager gets called""" diff --git a/bookwyrm/tests/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index 034222b29..c5b745c08 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -11,17 +11,17 @@ class Activitystreams(TestCase): """using redis to build activity streams""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need some stuff""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria", "nutria@nutria.nutria", "password", @@ -37,7 +37,7 @@ class Activitystreams(TestCase): is_active=False, ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -46,7 +46,7 @@ class Activitystreams(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.book = models.Edition.objects.create(title="test book") + cls.book = models.Edition.objects.create(title="test book") def test_populate_streams(self, _): """make sure the function on the redis manager gets called""" diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index b59088f91..c7949cd28 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -27,20 +27,20 @@ class ActivitypubMixins(TestCase): """functionality shared across models""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """shared 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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) - self.local_user.remote_id = "http://example.com/a/b" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "http://example.com/a/b" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/models/test_automod.py b/bookwyrm/tests/models/test_automod.py index ed3133cdc..5e10eb4d0 100644 --- a/bookwyrm/tests/models/test_automod.py +++ b/bookwyrm/tests/models/test_automod.py @@ -15,14 +15,14 @@ class AutomodModel(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index d0e441cef..d666b0e46 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -13,18 +13,18 @@ class BaseModel(TestCase): """functionality shared across models""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """shared 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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/models/test_group.py b/bookwyrm/tests/models/test_group.py index 3ea424333..2c2960ac4 100644 --- a/bookwyrm/tests/models/test_group.py +++ b/bookwyrm/tests/models/test_group.py @@ -10,7 +10,7 @@ class Group(TestCase): """some activitypub oddness ahead""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """Set up for tests""" with ( @@ -18,15 +18,15 @@ class Group(TestCase): patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), ): - self.owner_user = models.User.objects.create_user( + cls.owner_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", local=True, localname="rat" ) - self.badger = models.User.objects.create_user( + cls.badger = models.User.objects.create_user( "badger", "badger@badger.badger", "badgerword", @@ -34,7 +34,7 @@ class Group(TestCase): localname="badger", ) - self.capybara = models.User.objects.create_user( + cls.capybara = models.User.objects.create_user( "capybara", "capybara@capybara.capybara", "capybaraword", @@ -42,32 +42,32 @@ class Group(TestCase): localname="capybara", ) - self.public_group = models.Group.objects.create( + cls.public_group = models.Group.objects.create( name="Public Group", description="Initial description", - user=self.owner_user, + user=cls.owner_user, privacy="public", ) - self.private_group = models.Group.objects.create( + cls.private_group = models.Group.objects.create( name="Private Group", description="Top secret", - user=self.owner_user, + user=cls.owner_user, privacy="direct", ) - self.followers_only_group = models.Group.objects.create( + cls.followers_only_group = models.Group.objects.create( name="Followers Group", description="No strangers", - user=self.owner_user, + user=cls.owner_user, privacy="followers", ) - models.GroupMember.objects.create(group=self.private_group, user=self.badger) + models.GroupMember.objects.create(group=cls.private_group, user=cls.badger) models.GroupMember.objects.create( - group=self.followers_only_group, user=self.badger + group=cls.followers_only_group, user=cls.badger ) - models.GroupMember.objects.create(group=self.public_group, user=self.capybara) + models.GroupMember.objects.create(group=cls.public_group, user=cls.capybara) def test_group_members_can_see_private_groups(self, _): """direct privacy group should not be excluded from group listings for group diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index aa7b5b132..e591c33e8 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -17,14 +17,14 @@ class ImportJob(TestCase): """this is a fancy one!!!""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """data is from a goodreads export of The Raven Tower""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/models/test_list.py b/bookwyrm/tests/models/test_list.py index b1b756cab..b9148853b 100644 --- a/bookwyrm/tests/models/test_list.py +++ b/bookwyrm/tests/models/test_list.py @@ -12,18 +12,18 @@ class List(TestCase): """some activitypub oddness ahead""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """look, a list""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) work = models.Work.objects.create(title="hello") - self.book = models.Edition.objects.create(title="hi", parent_work=work) + cls.book = models.Edition.objects.create(title="hi", parent_work=work) def test_remote_id(self, *_): """shelves use custom remote ids""" diff --git a/bookwyrm/tests/models/test_notification.py b/bookwyrm/tests/models/test_notification.py index a9ed8b661..976ac39c9 100644 --- a/bookwyrm/tests/models/test_notification.py +++ b/bookwyrm/tests/models/test_notification.py @@ -8,21 +8,21 @@ class Notification(TestCase): """let people know things""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """useful things for creating a notification""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", local=True, localname="rat" ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -31,14 +31,14 @@ class Notification(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Test Book", isbn_13="1234567890123", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) - self.another_book = models.Edition.objects.create( + cls.another_book = models.Edition.objects.create( title="Second Test Book", parent_work=models.Work.objects.create(title="Test Work"), ) @@ -201,14 +201,14 @@ class NotifyInviteRequest(TestCase): """let admins know of invite requests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """ensure there is one admin""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/models/test_readthrough_model.py b/bookwyrm/tests/models/test_readthrough_model.py index 0da87f67b..239537df4 100644 --- a/bookwyrm/tests/models/test_readthrough_model.py +++ b/bookwyrm/tests/models/test_readthrough_model.py @@ -12,20 +12,20 @@ class ReadThrough(TestCase): """some activitypub oddness ahead""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """look, a shelf""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) - self.work = models.Work.objects.create(title="Example Work") - self.edition = models.Edition.objects.create( - title="Example Edition", parent_work=self.work + cls.work = models.Work.objects.create(title="Example Work") + cls.edition = models.Edition.objects.create( + title="Example Edition", parent_work=cls.work ) def test_valid_date(self): diff --git a/bookwyrm/tests/models/test_relationship_models.py b/bookwyrm/tests/models/test_relationship_models.py index dbb0ac8bb..ec9f751a4 100644 --- a/bookwyrm/tests/models/test_relationship_models.py +++ b/bookwyrm/tests/models/test_relationship_models.py @@ -15,10 +15,10 @@ class Relationship(TestCase): """following, blocking, stuff like that""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need some users for this""" with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -32,11 +32,11 @@ class Relationship(TestCase): patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) - self.local_user.remote_id = "http://local.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "http://local.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) def test_user_follows(self, *_): """basic functionality of user follows""" diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 2d45dadbc..022cb5c61 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -16,18 +16,18 @@ class Shelf(TestCase): """some activitypub oddness ahead""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """look, a shelf""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create(title="test book", parent_work=work) + cls.book = models.Edition.objects.create(title="test book", parent_work=work) def test_remote_id(self, *_): """shelves use custom remote ids""" diff --git a/bookwyrm/tests/models/test_site.py b/bookwyrm/tests/models/test_site.py index 8cf15ad6f..0933dac0c 100644 --- a/bookwyrm/tests/models/test_site.py +++ b/bookwyrm/tests/models/test_site.py @@ -13,14 +13,14 @@ class SiteModels(TestCase): """tests for site models""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 32ccc2c57..bd2853595 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -25,18 +25,18 @@ class Status(TestCase): """lotta types of statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """useful things for creating a status""" 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( + cls.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -45,7 +45,7 @@ class Status(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.book = models.Edition.objects.create(title="Test Edition") + cls.book = models.Edition.objects.create(title="Test Edition") def setUp(self): """individual test setup""" diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index a47896269..22c7a171b 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -19,13 +19,13 @@ class User(TestCase): protocol = "https://" if USE_HTTPS else "http://" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( f"mouse@{DOMAIN}", "mouse@mouse.mouse", "mouseword", @@ -35,7 +35,7 @@ class User(TestCase): summary="a summary", bookwyrm_user=False, ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( f"nutria@{DOMAIN}", "nutria@nutria.nutria", "nutriaword", diff --git a/bookwyrm/tests/templatetags/test_book_display_tags.py b/bookwyrm/tests/templatetags/test_book_display_tags.py index 77d6fee54..40fa0f7d6 100644 --- a/bookwyrm/tests/templatetags/test_book_display_tags.py +++ b/bookwyrm/tests/templatetags/test_book_display_tags.py @@ -14,21 +14,21 @@ class BookDisplayTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse", ) - self.book = models.Edition.objects.create(title="Test Book") + cls.book = models.Edition.objects.create(title="Test Book") def test_get_book_description(self, *_): """grab it from the edition or the parent""" diff --git a/bookwyrm/tests/templatetags/test_feed_page_tags.py b/bookwyrm/tests/templatetags/test_feed_page_tags.py index 891bfc32c..7e3ba6a9f 100644 --- a/bookwyrm/tests/templatetags/test_feed_page_tags.py +++ b/bookwyrm/tests/templatetags/test_feed_page_tags.py @@ -13,21 +13,21 @@ class FeedPageTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse", ) - self.book = models.Edition.objects.create(title="Test Book") + cls.book = models.Edition.objects.create(title="Test Book") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") def test_load_subclass(self, *_): diff --git a/bookwyrm/tests/templatetags/test_interaction.py b/bookwyrm/tests/templatetags/test_interaction.py index bd66575ff..6d707ffac 100644 --- a/bookwyrm/tests/templatetags/test_interaction.py +++ b/bookwyrm/tests/templatetags/test_interaction.py @@ -13,14 +13,14 @@ class InteractionTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", @@ -28,14 +28,14 @@ class InteractionTags(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", remote_id="http://example.com/rat", local=False, ) - self.book = models.Edition.objects.create(title="Test Book") + cls.book = models.Edition.objects.create(title="Test Book") def test_get_user_liked(self, *_): """did a user like a status""" diff --git a/bookwyrm/tests/templatetags/test_notification_page_tags.py b/bookwyrm/tests/templatetags/test_notification_page_tags.py index df2805828..2d18a5ca7 100644 --- a/bookwyrm/tests/templatetags/test_notification_page_tags.py +++ b/bookwyrm/tests/templatetags/test_notification_page_tags.py @@ -13,14 +13,14 @@ class NotificationPageTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", diff --git a/bookwyrm/tests/templatetags/test_rating_tags.py b/bookwyrm/tests/templatetags/test_rating_tags.py index f50236262..cb28fd788 100644 --- a/bookwyrm/tests/templatetags/test_rating_tags.py +++ b/bookwyrm/tests/templatetags/test_rating_tags.py @@ -13,14 +13,14 @@ class RatingTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", @@ -28,7 +28,7 @@ class RatingTags(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", @@ -36,7 +36,7 @@ class RatingTags(TestCase): local=False, ) work = models.Work.objects.create(title="Work title") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Test Book", parent_work=work, ) diff --git a/bookwyrm/tests/templatetags/test_shelf_tags.py b/bookwyrm/tests/templatetags/test_shelf_tags.py index 47e86d9ef..8b3ec82d1 100644 --- a/bookwyrm/tests/templatetags/test_shelf_tags.py +++ b/bookwyrm/tests/templatetags/test_shelf_tags.py @@ -16,14 +16,14 @@ class ShelfTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", @@ -31,14 +31,14 @@ class ShelfTags(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", remote_id="http://example.com/rat", local=False, ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Test Book", parent_work=models.Work.objects.create(title="Test work"), ) diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index af125fd06..762f14ea8 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -15,14 +15,14 @@ class StatusDisplayTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", @@ -30,14 +30,14 @@ class StatusDisplayTags(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", remote_id="http://example.com/rat", local=False, ) - self.book = models.Edition.objects.create(title="Test Book") + cls.book = models.Edition.objects.create(title="Test Book") def test_get_mentions(self, *_): """list of people mentioned""" diff --git a/bookwyrm/tests/templatetags/test_utilities.py b/bookwyrm/tests/templatetags/test_utilities.py index 6fade22a7..bfd4f41ae 100644 --- a/bookwyrm/tests/templatetags/test_utilities.py +++ b/bookwyrm/tests/templatetags/test_utilities.py @@ -15,14 +15,14 @@ class UtilitiesTags(TestCase): """lotta different things here""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create some filler objects""" 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.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", "mouseword", @@ -30,15 +30,15 @@ class UtilitiesTags(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", remote_id="http://example.com/rat", local=False, ) - self.author = models.Author.objects.create(name="Jessica", isni="4") - self.book = models.Edition.objects.create(title="Test Book") + cls.author = models.Author.objects.create(name="Jessica", isni="4") + cls.book = models.Edition.objects.create(title="Test Book") def test_get_uuid(self, *_): """uuid functionality""" diff --git a/bookwyrm/tests/test_context_processors.py b/bookwyrm/tests/test_context_processors.py index e5290f312..7a58b05d8 100644 --- a/bookwyrm/tests/test_context_processors.py +++ b/bookwyrm/tests/test_context_processors.py @@ -12,23 +12,23 @@ class ContextProcessor(TestCase): """pages you land on without really trying""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False - self.site = models.SiteSettings.objects.create() + cls.anonymous_user = AnonymousUser + cls.anonymous_user.is_authenticated = False + cls.site = models.SiteSettings.objects.create() def setUp(self): """other test data""" diff --git a/bookwyrm/tests/test_emailing.py b/bookwyrm/tests/test_emailing.py index 8a5b543d5..c507a059f 100644 --- a/bookwyrm/tests/test_emailing.py +++ b/bookwyrm/tests/test_emailing.py @@ -12,14 +12,14 @@ class Emailing(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index 70f8e47cf..e41548bcf 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -36,24 +36,24 @@ class Signature(TestCase): """signature test""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create users and test 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"), ): - self.mouse = models.User.objects.create_user( + cls.mouse = models.User.objects.create_user( f"mouse@{DOMAIN}", "mouse@example.com", "", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( f"rat@{DOMAIN}", "rat@example.com", "", local=True, localname="rat" ) - self.cat = models.User.objects.create_user( + cls.cat = models.User.objects.create_user( f"cat@{DOMAIN}", "cat@example.com", "", local=True, localname="cat" ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/admin/test_announcements.py b/bookwyrm/tests/views/admin/test_announcements.py index 958d78fc4..62fb86d16 100644 --- a/bookwyrm/tests/views/admin/test_announcements.py +++ b/bookwyrm/tests/views/admin/test_announcements.py @@ -12,14 +12,14 @@ class AnnouncementViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/admin/test_automod.py b/bookwyrm/tests/views/admin/test_automod.py index 332410eba..27f98163e 100644 --- a/bookwyrm/tests/views/admin/test_automod.py +++ b/bookwyrm/tests/views/admin/test_automod.py @@ -16,14 +16,14 @@ class AutomodViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -33,7 +33,7 @@ class AutomodViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/admin/test_celery.py b/bookwyrm/tests/views/admin/test_celery.py index 577d312b1..513d69944 100644 --- a/bookwyrm/tests/views/admin/test_celery.py +++ b/bookwyrm/tests/views/admin/test_celery.py @@ -15,14 +15,14 @@ class CeleryStatusViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,7 +32,7 @@ class CeleryStatusViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="admin") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/admin/test_dashboard.py b/bookwyrm/tests/views/admin/test_dashboard.py index a68b046e3..35fcb25a4 100644 --- a/bookwyrm/tests/views/admin/test_dashboard.py +++ b/bookwyrm/tests/views/admin/test_dashboard.py @@ -15,14 +15,14 @@ class DashboardViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,7 +32,7 @@ class DashboardViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/admin/test_email_blocks.py b/bookwyrm/tests/views/admin/test_email_blocks.py index b37166d3c..08a131c3a 100644 --- a/bookwyrm/tests/views/admin/test_email_blocks.py +++ b/bookwyrm/tests/views/admin/test_email_blocks.py @@ -15,14 +15,14 @@ class EmailBlocklistViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,7 +32,7 @@ class EmailBlocklistViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/admin/test_email_config.py b/bookwyrm/tests/views/admin/test_email_config.py index 374c2402e..22f4b7a05 100644 --- a/bookwyrm/tests/views/admin/test_email_config.py +++ b/bookwyrm/tests/views/admin/test_email_config.py @@ -15,14 +15,14 @@ class EmailConfigViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,7 +32,7 @@ class EmailConfigViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="admin") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/admin/test_federation.py b/bookwyrm/tests/views/admin/test_federation.py index 8244e8335..1d0012dde 100644 --- a/bookwyrm/tests/views/admin/test_federation.py +++ b/bookwyrm/tests/views/admin/test_federation.py @@ -18,14 +18,14 @@ class FederationViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -33,7 +33,7 @@ class FederationViews(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -45,7 +45,7 @@ class FederationViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/admin/test_imports.py b/bookwyrm/tests/views/admin/test_imports.py index acb769546..211407ff6 100644 --- a/bookwyrm/tests/views/admin/test_imports.py +++ b/bookwyrm/tests/views/admin/test_imports.py @@ -15,14 +15,14 @@ class ImportsAdminViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,7 +32,7 @@ class ImportsAdminViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="admin") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/admin/test_ip_blocklist.py b/bookwyrm/tests/views/admin/test_ip_blocklist.py index b34828622..491915eda 100644 --- a/bookwyrm/tests/views/admin/test_ip_blocklist.py +++ b/bookwyrm/tests/views/admin/test_ip_blocklist.py @@ -15,14 +15,14 @@ class IPBlocklistViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,7 +32,7 @@ class IPBlocklistViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/admin/test_link_domains.py b/bookwyrm/tests/views/admin/test_link_domains.py index fabb7511a..20d28896f 100644 --- a/bookwyrm/tests/views/admin/test_link_domains.py +++ b/bookwyrm/tests/views/admin/test_link_domains.py @@ -15,14 +15,14 @@ class LinkDomainViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,13 +32,13 @@ class LinkDomainViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) - self.book = models.Edition.objects.create(title="hello") + cls.book = models.Edition.objects.create(title="hello") models.FileLink.objects.create( - book=self.book, + book=cls.book, url="https://beep.com/book/1", - added_by=self.local_user, + added_by=cls.local_user, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/admin/test_reports.py b/bookwyrm/tests/views/admin/test_reports.py index 7ce665451..146e40a9b 100644 --- a/bookwyrm/tests/views/admin/test_reports.py +++ b/bookwyrm/tests/views/admin/test_reports.py @@ -16,21 +16,21 @@ class ReportViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@mouse.mouse", "password", @@ -40,7 +40,7 @@ class ReportViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/admin/test_site.py b/bookwyrm/tests/views/admin/test_site.py index ec5b07e3a..277bfbc85 100644 --- a/bookwyrm/tests/views/admin/test_site.py +++ b/bookwyrm/tests/views/admin/test_site.py @@ -15,14 +15,14 @@ class SiteSettingsViews(TestCase): """Edit site settings""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -32,9 +32,9 @@ class SiteSettingsViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="admin") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) - self.site = models.SiteSettings.objects.create() + cls.site = models.SiteSettings.objects.create() def setUp(self): """individual test setup""" diff --git a/bookwyrm/tests/views/admin/test_themes.py b/bookwyrm/tests/views/admin/test_themes.py index b931ea561..af46bf060 100644 --- a/bookwyrm/tests/views/admin/test_themes.py +++ b/bookwyrm/tests/views/admin/test_themes.py @@ -16,21 +16,21 @@ class AdminThemesViews(TestCase): """Edit site settings""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", @@ -40,9 +40,9 @@ class AdminThemesViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="admin") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) - self.site = models.SiteSettings.objects.create() + cls.site = models.SiteSettings.objects.create() def setUp(self): """individual test setup""" diff --git a/bookwyrm/tests/views/admin/test_user_admin.py b/bookwyrm/tests/views/admin/test_user_admin.py index 5247ff70f..48fd7202e 100644 --- a/bookwyrm/tests/views/admin/test_user_admin.py +++ b/bookwyrm/tests/views/admin/test_user_admin.py @@ -16,14 +16,14 @@ class UserAdminViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -33,7 +33,7 @@ class UserAdminViews(TestCase): initdb.init_groups() initdb.init_permissions() group = Group.objects.get(name="moderator") - self.local_user.groups.set([group]) + cls.local_user.groups.set([group]) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/books/test_book.py b/bookwyrm/tests/views/books/test_book.py index 68a114fb9..cb66811a1 100644 --- a/bookwyrm/tests/views/books/test_book.py +++ b/bookwyrm/tests/views/books/test_book.py @@ -24,14 +24,14 @@ class BookViews(TestCase): """books books books""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -39,19 +39,19 @@ class BookViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.group = Group.objects.create(name="editor") - self.group.permissions.add( + cls.group = Group.objects.create(name="editor") + cls.group.permissions.add( Permission.objects.create( name="edit_book", codename="edit_book", content_type=ContentType.objects.get_for_model(models.User), ).id ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/books/test_edit_book.py b/bookwyrm/tests/views/books/test_edit_book.py index 0bd962de5..05a4d68ac 100644 --- a/bookwyrm/tests/views/books/test_edit_book.py +++ b/bookwyrm/tests/views/books/test_edit_book.py @@ -20,14 +20,14 @@ class EditBookViews(TestCase): """books books books""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -35,19 +35,19 @@ class EditBookViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.group = Group.objects.create(name="editor") - self.group.permissions.add( + cls.group = Group.objects.create(name="editor") + cls.group.permissions.add( Permission.objects.create( name="edit_book", codename="edit_book", content_type=ContentType.objects.get_for_model(models.User), ).id ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/books/test_editions.py b/bookwyrm/tests/views/books/test_editions.py index b829d471b..ef7404e51 100644 --- a/bookwyrm/tests/views/books/test_editions.py +++ b/bookwyrm/tests/views/books/test_editions.py @@ -14,14 +14,14 @@ class BookViews(TestCase): """books books books""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -29,11 +29,11 @@ class BookViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, physical_format="paperback", ) diff --git a/bookwyrm/tests/views/books/test_links.py b/bookwyrm/tests/views/books/test_links.py index d1040a591..299dea484 100644 --- a/bookwyrm/tests/views/books/test_links.py +++ b/bookwyrm/tests/views/books/test_links.py @@ -16,13 +16,13 @@ class LinkViews(TestCase): """books books books""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" with ( patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch("bookwyrm.activitystreams.populate_stream_task.delay"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -38,13 +38,13 @@ class LinkViews(TestCase): content_type=ContentType.objects.get_for_model(models.User), ).id ) - self.local_user.groups.add(group) + cls.local_user.groups.add(group) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/imports/test_import.py b/bookwyrm/tests/views/imports/test_import.py index c3b2795b1..658d95a33 100644 --- a/bookwyrm/tests/views/imports/test_import.py +++ b/bookwyrm/tests/views/imports/test_import.py @@ -17,14 +17,14 @@ class ImportViews(TestCase): """goodreads import views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/imports/test_import_review.py b/bookwyrm/tests/views/imports/test_import_review.py index 5da02a56a..026efac11 100644 --- a/bookwyrm/tests/views/imports/test_import_review.py +++ b/bookwyrm/tests/views/imports/test_import_review.py @@ -12,14 +12,14 @@ class ImportManualReviewViews(TestCase): """goodreads import views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -27,10 +27,10 @@ class ImportManualReviewViews(TestCase): localname="mouse", ) models.SiteSettings.objects.create() - self.job = models.ImportJob.objects.create(user=self.local_user, mappings={}) + cls.job = models.ImportJob.objects.create(user=cls.local_user, mappings={}) work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/views/imports/test_import_troubleshoot.py b/bookwyrm/tests/views/imports/test_import_troubleshoot.py index 9ddc99785..2e76da373 100644 --- a/bookwyrm/tests/views/imports/test_import_troubleshoot.py +++ b/bookwyrm/tests/views/imports/test_import_troubleshoot.py @@ -13,14 +13,14 @@ class ImportTroubleshootViews(TestCase): """goodreads import views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py index af85e84d4..92ee8a43d 100644 --- a/bookwyrm/tests/views/inbox/test_inbox.py +++ b/bookwyrm/tests/views/inbox/test_inbox.py @@ -29,7 +29,7 @@ class Inbox(TestCase): } @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """basic user and book data""" with ( patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), @@ -46,7 +46,7 @@ class Inbox(TestCase): local_user.remote_id = "https://example.com/user/mouse" local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/views/inbox/test_inbox_add.py b/bookwyrm/tests/views/inbox/test_inbox_add.py index 2bd5faf6a..0a11053e4 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_add.py +++ b/bookwyrm/tests/views/inbox/test_inbox_add.py @@ -12,7 +12,7 @@ class InboxAdd(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """basic user and book data""" with ( patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), @@ -29,7 +29,7 @@ class InboxAdd(TestCase): local_user.remote_id = "https://example.com/user/mouse" local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -40,7 +40,7 @@ class InboxAdd(TestCase): ) work = models.Work.objects.create(title="work title") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Test", remote_id="https://example.com/book/37292", parent_work=work, diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index d982a91c8..d499629a7 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -12,24 +12,24 @@ class InboxActivities(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -43,8 +43,8 @@ class InboxActivities(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.activitystreams.add_status_task.delay"), ): - self.status = models.Status.objects.create( - user=self.local_user, + cls.status = models.Status.objects.create( + user=cls.local_user, content="Test status", remote_id="https://example.com/status/1", ) diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index 9cdf7eba3..19b0eb97f 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -11,24 +11,24 @@ class InboxBlock(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index 7f5be5b65..e8a3a8b12 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -74,24 +74,24 @@ class InboxCreate(TestCase): """readthrough tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 9c2b589e2..a72898857 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -12,24 +12,24 @@ class InboxActivities(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -39,8 +39,8 @@ class InboxActivities(TestCase): outbox="https://example.com/users/rat/outbox", ) with patch("bookwyrm.activitystreams.add_status_task.delay"): - self.status = models.Status.objects.create( - user=self.remote_user, + cls.status = models.Status.objects.create( + user=cls.remote_user, content="Test status", remote_id="https://example.com/status/1", ) diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index 8ccffe1db..aad52937b 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -12,24 +12,24 @@ class InboxRelationships(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index 4efe4cb98..2ab8c4701 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -11,24 +11,24 @@ class InboxActivities(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -42,8 +42,8 @@ class InboxActivities(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.activitystreams.add_status_task.delay"), ): - self.status = models.Status.objects.create( - user=self.local_user, + cls.status = models.Status.objects.create( + user=cls.local_user, content="Test status", remote_id="https://example.com/status/1", ) diff --git a/bookwyrm/tests/views/inbox/test_inbox_remove.py b/bookwyrm/tests/views/inbox/test_inbox_remove.py index f0be2b17a..ab92eb995 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_remove.py +++ b/bookwyrm/tests/views/inbox/test_inbox_remove.py @@ -11,24 +11,24 @@ class InboxRemove(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -38,11 +38,11 @@ class InboxRemove(TestCase): outbox="https://example.com/users/rat/outbox", ) - self.work = models.Work.objects.create(title="work title") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="work title") + cls.book = models.Edition.objects.create( title="Test", remote_id="https://bookwyrm.social/book/37292", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index fb2c85a88..99f4c2077 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -13,24 +13,24 @@ class InboxUpdate(TestCase): """inbox tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", "mouseword", local=True, localname="mouse", ) - self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False, update_fields=["remote_id"]) + cls.local_user.remote_id = "https://example.com/user/mouse" + cls.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/views/landing/test_invite.py b/bookwyrm/tests/views/landing/test_invite.py index 5a76f578b..8adc64f4f 100644 --- a/bookwyrm/tests/views/landing/test_invite.py +++ b/bookwyrm/tests/views/landing/test_invite.py @@ -15,14 +15,14 @@ class InviteViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/landing/test_landing.py b/bookwyrm/tests/views/landing/test_landing.py index c0581d893..c68c9cd53 100644 --- a/bookwyrm/tests/views/landing/test_landing.py +++ b/bookwyrm/tests/views/landing/test_landing.py @@ -15,14 +15,14 @@ class LandingViews(TestCase): """pages you land on without really trying""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/landing/test_login.py b/bookwyrm/tests/views/landing/test_login.py index 283890e3e..7d4a06612 100644 --- a/bookwyrm/tests/views/landing/test_login.py +++ b/bookwyrm/tests/views/landing/test_login.py @@ -18,14 +18,14 @@ class LoginViews(TestCase): """login and password management""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@your.domain.here", "mouse@mouse.com", "password", @@ -33,14 +33,14 @@ class LoginViews(TestCase): localname="mouse", two_factor_auth=False, ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@your.domain.here", "rat@rat.com", "password", local=True, localname="rat", ) - self.badger = models.User.objects.create_user( + cls.badger = models.User.objects.create_user( "badger@your.domain.here", "badger@badger.com", "password", diff --git a/bookwyrm/tests/views/landing/test_password.py b/bookwyrm/tests/views/landing/test_password.py index 8f322b3cb..ad3110b02 100644 --- a/bookwyrm/tests/views/landing/test_password.py +++ b/bookwyrm/tests/views/landing/test_password.py @@ -17,14 +17,14 @@ class PasswordViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "password", diff --git a/bookwyrm/tests/views/landing/test_register.py b/bookwyrm/tests/views/landing/test_register.py index 4b3d46673..7db6775db 100644 --- a/bookwyrm/tests/views/landing/test_register.py +++ b/bookwyrm/tests/views/landing/test_register.py @@ -21,21 +21,21 @@ class RegisterViews(TestCase): """login and password management""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@your.domain.here", "mouse@mouse.com", "password", local=True, localname="mouse", ) - self.settings = models.SiteSettings.objects.create( + cls.settings = models.SiteSettings.objects.create( id=1, require_confirm_email=False, allow_registration=True ) diff --git a/bookwyrm/tests/views/lists/test_curate.py b/bookwyrm/tests/views/lists/test_curate.py index 59d73cefd..af6116efa 100644 --- a/bookwyrm/tests/views/lists/test_curate.py +++ b/bookwyrm/tests/views/lists/test_curate.py @@ -16,14 +16,14 @@ class ListViews(TestCase): """list view""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -32,7 +32,7 @@ class ListViews(TestCase): remote_id="https://example.com/users/mouse", ) work = models.Work.objects.create(title="Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, @@ -42,9 +42,7 @@ class ListViews(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.lists_stream.remove_list_task.delay"), ): - self.list = models.List.objects.create( - name="Test List", user=self.local_user - ) + cls.list = models.List.objects.create(name="Test List", user=cls.local_user) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/lists/test_embed.py b/bookwyrm/tests/views/lists/test_embed.py index 9c1d3846d..2d2d5ec8c 100644 --- a/bookwyrm/tests/views/lists/test_embed.py +++ b/bookwyrm/tests/views/lists/test_embed.py @@ -16,14 +16,14 @@ class ListViews(TestCase): """list view""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -32,7 +32,7 @@ class ListViews(TestCase): remote_id="https://example.com/users/mouse", ) work = models.Work.objects.create(title="Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, @@ -42,9 +42,7 @@ class ListViews(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.lists_stream.remove_list_task.delay"), ): - self.list = models.List.objects.create( - name="Test List", user=self.local_user - ) + cls.list = models.List.objects.create(name="Test List", user=cls.local_user) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/lists/test_list.py b/bookwyrm/tests/views/lists/test_list.py index dc144c134..6af9d1db1 100644 --- a/bookwyrm/tests/views/lists/test_list.py +++ b/bookwyrm/tests/views/lists/test_list.py @@ -19,14 +19,14 @@ class ListViews(TestCase): """list view""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -34,7 +34,7 @@ class ListViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@rat.com", "ratword", @@ -43,25 +43,25 @@ class ListViews(TestCase): remote_id="https://example.com/users/rat", ) work = models.Work.objects.create(title="Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, ) work_two = models.Work.objects.create(title="Labori") - self.book_two = models.Edition.objects.create( + cls.book_two = models.Edition.objects.create( title="Example Edition 2", remote_id="https://example.com/book/2", parent_work=work_two, ) work_three = models.Work.objects.create(title="Trabajar") - self.book_three = models.Edition.objects.create( + cls.book_three = models.Edition.objects.create( title="Example Edition 3", remote_id="https://example.com/book/3", parent_work=work_three, ) work_four = models.Work.objects.create(title="Travailler") - self.book_four = models.Edition.objects.create( + cls.book_four = models.Edition.objects.create( title="Example Edition 4", remote_id="https://example.com/book/4", parent_work=work_four, @@ -71,9 +71,7 @@ class ListViews(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.lists_stream.remove_list_task.delay"), ): - self.list = models.List.objects.create( - name="Test List", user=self.local_user - ) + cls.list = models.List.objects.create(name="Test List", user=cls.local_user) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/lists/test_list_item.py b/bookwyrm/tests/views/lists/test_list_item.py index e265d7ef5..e70eabf1b 100644 --- a/bookwyrm/tests/views/lists/test_list_item.py +++ b/bookwyrm/tests/views/lists/test_list_item.py @@ -13,14 +13,14 @@ class ListItemViews(TestCase): """list view""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -29,7 +29,7 @@ class ListItemViews(TestCase): remote_id="https://example.com/users/mouse", ) work = models.Work.objects.create(title="Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, @@ -38,9 +38,7 @@ class ListItemViews(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.lists_stream.remove_list_task.delay"), ): - self.list = models.List.objects.create( - name="Test List", user=self.local_user - ) + cls.list = models.List.objects.create(name="Test List", user=cls.local_user) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/lists/test_lists.py b/bookwyrm/tests/views/lists/test_lists.py index 88ea71360..069fd7008 100644 --- a/bookwyrm/tests/views/lists/test_lists.py +++ b/bookwyrm/tests/views/lists/test_lists.py @@ -16,14 +16,14 @@ class ListViews(TestCase): """lists of lists""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -31,7 +31,7 @@ class ListViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "rat@local.com", "rat@rat.com", "ratword", local=True, localname="rat" ) diff --git a/bookwyrm/tests/views/preferences/test_block.py b/bookwyrm/tests/views/preferences/test_block.py index bc39d2f62..e20888659 100644 --- a/bookwyrm/tests/views/preferences/test_block.py +++ b/bookwyrm/tests/views/preferences/test_block.py @@ -14,14 +14,14 @@ class BlockViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", @@ -29,7 +29,7 @@ class BlockViews(TestCase): localname="mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", diff --git a/bookwyrm/tests/views/preferences/test_change_password.py b/bookwyrm/tests/views/preferences/test_change_password.py index 1717204bd..75a17e462 100644 --- a/bookwyrm/tests/views/preferences/test_change_password.py +++ b/bookwyrm/tests/views/preferences/test_change_password.py @@ -13,14 +13,14 @@ class ChangePasswordViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "password", diff --git a/bookwyrm/tests/views/preferences/test_delete_user.py b/bookwyrm/tests/views/preferences/test_delete_user.py index 94d8c4a69..34ab52be4 100644 --- a/bookwyrm/tests/views/preferences/test_delete_user.py +++ b/bookwyrm/tests/views/preferences/test_delete_user.py @@ -17,21 +17,21 @@ class DeleteUserViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@your.domain.here", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@your.domain.here", "rat@rat.rat", "password", @@ -39,7 +39,7 @@ class DeleteUserViews(TestCase): localname="rat", ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) with ( @@ -47,9 +47,9 @@ class DeleteUserViews(TestCase): patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), ): models.ShelfBook.objects.create( - book=self.book, - user=self.local_user, - shelf=self.local_user.shelf_set.first(), + book=cls.book, + user=cls.local_user, + shelf=cls.local_user.shelf_set.first(), ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/preferences/test_edit_user.py b/bookwyrm/tests/views/preferences/test_edit_user.py index 4b83f3b80..7872e8f6e 100644 --- a/bookwyrm/tests/views/preferences/test_edit_user.py +++ b/bookwyrm/tests/views/preferences/test_edit_user.py @@ -19,25 +19,25 @@ class EditUserViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) with ( @@ -45,9 +45,9 @@ class EditUserViews(TestCase): patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), ): models.ShelfBook.objects.create( - book=self.book, - user=self.local_user, - shelf=self.local_user.shelf_set.first(), + book=cls.book, + user=cls.local_user, + shelf=cls.local_user.shelf_set.first(), ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 128b8fc8b..f125e9009 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -18,15 +18,13 @@ class ExportViews(TestCase): """viewing and creating statuses""" @classmethod - def setUpTestData( - self, - ): # pylint: disable=bad-classmethod-argument, disable=invalid-name + def setUpTestData(cls): # pylint: disable=invalid-name """we need basic test data and mocks""" with ( patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch("bookwyrm.activitystreams.populate_stream_task.delay"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -34,11 +32,11 @@ class ExportViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Test Book", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, isbn_13="9781234567890", bnf_id="beep", ) diff --git a/bookwyrm/tests/views/preferences/test_two_factor_auth.py b/bookwyrm/tests/views/preferences/test_two_factor_auth.py index 8eb5e92c7..3b16236ed 100644 --- a/bookwyrm/tests/views/preferences/test_two_factor_auth.py +++ b/bookwyrm/tests/views/preferences/test_two_factor_auth.py @@ -18,14 +18,14 @@ class TwoFactorViews(TestCase): """Two Factor Authentication management""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@your.domain.here", "mouse@mouse.com", "password", diff --git a/bookwyrm/tests/views/shelf/test_shelf.py b/bookwyrm/tests/views/shelf/test_shelf.py index 57631974f..9c2b0a645 100644 --- a/bookwyrm/tests/views/shelf/test_shelf.py +++ b/bookwyrm/tests/views/shelf/test_shelf.py @@ -21,14 +21,14 @@ class ShelfViews(TestCase): """tag views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -36,15 +36,15 @@ class ShelfViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) 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 + cls.shelf = models.Shelf.objects.create( + name="Test Shelf", identifier="test-shelf", user=cls.local_user ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/shelf/test_shelf_actions.py b/bookwyrm/tests/views/shelf/test_shelf_actions.py index ee5854d18..d4727d9c5 100644 --- a/bookwyrm/tests/views/shelf/test_shelf_actions.py +++ b/bookwyrm/tests/views/shelf/test_shelf_actions.py @@ -19,14 +19,14 @@ class ShelfActionViews(TestCase): """tag views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -34,7 +34,7 @@ class ShelfActionViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "rat@local.com", "rat@rat.com", "ratword", @@ -42,15 +42,15 @@ class ShelfActionViews(TestCase): localname="rat", remote_id="https://example.com/users/rat", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) 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 + cls.shelf = models.Shelf.objects.create( + name="Test Shelf", identifier="test-shelf", user=cls.local_user ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_annual_summary.py b/bookwyrm/tests/views/test_annual_summary.py index 2fd7dc4eb..db8389fc6 100644 --- a/bookwyrm/tests/views/test_annual_summary.py +++ b/bookwyrm/tests/views/test_annual_summary.py @@ -22,14 +22,14 @@ class AnnualSummary(TestCase): """views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -38,11 +38,11 @@ class AnnualSummary(TestCase): remote_id="https://example.com/users/mouse", summary_keys={"2020": "0123456789"}, ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, pages=300, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index bee057d0c..ed65fc30b 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -17,14 +17,14 @@ class AuthorViews(TestCase): """author views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -32,19 +32,19 @@ class AuthorViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.group = Group.objects.create(name="editor") - self.group.permissions.add( + cls.group = Group.objects.create(name="editor") + cls.group.permissions.add( Permission.objects.create( name="edit_book", codename="edit_book", content_type=ContentType.objects.get_for_model(models.User), ).id ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index e2bef539e..a169551ac 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -14,14 +14,14 @@ class DirectoryViews(TestCase): """tag views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", diff --git a/bookwyrm/tests/views/test_discover.py b/bookwyrm/tests/views/test_discover.py index 937039592..15732b924 100644 --- a/bookwyrm/tests/views/test_discover.py +++ b/bookwyrm/tests/views/test_discover.py @@ -12,14 +12,14 @@ class DiscoverViews(TestCase): """pages you land on without really trying""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index fb2609575..a57be1023 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -25,28 +25,28 @@ class FeedViews(TestCase): """activity feed, statuses, dms""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "nutria@local.com", "nutria@nutria.nutria", "password", local=True, localname="nutria", ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( parent_work=models.Work.objects.create(title="hi"), title="Example Edition", remote_id="https://example.com/book/1", diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index 61a0a82ce..c26a9372a 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -18,7 +18,7 @@ class FollowViews(TestCase): """follows""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" models.SiteSettings.objects.create() with ( @@ -26,7 +26,7 @@ class FollowViews(TestCase): patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -35,7 +35,7 @@ class FollowViews(TestCase): remote_id="https://example.com/users/mouse", ) with patch("bookwyrm.models.user.set_remote_server"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@email.com", "ratword", @@ -44,19 +44,19 @@ class FollowViews(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.group = Group.objects.create(name="editor") - self.group.permissions.add( + cls.group = Group.objects.create(name="editor") + cls.group.permissions.add( Permission.objects.create( name="edit_book", codename="edit_book", content_type=ContentType.objects.get_for_model(models.User), ).id ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) def setUp(self): diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 5d6aa8782..b33948c19 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -13,28 +13,28 @@ class GetStartedViews(TestCase): """helping new users get oriented""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat", ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( parent_work=models.Work.objects.create(title="hi"), title="Example Edition", remote_id="https://example.com/book/1", diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index 49227457b..d682b727d 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -16,14 +16,14 @@ class GoalViews(TestCase): """viewing and creating statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -31,7 +31,7 @@ class GoalViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@rat.com", "ratword", @@ -39,7 +39,7 @@ class GoalViews(TestCase): localname="rat", remote_id="https://example.com/users/rat", ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", ) diff --git a/bookwyrm/tests/views/test_group.py b/bookwyrm/tests/views/test_group.py index ca9284686..90223f74a 100644 --- a/bookwyrm/tests/views/test_group.py +++ b/bookwyrm/tests/views/test_group.py @@ -17,21 +17,21 @@ class GroupViews(TestCase): """view group and edit details""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", @@ -39,14 +39,14 @@ class GroupViews(TestCase): localname="rat", ) - self.testgroup = models.Group.objects.create( + cls.testgroup = models.Group.objects.create( name="Test Group", description="Initial description", - user=self.local_user, + user=cls.local_user, privacy="public", ) - self.membership = models.GroupMember.objects.create( - group=self.testgroup, user=self.local_user + cls.membership = models.GroupMember.objects.create( + group=cls.testgroup, user=cls.local_user ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_hashtag.py b/bookwyrm/tests/views/test_hashtag.py index 5979238d8..d9679fe5a 100644 --- a/bookwyrm/tests/views/test_hashtag.py +++ b/bookwyrm/tests/views/test_hashtag.py @@ -15,13 +15,13 @@ class HashtagView(TestCase): """hashtag view""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -29,7 +29,7 @@ class HashtagView(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.follower_user = models.User.objects.create_user( + cls.follower_user = models.User.objects.create_user( "follower@local.com", "follower@email.com", "followerword", @@ -37,8 +37,8 @@ class HashtagView(TestCase): localname="follower", remote_id="https://example.com/users/follower", ) - self.local_user.followers.add(self.follower_user) - self.other_user = models.User.objects.create_user( + cls.local_user.followers.add(cls.follower_user) + cls.other_user = models.User.objects.create_user( "other@local.com", "other@email.com", "otherword", @@ -47,25 +47,25 @@ class HashtagView(TestCase): remote_id="https://example.com/users/other", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) - self.hashtag_bookclub = models.Hashtag.objects.create(name="#BookClub") + cls.hashtag_bookclub = models.Hashtag.objects.create(name="#BookClub") with ( patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.activitystreams.add_status_task.delay"), ): - self.statuses_bookclub = [ + cls.statuses_bookclub = [ models.Comment.objects.create( - book=self.book, user=self.local_user, content="#BookClub" + book=cls.book, user=cls.local_user, content="#BookClub" ), ] - for status in self.statuses_bookclub: - status.mention_hashtags.add(self.hashtag_bookclub) + for status in cls.statuses_bookclub: + status.mention_hashtags.add(cls.hashtag_bookclub) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index e00e1d234..818647db1 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -19,7 +19,7 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods """viewing and creating statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" with ( patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), @@ -27,7 +27,7 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.lists_stream.populate_lists_task.delay"), patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -40,7 +40,7 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods patch("bookwyrm.models.user.set_remote_server.delay"), patch("bookwyrm.suggested_users.rerank_user_task.delay"), ): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -50,15 +50,15 @@ class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Test Book", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) 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 + cls.shelf = models.Shelf.objects.create( + name="Test Shelf", identifier="test-shelf", user=cls.local_user ) def setUp(self): diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 95d7b5791..d1533c451 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -13,14 +13,14 @@ class InteractionViews(TestCase): """viewing and creating statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -29,7 +29,7 @@ class InteractionViews(TestCase): remote_id="https://example.com/users/mouse", ) with patch("bookwyrm.models.user.set_remote_server"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@email.com", "ratword", @@ -39,7 +39,7 @@ class InteractionViews(TestCase): outbox="https://example.com/users/rat/outbox", ) work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index bb66c8f3e..632a831b0 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -15,14 +15,14 @@ class IsbnViews(TestCase): """tag views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -30,12 +30,12 @@ class IsbnViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Test Book", isbn_13="1234567890123", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_notifications.py b/bookwyrm/tests/views/test_notifications.py index c44940742..878a64c2c 100644 --- a/bookwyrm/tests/views/test_notifications.py +++ b/bookwyrm/tests/views/test_notifications.py @@ -13,27 +13,25 @@ class NotificationViews(TestCase): """notifications""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( "rat", "rat@rat.rat", "ratword", local=True, localname="rat" ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): - self.status = models.Status.objects.create( - content="hi", user=self.local_user - ) + cls.status = models.Status.objects.create(content="hi", user=cls.local_user) models.SiteSettings.objects.create() def setUp(self): diff --git a/bookwyrm/tests/views/test_outbox.py b/bookwyrm/tests/views/test_outbox.py index ca289db3f..b21d56c83 100644 --- a/bookwyrm/tests/views/test_outbox.py +++ b/bookwyrm/tests/views/test_outbox.py @@ -16,14 +16,14 @@ class OutboxView(TestCase): """sends out activities""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we'll need some 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"), ): - self.local_user = models.User.objects.create_user( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -32,7 +32,7 @@ class OutboxView(TestCase): remote_id="https://example.com/users/mouse", ) work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 39c611d6c..139d91820 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -16,14 +16,14 @@ class ReadingViews(TestCase): """viewing and creating statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -32,7 +32,7 @@ class ReadingViews(TestCase): remote_id="https://example.com/users/mouse", ) with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@rat.com", "ratword", @@ -41,11 +41,11 @@ class ReadingViews(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Test Book", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) def setUp(self): diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index 113b3161d..c71ee6c58 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -16,12 +16,12 @@ class ReadThrough(TestCase): """readthrough tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """basic user and book data""" - self.work = models.Work.objects.create(title="Example Work") + cls.work = models.Work.objects.create(title="Example Work") - self.edition = models.Edition.objects.create( - title="Example Edition", parent_work=self.work + cls.edition = models.Edition.objects.create( + title="Example Edition", parent_work=cls.work ) with ( @@ -29,7 +29,7 @@ class ReadThrough(TestCase): patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), ): - self.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" ) diff --git a/bookwyrm/tests/views/test_report.py b/bookwyrm/tests/views/test_report.py index 65670dcbf..f07887bfe 100644 --- a/bookwyrm/tests/views/test_report.py +++ b/bookwyrm/tests/views/test_report.py @@ -12,21 +12,21 @@ class ReportViews(TestCase): """every response to a get request, html or json""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@mouse.mouse", "password", @@ -37,8 +37,8 @@ class ReportViews(TestCase): patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"), patch("bookwyrm.activitystreams.add_status_task.delay"), ): - self.status = models.Status.objects.create( - user=self.local_user, + cls.status = models.Status.objects.create( + user=cls.local_user, content="Test status", ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index af5ad5301..790efe51b 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -13,17 +13,17 @@ class RssFeedView(TestCase): """rss feed behaves as expected""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): 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( + cls.local_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( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/views/test_search.py b/bookwyrm/tests/views/test_search.py index 5e06e6f81..64ff68ba8 100644 --- a/bookwyrm/tests/views/test_search.py +++ b/bookwyrm/tests/views/test_search.py @@ -18,14 +18,14 @@ class Views(TestCase): """tag views""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -33,11 +33,11 @@ class Views(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.work = models.Work.objects.create(title="Test Work") + cls.book = models.Edition.objects.create( title="Test Book", remote_id="https://example.com/book/1", - parent_work=self.work, + parent_work=cls.work, ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index f5fe515f1..52582a235 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -77,14 +77,14 @@ class StatusViews(TestCase): """viewing and creating statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", "mouseword", @@ -92,16 +92,16 @@ class StatusViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - self.another_user = models.User.objects.create_user( + cls.another_user = models.User.objects.create_user( f"nutria@{DOMAIN}", "nutria@nutria.com", "password", local=True, localname="nutria", ) - self.existing_hashtag = models.Hashtag.objects.create(name="#existing") + cls.existing_hashtag = models.Hashtag.objects.create(name="#existing") with patch("bookwyrm.models.user.set_remote_server"): - self.remote_user = models.User.objects.create_user( + cls.remote_user = models.User.objects.create_user( "rat", "rat@email.com", "ratword", @@ -111,7 +111,7 @@ class StatusViews(TestCase): outbox="https://example.com/users/rat/outbox", ) work = models.Work.objects.create(title="Test Work") - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", parent_work=work, diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index 6f826b46f..7230f3324 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -13,14 +13,14 @@ class UpdateViews(TestCase): """lets the ui check for unread notification""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 4b49f120e..362d04feb 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -16,24 +16,24 @@ class UserViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", local=True, localname="mouse", ) - self.rat = models.User.objects.create_user( + cls.rat = models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) with ( @@ -42,9 +42,9 @@ class UserViews(TestCase): patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), ): models.ShelfBook.objects.create( - book=self.book, - user=self.local_user, - shelf=self.local_user.shelf_set.first(), + book=cls.book, + user=cls.local_user, + shelf=cls.local_user.shelf_set.first(), ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_wellknown.py b/bookwyrm/tests/views/test_wellknown.py index d8bf0d062..444d88d17 100644 --- a/bookwyrm/tests/views/test_wellknown.py +++ b/bookwyrm/tests/views/test_wellknown.py @@ -14,14 +14,14 @@ class WellknownViews(TestCase): """view user and edit profile""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" 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( + cls.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", "password", From 90bd8935689274aa9b3c54a1eb1f509309ae004a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sun, 17 Mar 2024 21:00:48 -0300 Subject: [PATCH 05/10] Fix remaining instances of `bad-classmethod-argument` --- bookwyrm/tests/activitypub/test_author.py | 6 +++--- bookwyrm/tests/activitypub/test_quotation.py | 6 +++--- .../tests/connectors/test_abstract_connector.py | 4 ++-- .../test_abstract_minimal_connector.py | 4 ++-- .../tests/connectors/test_bookwyrm_connector.py | 2 +- .../tests/connectors/test_connector_manager.py | 12 ++++++------ .../connectors/test_openlibrary_connector.py | 2 +- bookwyrm/tests/models/test_book_model.py | 12 ++++++------ bookwyrm/tests/test_book_search.py | 16 ++++++++-------- bookwyrm/tests/views/test_setup.py | 4 ++-- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_author.py b/bookwyrm/tests/activitypub/test_author.py index 7579909a8..7f21e570c 100644 --- a/bookwyrm/tests/activitypub/test_author.py +++ b/bookwyrm/tests/activitypub/test_author.py @@ -7,13 +7,13 @@ class Author(TestCase): """serialize author tests""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """initial data""" - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", ) - self.author = models.Author.objects.create( + cls.author = models.Author.objects.create( name="Author fullname", aliases=["One", "Two"], bio="bio bio bio", diff --git a/bookwyrm/tests/activitypub/test_quotation.py b/bookwyrm/tests/activitypub/test_quotation.py index 9a0867c52..50aeb5834 100644 --- a/bookwyrm/tests/activitypub/test_quotation.py +++ b/bookwyrm/tests/activitypub/test_quotation.py @@ -11,10 +11,10 @@ class Quotation(TestCase): """we have hecka ways to create statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """model objects we'll need""" with patch("bookwyrm.models.user.set_remote_server.delay"): - self.user = models.User.objects.create_user( + cls.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", @@ -23,7 +23,7 @@ class Quotation(TestCase): outbox="https://example.com/user/mouse/outbox", remote_id="https://example.com/user/mouse", ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", ) diff --git a/bookwyrm/tests/connectors/test_abstract_connector.py b/bookwyrm/tests/connectors/test_abstract_connector.py index b43966d6a..994286994 100644 --- a/bookwyrm/tests/connectors/test_abstract_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_connector.py @@ -13,7 +13,7 @@ class AbstractConnector(TestCase): """generic code for connecting to outside data sources""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need an example connector in the database""" models.Connector.objects.create( identifier="example.com", @@ -23,7 +23,7 @@ class AbstractConnector(TestCase): covers_url="https://example.com/covers", search_url="https://example.com/search?q=", ) - self.book = models.Edition.objects.create( + cls.book = models.Edition.objects.create( title="Test Book", remote_id="https://example.com/book/1234", openlibrary_key="OL1234M", diff --git a/bookwyrm/tests/connectors/test_abstract_minimal_connector.py b/bookwyrm/tests/connectors/test_abstract_minimal_connector.py index 73399649e..cbbecf652 100644 --- a/bookwyrm/tests/connectors/test_abstract_minimal_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_minimal_connector.py @@ -10,9 +10,9 @@ class AbstractConnector(TestCase): """generic code for connecting to outside data sources""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need an example connector in the database""" - self.connector_info = models.Connector.objects.create( + cls.connector_info = models.Connector.objects.create( identifier="example.com", connector_file="openlibrary", base_url="https://example.com", diff --git a/bookwyrm/tests/connectors/test_bookwyrm_connector.py b/bookwyrm/tests/connectors/test_bookwyrm_connector.py index 553901655..9a909aa8a 100644 --- a/bookwyrm/tests/connectors/test_bookwyrm_connector.py +++ b/bookwyrm/tests/connectors/test_bookwyrm_connector.py @@ -12,7 +12,7 @@ class BookWyrmConnector(TestCase): """this connector doesn't do much, just search""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """create bookwrym_connector in the database""" models.Connector.objects.create( identifier="example.com", diff --git a/bookwyrm/tests/connectors/test_connector_manager.py b/bookwyrm/tests/connectors/test_connector_manager.py index cc01f1116..7c9512ced 100644 --- a/bookwyrm/tests/connectors/test_connector_manager.py +++ b/bookwyrm/tests/connectors/test_connector_manager.py @@ -11,18 +11,18 @@ class ConnectorManager(TestCase): """interface between the app and various connectors""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we'll need some books and a connector info entry""" - self.work = models.Work.objects.create(title="Example Work") + cls.work = models.Work.objects.create(title="Example Work") models.Edition.objects.create( - title="Example Edition", parent_work=self.work, isbn_10="0000000000" + title="Example Edition", parent_work=cls.work, isbn_10="0000000000" ) - self.edition = models.Edition.objects.create( - title="Another Edition", parent_work=self.work, isbn_10="1111111111" + cls.edition = models.Edition.objects.create( + title="Another Edition", parent_work=cls.work, isbn_10="1111111111" ) - self.remote_connector = models.Connector.objects.create( + cls.remote_connector = models.Connector.objects.create( identifier="test_connector_remote", priority=1, connector_file="bookwyrm_connector", diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index 487356400..72bac4244 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -19,7 +19,7 @@ class Openlibrary(TestCase): """test loading data from openlibrary.org""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """creates the connector in the database""" models.Connector.objects.create( identifier="openlibrary.org", diff --git a/bookwyrm/tests/models/test_book_model.py b/bookwyrm/tests/models/test_book_model.py index c6b854180..c40c94294 100644 --- a/bookwyrm/tests/models/test_book_model.py +++ b/bookwyrm/tests/models/test_book_model.py @@ -19,17 +19,17 @@ class Book(TestCase): """not too much going on in the books model but here we are""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we'll need some books""" - self.work = models.Work.objects.create( + cls.work = models.Work.objects.create( title="Example Work", remote_id="https://example.com/book/1" ) - self.first_edition = models.Edition.objects.create( - title="Example Edition", parent_work=self.work + cls.first_edition = models.Edition.objects.create( + title="Example Edition", parent_work=cls.work ) - self.second_edition = models.Edition.objects.create( + cls.second_edition = models.Edition.objects.create( title="Another Example Edition", - parent_work=self.work, + parent_work=cls.work, ) def test_remote_id(self): diff --git a/bookwyrm/tests/test_book_search.py b/bookwyrm/tests/test_book_search.py index d2056bfeb..4663d1cdc 100644 --- a/bookwyrm/tests/test_book_search.py +++ b/bookwyrm/tests/test_book_search.py @@ -11,27 +11,27 @@ class BookSearch(TestCase): """look for some books""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" - self.work = models.Work.objects.create(title="Example Work") + cls.work = models.Work.objects.create(title="Example Work") - self.first_edition = models.Edition.objects.create( + cls.first_edition = models.Edition.objects.create( title="Example Edition", - parent_work=self.work, + parent_work=cls.work, isbn_10="0000000000", physical_format="Paperback", published_date=datetime.datetime(2019, 4, 9, 0, 0, tzinfo=timezone.utc), ) - self.second_edition = models.Edition.objects.create( + cls.second_edition = models.Edition.objects.create( title="Another Edition", - parent_work=self.work, + parent_work=cls.work, isbn_10="1111111111", openlibrary_key="hello", pages=150, ) - self.third_edition = models.Edition.objects.create( + cls.third_edition = models.Edition.objects.create( title="Another Edition with annoying ISBN", - parent_work=self.work, + parent_work=cls.work, isbn_10="022222222X", ) diff --git a/bookwyrm/tests/views/test_setup.py b/bookwyrm/tests/views/test_setup.py index d2bdba340..7547b5646 100644 --- a/bookwyrm/tests/views/test_setup.py +++ b/bookwyrm/tests/views/test_setup.py @@ -14,9 +14,9 @@ class SetupViews(TestCase): """activity feed, statuses, dms""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData(cls): """we need basic test data and mocks""" - self.site = models.SiteSettings.objects.create(install_mode=True) + cls.site = models.SiteSettings.objects.create(install_mode=True) def setUp(self): """individual test setup""" From 98600440d8c2315205616e6bd2effe1aafc667df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20C=C3=A1mara?= Date: Tue, 26 Mar 2024 17:14:09 +0000 Subject: [PATCH 06/10] Remove twitter from README.md The Twitter/X account doesn't seem to exist, so removing the badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f8b2eb1f6..7e27d44e6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ BookWyrm is a social network for tracking your reading, talking about books, wri ## Links [![Mastodon Follow](https://img.shields.io/mastodon/follow/000146121?domain=https%3A%2F%2Ftech.lgbt&style=social)](https://tech.lgbt/@bookwyrm) -[![Twitter Follow](https://img.shields.io/twitter/follow/BookWyrmSocial?style=social)](https://twitter.com/BookWyrmSocial) - [Project homepage](https://joinbookwyrm.com/) - [Support](https://patreon.com/bookwyrm) From 2272e7a326c751f55d4c37150fee8b346218e501 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 29 Mar 2024 12:07:52 +0100 Subject: [PATCH 07/10] flower 2.0.1 fixes a few link bugs (particularly for favicon) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6b3d838bf..81975fc4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ django-sass-processor==1.2.2 django-storages==1.13.2 django-storages[azure] environs==9.5.0 -flower==2.0.0 +flower==2.0.1 grpcio==1.57.0 # Not a direct dependency, pinned to get a security fix libsass==0.22.0 Markdown==3.4.1 From ffee29d8e2d5c8c430520ac666b5083c75b16499 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Fri, 29 Mar 2024 15:45:35 +0100 Subject: [PATCH 08/10] Fix resource leaks Rewrite places where files (or other resources) are opened but not closed to "with" blocks, which automatically call close() at the end of the scope. Also simplify some tests where images need to be saved to a model field: an opened file can be passed directly to FileField.save(). --- bookwyrm/preview_images.py | 48 +++++++++--------- bookwyrm/settings.py | 1 - .../tests/activitypub/test_base_activity.py | 10 ++-- .../tests/importers/test_calibre_import.py | 6 ++- .../tests/importers/test_goodreads_import.py | 6 ++- bookwyrm/tests/importers/test_importer.py | 6 ++- .../importers/test_librarything_import.py | 6 ++- .../importers/test_openlibrary_import.py | 6 ++- .../tests/importers/test_storygraph_import.py | 6 ++- bookwyrm/tests/models/test_book_model.py | 11 ++--- bookwyrm/tests/models/test_fields.py | 49 +++++++------------ bookwyrm/tests/models/test_status_model.py | 15 +++--- bookwyrm/tests/test_preview_images.py | 17 ++++--- bookwyrm/tests/views/admin/test_federation.py | 8 +-- bookwyrm/tests/views/books/test_book.py | 30 +++++------- bookwyrm/tests/views/imports/test_import.py | 14 +++--- .../tests/views/imports/test_user_import.py | 14 +++--- .../tests/views/preferences/test_edit_user.py | 20 ++++---- bookwyrm/tests/views/test_feed.py | 11 ++--- 19 files changed, 135 insertions(+), 149 deletions(-) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 995f25bfd..a213490ab 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -175,11 +175,13 @@ def generate_instance_layer(content_width): site = models.SiteSettings.objects.get() if site.logo_small: - logo_img = Image.open(site.logo_small) + with Image.open(site.logo_small) as logo_img: + logo_img.load() else: try: static_path = os.path.join(settings.STATIC_ROOT, "images/logo-small.png") - logo_img = Image.open(static_path) + with Image.open(static_path) as logo_img: + logo_img.load() except FileNotFoundError: logo_img = None @@ -211,18 +213,9 @@ def generate_instance_layer(content_width): def generate_rating_layer(rating, content_width): """Places components for rating preview""" - try: - icon_star_full = Image.open( - os.path.join(settings.STATIC_ROOT, "images/icons/star-full.png") - ) - icon_star_empty = Image.open( - os.path.join(settings.STATIC_ROOT, "images/icons/star-empty.png") - ) - icon_star_half = Image.open( - os.path.join(settings.STATIC_ROOT, "images/icons/star-half.png") - ) - except FileNotFoundError: - return None + path_star_full = os.path.join(settings.STATIC_ROOT, "images/icons/star-full.png") + path_star_empty = os.path.join(settings.STATIC_ROOT, "images/icons/star-empty.png") + path_star_half = os.path.join(settings.STATIC_ROOT, "images/icons/star-half.png") icon_size = 64 icon_margin = 10 @@ -237,17 +230,23 @@ def generate_rating_layer(rating, content_width): position_x = 0 - for _ in range(math.floor(rating)): - rating_layer_mask.alpha_composite(icon_star_full, (position_x, 0)) - position_x = position_x + icon_size + icon_margin + try: + with Image.open(path_star_full) as icon_star_full: + for _ in range(math.floor(rating)): + rating_layer_mask.alpha_composite(icon_star_full, (position_x, 0)) + position_x = position_x + icon_size + icon_margin - if math.floor(rating) != math.ceil(rating): - rating_layer_mask.alpha_composite(icon_star_half, (position_x, 0)) - position_x = position_x + icon_size + icon_margin + if math.floor(rating) != math.ceil(rating): + with Image.open(path_star_half) as icon_star_half: + rating_layer_mask.alpha_composite(icon_star_half, (position_x, 0)) + position_x = position_x + icon_size + icon_margin - for _ in range(5 - math.ceil(rating)): - rating_layer_mask.alpha_composite(icon_star_empty, (position_x, 0)) - position_x = position_x + icon_size + icon_margin + with Image.open(path_star_empty) as icon_star_empty: + for _ in range(5 - math.ceil(rating)): + rating_layer_mask.alpha_composite(icon_star_empty, (position_x, 0)) + position_x = position_x + icon_size + icon_margin + except FileNotFoundError: + return None rating_layer_mask = rating_layer_mask.getchannel("A") rating_layer_mask = ImageOps.invert(rating_layer_mask) @@ -290,7 +289,8 @@ def generate_preview_image( texts = texts or {} # Cover try: - inner_img_layer = Image.open(picture) + with Image.open(picture) as inner_img_layer: + inner_img_layer.load() inner_img_layer.thumbnail( (inner_img_width, inner_img_height), Image.Resampling.LANCZOS ) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 77bec0d8e..28d78a3da 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -19,7 +19,6 @@ DOMAIN = env("DOMAIN") with open("VERSION", encoding="utf-8") as f: version = f.read() version = version.replace("\n", "") -f.close() VERSION = version diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index b529f6ae5..a545beb3e 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -1,12 +1,10 @@ """ tests the base functionality for activitypub dataclasses """ -from io import BytesIO import json import pathlib from unittest.mock import patch from dataclasses import dataclass from django.test import TestCase -from PIL import Image import responses from bookwyrm import activitypub @@ -48,13 +46,11 @@ class BaseActivity(TestCase): # don't try to load the user icon del self.userdata["icon"] - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) - self.image_data = output.getvalue() + with open(image_path, "rb") as image_file: + self.image_data = image_file.read() def test_get_representative_not_existing(self, *_): """test that an instance representative actor is created if it does not exist""" diff --git a/bookwyrm/tests/importers/test_calibre_import.py b/bookwyrm/tests/importers/test_calibre_import.py index dcbe68c64..d7947e65e 100644 --- a/bookwyrm/tests/importers/test_calibre_import.py +++ b/bookwyrm/tests/importers/test_calibre_import.py @@ -9,7 +9,6 @@ from bookwyrm.importers import CalibreImporter from bookwyrm.models.import_job import handle_imported_book -# pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @@ -20,8 +19,13 @@ class CalibreImport(TestCase): """use a test csv""" self.importer = CalibreImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/calibre.csv") + # pylint: disable-next=consider-using-with self.csv = open(datafile, "r", encoding=self.importer.encoding) + def tearDown(self): + """close test csv""" + self.csv.close() + @classmethod def setUpTestData(cls): """populate database""" diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index f0b67cffd..79d58085c 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -16,7 +16,6 @@ def make_date(*args): return datetime.datetime(*args, tzinfo=pytz.UTC) -# pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @@ -27,8 +26,13 @@ class GoodreadsImport(TestCase): """use a test csv""" self.importer = GoodreadsImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") + # pylint: disable-next=consider-using-with self.csv = open(datafile, "r", encoding=self.importer.encoding) + def tearDown(self): + """close test csv""" + self.csv.close() + @classmethod def setUpTestData(cls): """populate database""" diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index ea10d0f53..39aac22ff 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -19,7 +19,6 @@ def make_date(*args): return datetime.datetime(*args, tzinfo=pytz.UTC) -# pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @@ -30,8 +29,13 @@ class GenericImporter(TestCase): """use a test csv""" self.importer = Importer() datafile = pathlib.Path(__file__).parent.joinpath("../data/generic.csv") + # pylint: disable-next=consider-using-with self.csv = open(datafile, "r", encoding=self.importer.encoding) + def tearDown(self): + """close test csv""" + self.csv.close() + @classmethod def setUpTestData(cls): """populate database""" diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 280131115..4d78d242a 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -16,7 +16,6 @@ def make_date(*args): return datetime.datetime(*args, tzinfo=pytz.UTC) -# pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @@ -29,8 +28,13 @@ class LibrarythingImport(TestCase): datafile = pathlib.Path(__file__).parent.joinpath("../data/librarything.tsv") # Librarything generates latin encoded exports... + # pylint: disable-next=consider-using-with self.csv = open(datafile, "r", encoding=self.importer.encoding) + def tearDown(self): + """close test csv""" + self.csv.close() + @classmethod def setUpTestData(cls): """populate database""" diff --git a/bookwyrm/tests/importers/test_openlibrary_import.py b/bookwyrm/tests/importers/test_openlibrary_import.py index 05bab0cc2..8f2f120ff 100644 --- a/bookwyrm/tests/importers/test_openlibrary_import.py +++ b/bookwyrm/tests/importers/test_openlibrary_import.py @@ -16,7 +16,6 @@ def make_date(*args): return datetime.datetime(*args, tzinfo=pytz.UTC) -# pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @@ -27,8 +26,13 @@ class OpenLibraryImport(TestCase): """use a test csv""" self.importer = OpenLibraryImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/openlibrary.csv") + # pylint: disable-next=consider-using-with self.csv = open(datafile, "r", encoding=self.importer.encoding) + def tearDown(self): + """close test csv""" + self.csv.close() + @classmethod def setUpTestData(cls): """populate database""" diff --git a/bookwyrm/tests/importers/test_storygraph_import.py b/bookwyrm/tests/importers/test_storygraph_import.py index eee27010c..3de2b13a0 100644 --- a/bookwyrm/tests/importers/test_storygraph_import.py +++ b/bookwyrm/tests/importers/test_storygraph_import.py @@ -16,7 +16,6 @@ def make_date(*args): return datetime.datetime(*args, tzinfo=pytz.UTC) -# pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @@ -27,8 +26,13 @@ class StorygraphImport(TestCase): """use a test csv""" self.importer = StorygraphImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/storygraph.csv") + # pylint: disable-next=consider-using-with self.csv = open(datafile, "r", encoding=self.importer.encoding) + def tearDown(self): + """close test csv""" + self.csv.close() + @classmethod def setUpTestData(cls): """populate database""" diff --git a/bookwyrm/tests/models/test_book_model.py b/bookwyrm/tests/models/test_book_model.py index c40c94294..5b2b71ba9 100644 --- a/bookwyrm/tests/models/test_book_model.py +++ b/bookwyrm/tests/models/test_book_model.py @@ -1,12 +1,9 @@ """ testing models """ -from io import BytesIO import pathlib import pytest from dateutil.parser import parse -from PIL import Image -from django.core.files.base import ContentFile from django.test import TestCase from django.utils import timezone @@ -130,15 +127,13 @@ class Book(TestCase): ) def test_thumbnail_fields(self): """Just hit them""" - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) book = models.Edition.objects.create(title="hello") - book.cover.save("test.jpg", ContentFile(output.getvalue())) + with open(image_path, "rb") as image_file: + book.cover.save("test.jpg", image_file) self.assertIsNotNone(book.cover_bw_book_xsmall_webp.url) self.assertIsNotNone(book.cover_bw_book_xsmall_jpg.url) diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index cc8c54113..2917c8908 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -1,5 +1,4 @@ """ testing models """ -from io import BytesIO from collections import namedtuple from dataclasses import dataclass import datetime @@ -10,7 +9,6 @@ from typing import List from unittest import expectedFailure from unittest.mock import patch -from PIL import Image import responses from django.core.exceptions import ValidationError @@ -420,13 +418,11 @@ class ModelFields(TestCase): user = User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) - user.avatar.save("test.jpg", ContentFile(output.getvalue())) + with open(image_path, "rb") as image_file: + user.avatar.save("test.jpg", image_file) instance = fields.ImageField() @@ -516,30 +512,25 @@ class ModelFields(TestCase): @responses.activate def test_image_field_set_field_from_activity_no_overwrite_with_cover(self, *_): """update a model instance from an activitypub object""" - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) - - another_image_file = pathlib.Path(__file__).parent.joinpath( + another_image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/logo.png" ) - another_image = Image.open(another_image_file) - another_output = BytesIO() - another_image.save(another_output, format=another_image.format) instance = fields.ImageField(activitypub_field="cover", name="cover") - responses.add( - responses.GET, - "http://www.example.com/image.jpg", - body=another_image.tobytes(), - status=200, - ) + with open(another_image_path, "rb") as another_image_file: + responses.add( + responses.GET, + "http://www.example.com/image.jpg", + body=another_image_file.read(), + status=200, + ) book = Edition.objects.create(title="hello") - book.cover.save("test.jpg", ContentFile(output.getvalue())) + with open(image_path, "rb") as image_file: + book.cover.save("test.jpg", image_file) cover_size = book.cover.size self.assertIsNotNone(cover_size) @@ -553,24 +544,22 @@ class ModelFields(TestCase): @responses.activate def test_image_field_set_field_from_activity_with_overwrite_with_cover(self, *_): """update a model instance from an activitypub object""" - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) book = Edition.objects.create(title="hello") - book.cover.save("test.jpg", ContentFile(output.getvalue())) + with open(image_path, "rb") as image_file: + book.cover.save("test.jpg", image_file) cover_size = book.cover.size self.assertIsNotNone(cover_size) - another_image_file = pathlib.Path(__file__).parent.joinpath( + another_image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/logo.png" ) instance = fields.ImageField(activitypub_field="cover", name="cover") - with open(another_image_file, "rb") as another_image: + with open(another_image_path, "rb") as another_image: responses.add( responses.GET, "http://www.example.com/image.jpg", diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index bd2853595..e97febbfa 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -1,16 +1,13 @@ """ testing models """ from unittest.mock import patch -from io import BytesIO import pathlib import re from django.http import Http404 -from django.core.files.base import ContentFile from django.db import IntegrityError from django.contrib.auth.models import AnonymousUser from django.test import TestCase from django.utils import timezone -from PIL import Image import responses from bookwyrm import activitypub, models, settings @@ -51,14 +48,14 @@ class Status(TestCase): """individual test setup""" self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - with patch("bookwyrm.models.Status.broadcast"): - image.save(output, format=image.format) - self.book.cover.save("test.jpg", ContentFile(output.getvalue())) + with ( + patch("bookwyrm.models.Status.broadcast"), + open(image_path, "rb") as image_file, + ): + self.book.cover.save("test.jpg", image_file) def test_status_generated_fields(self, *_): """setting remote id""" diff --git a/bookwyrm/tests/test_preview_images.py b/bookwyrm/tests/test_preview_images.py index 4f711b38b..12fb56d07 100644 --- a/bookwyrm/tests/test_preview_images.py +++ b/bookwyrm/tests/test_preview_images.py @@ -21,20 +21,20 @@ from bookwyrm.preview_images import ( # pylint: disable=unused-argument # pylint: disable=missing-function-docstring -# pylint: disable=consider-using-with class PreviewImages(TestCase): """every response to a get request, html or json""" def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - avatar_file = pathlib.Path(__file__).parent.joinpath( + avatar_path = pathlib.Path(__file__).parent.joinpath( "../static/images/no_cover.jpg" ) with ( patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), + open(avatar_path, "rb") as avatar_file, ): self.local_user = models.User.objects.create_user( "possum@local.com", @@ -43,8 +43,8 @@ class PreviewImages(TestCase): local=True, localname="possum", avatar=SimpleUploadedFile( - avatar_file, - open(avatar_file, "rb").read(), + avatar_path, + avatar_file.read(), content_type="image/jpeg", ), ) @@ -68,6 +68,7 @@ class PreviewImages(TestCase): patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch("bookwyrm.activitystreams.populate_stream_task.delay"), patch("bookwyrm.lists_stream.populate_lists_task.delay"), + open(avatar_path, "rb") as avatar_file, ): self.remote_user_with_preview = models.User.objects.create_user( "badger@your.domain.here", @@ -78,8 +79,8 @@ class PreviewImages(TestCase): inbox="https://example.com/users/badger/inbox", outbox="https://example.com/users/badger/outbox", avatar=SimpleUploadedFile( - avatar_file, - open(avatar_file, "rb").read(), + avatar_path, + avatar_file.read(), content_type="image/jpeg", ), ) @@ -96,7 +97,7 @@ class PreviewImages(TestCase): settings.ENABLE_PREVIEW_IMAGES = True def test_generate_preview_image(self, *args, **kwargs): - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../static/images/no_cover.jpg" ) @@ -105,7 +106,7 @@ class PreviewImages(TestCase): "text_three": "@possum@local.com", } - result = generate_preview_image(texts=texts, picture=image_file, rating=5) + result = generate_preview_image(texts=texts, picture=image_path, rating=5) self.assertIsInstance(result, Image.Image) self.assertEqual( result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT) diff --git a/bookwyrm/tests/views/admin/test_federation.py b/bookwyrm/tests/views/admin/test_federation.py index 1d0012dde..6dcd5535f 100644 --- a/bookwyrm/tests/views/admin/test_federation.py +++ b/bookwyrm/tests/views/admin/test_federation.py @@ -1,5 +1,4 @@ """ test for app action functionality """ -import os import json from unittest.mock import patch @@ -179,7 +178,6 @@ class FederationViews(TestCase): self.assertEqual(server.application_type, "coolsoft") self.assertEqual(server.status, "blocked") - # pylint: disable=consider-using-with def test_import_blocklist(self): """load a json file with a list of servers to block""" server = models.FederatedServer.objects.create(server_name="hi.there.com") @@ -191,14 +189,13 @@ class FederationViews(TestCase): {"instance": "hi.there.com", "url": "https://explanation.url"}, # existing {"a": "b"}, # invalid ] - json.dump(data, open("file.json", "w")) # pylint: disable=unspecified-encoding view = views.ImportServerBlocklist.as_view() request = self.factory.post( "", { "json_file": SimpleUploadedFile( - "file.json", open("file.json", "rb").read() + "file.json", json.dumps(data).encode("utf-8") ) }, ) @@ -214,6 +211,3 @@ class FederationViews(TestCase): created = models.FederatedServer.objects.get(server_name="server.name") self.assertEqual(created.status, "blocked") self.assertEqual(created.notes, "https://explanation.url") - - # remove file.json after test - os.remove("file.json") diff --git a/bookwyrm/tests/views/books/test_book.py b/bookwyrm/tests/views/books/test_book.py index cb66811a1..ee6e7d8b4 100644 --- a/bookwyrm/tests/views/books/test_book.py +++ b/bookwyrm/tests/views/books/test_book.py @@ -1,8 +1,6 @@ """ test for app action functionality """ -from io import BytesIO import pathlib from unittest.mock import patch -from PIL import Image import responses @@ -161,15 +159,15 @@ class BookViews(TestCase): def test_upload_cover_file(self): """add a cover via file upload""" self.assertFalse(self.book.cover) - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../../static/images/default_avi.jpg" ) form = forms.CoverForm(instance=self.book) - # pylint: disable=consider-using-with - form.data["cover"] = SimpleUploadedFile( - image_file, open(image_file, "rb").read(), content_type="image/jpeg" - ) + with open(image_path, "rb") as image_file: + form.data["cover"] = SimpleUploadedFile( + image_path, image_file.read(), content_type="image/jpeg" + ) request = self.factory.post("", form.data) request.user = self.local_user @@ -296,16 +294,14 @@ class BookViews(TestCase): def _setup_cover_url(): """creates cover url mock""" cover_url = "http://example.com" - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) - responses.add( - responses.GET, - cover_url, - body=output.getvalue(), - status=200, - ) + with open(image_path, "rb") as image_file: + responses.add( + responses.GET, + cover_url, + body=image_file.read(), + status=200, + ) return cover_url diff --git a/bookwyrm/tests/views/imports/test_import.py b/bookwyrm/tests/views/imports/test_import.py index 658d95a33..f694b7bf5 100644 --- a/bookwyrm/tests/views/imports/test_import.py +++ b/bookwyrm/tests/views/imports/test_import.py @@ -81,13 +81,13 @@ class ImportViews(TestCase): form.data["source"] = "Goodreads" form.data["privacy"] = "public" form.data["include_reviews"] = False - csv_file = pathlib.Path(__file__).parent.joinpath("../../data/goodreads.csv") - form.data["csv_file"] = SimpleUploadedFile( - # pylint: disable=consider-using-with - csv_file, - open(csv_file, "rb").read(), - content_type="text/csv", - ) + csv_path = pathlib.Path(__file__).parent.joinpath("../../data/goodreads.csv") + with open(csv_path, "rb") as csv_file: + form.data["csv_file"] = SimpleUploadedFile( + csv_path, + csv_file.read(), + content_type="text/csv", + ) request = self.factory.post("", form.data) request.user = self.local_user diff --git a/bookwyrm/tests/views/imports/test_user_import.py b/bookwyrm/tests/views/imports/test_user_import.py index 4a676a57f..a8214e74e 100644 --- a/bookwyrm/tests/views/imports/test_user_import.py +++ b/bookwyrm/tests/views/imports/test_user_import.py @@ -47,16 +47,16 @@ class ImportUserViews(TestCase): view = views.UserImport.as_view() form = forms.ImportUserForm() - archive_file = pathlib.Path(__file__).parent.joinpath( + archive_path = 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", - ) + with open(archive_path, "rb") as archive_file: + form.data["archive_file"] = SimpleUploadedFile( + archive_path, + archive_file.read(), + content_type="application/gzip", + ) form.data["include_user_settings"] = "" form.data["include_goals"] = "on" diff --git a/bookwyrm/tests/views/preferences/test_edit_user.py b/bookwyrm/tests/views/preferences/test_edit_user.py index 7872e8f6e..c31c8237e 100644 --- a/bookwyrm/tests/views/preferences/test_edit_user.py +++ b/bookwyrm/tests/views/preferences/test_edit_user.py @@ -96,13 +96,13 @@ class EditUserViews(TestCase): form.data["email"] = "wow@email.com" form.data["default_post_privacy"] = "public" form.data["preferred_timezone"] = "UTC" - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../../static/images/no_cover.jpg" ) - # pylint: disable=consider-using-with - form.data["avatar"] = SimpleUploadedFile( - image_file, open(image_file, "rb").read(), content_type="image/jpeg" - ) + with open(image_path, "rb") as image_file: + form.data["avatar"] = SimpleUploadedFile( + image_path, image_file.read(), content_type="image/jpeg" + ) request = self.factory.post("", form.data) request.user = self.local_user @@ -119,12 +119,12 @@ class EditUserViews(TestCase): def test_crop_avatar(self, _): """reduce that image size""" - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../../static/images/no_cover.jpg" ) - image = Image.open(image_file) - result = views.preferences.edit_user.crop_avatar(image) + with Image.open(image_path) as image: + result = views.preferences.edit_user.crop_avatar(image) self.assertIsInstance(result, ContentFile) - image_result = Image.open(result) - self.assertEqual(image_result.size, (120, 120)) + with Image.open(result) as image_result: + self.assertEqual(image_result.size, (120, 120)) diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index a57be1023..be4956c64 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -1,10 +1,7 @@ """ test for app action functionality """ -from io import BytesIO from unittest.mock import patch import pathlib -from PIL import Image -from django.core.files.base import ContentFile from django.http import Http404 from django.template.response import TemplateResponse from django.test import TestCase @@ -142,12 +139,9 @@ class FeedViews(TestCase): """there are so many views, this just makes sure it LOADS""" view = views.Status.as_view() - image_file = pathlib.Path(__file__).parent.joinpath( + image_path = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) - image = Image.open(image_file) - output = BytesIO() - image.save(output, format=image.format) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): status = models.Review.objects.create( content="hi", @@ -157,7 +151,8 @@ class FeedViews(TestCase): attachment = models.Image.objects.create( status=status, caption="alt text here" ) - attachment.image.save("test.jpg", ContentFile(output.getvalue())) + with open(image_path, "rb") as image_file: + attachment.image.save("test.jpg", image_file) request = self.factory.get("") request.user = self.local_user From f66695193497adc5b8d864b346c8a013ce359732 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Sat, 30 Mar 2024 21:56:41 +0100 Subject: [PATCH 09/10] Update CodeQL workflows to v3 https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/ --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 51316ef62..014745a52 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -40,7 +40,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -51,7 +51,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -65,4 +65,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 From 4bbdd0b2d0f4e97e3f9e50aadff437b11276e1a9 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Tue, 2 Apr 2024 21:54:30 +0200 Subject: [PATCH 10/10] Add index on Status.remote_id This field is often used in WHERE-clauses in queries that are very slow on bookwyrm.social. --- ...9_status_bookwyrm_st_remote__06aeba_idx.py | 19 +++++++++++++++++++ bookwyrm/models/status.py | 3 +++ 2 files changed, 22 insertions(+) create mode 100644 bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py diff --git a/bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py b/bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py new file mode 100644 index 000000000..5d2513698 --- /dev/null +++ b/bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.25 on 2024-04-02 19:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0198_book_search_vector_author_aliases"), + ] + + operations = [ + migrations.AddIndex( + model_name="status", + index=models.Index( + fields=["remote_id"], name="bookwyrm_st_remote__06aeba_idx" + ), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index f6235dab6..a9c678cb5 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -80,6 +80,9 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """default sorting""" ordering = ("-published_date",) + indexes = [ + models.Index(fields=["remote_id"]), + ] def save(self, *args, **kwargs): """save and notify"""