From b7965ce2aef2e4984154c00696ab5d45d4de3206 Mon Sep 17 00:00:00 2001 From: Joachim Date: Thu, 27 May 2021 21:37:27 +0200 Subject: [PATCH] Fix tests --- bookwyrm/tests/activitypub/test_person.py | 5 +- bookwyrm/tests/activitypub/test_quotation.py | 21 ++-- .../tests/connectors/test_self_connector.py | 2 +- .../tests/management/test_populate_streams.py | 20 ++-- .../tests/models/test_activitypub_mixin.py | 108 +++++++++--------- bookwyrm/tests/models/test_base_model.py | 20 ++-- .../tests/models/test_federated_server.py | 47 ++++---- .../tests/models/test_relationship_models.py | 20 ++-- bookwyrm/tests/models/test_status_model.py | 29 ++--- bookwyrm/tests/models/test_user_model.py | 19 +-- bookwyrm/tests/test_activitystreams.py | 20 ++-- bookwyrm/tests/test_signing.py | 34 +++--- bookwyrm/tests/test_templatetags.py | 37 +++--- bookwyrm/tests/views/inbox/test_inbox.py | 20 ++-- bookwyrm/tests/views/inbox/test_inbox_add.py | 20 ++-- .../tests/views/inbox/test_inbox_announce.py | 20 ++-- .../tests/views/inbox/test_inbox_block.py | 20 ++-- .../tests/views/inbox/test_inbox_create.py | 20 ++-- .../tests/views/inbox/test_inbox_delete.py | 23 ++-- .../tests/views/inbox/test_inbox_follow.py | 20 ++-- bookwyrm/tests/views/inbox/test_inbox_like.py | 20 ++-- .../tests/views/inbox/test_inbox_remove.py | 20 ++-- .../tests/views/inbox/test_inbox_update.py | 20 ++-- bookwyrm/tests/views/test_block.py | 20 ++-- bookwyrm/tests/views/test_federation.py | 20 ++-- bookwyrm/tests/views/test_follow.py | 20 ++-- bookwyrm/tests/views/test_helpers.py | 22 ++-- bookwyrm/tests/views/test_interaction.py | 20 ++-- bookwyrm/tests/views/test_reading.py | 20 ++-- bookwyrm/tests/views/test_status.py | 20 ++-- bookwyrm/tests/views/test_wellknown.py | 20 ++-- 31 files changed, 380 insertions(+), 367 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_person.py b/bookwyrm/tests/activitypub/test_person.py index 67aaf891..20dbcdfb 100644 --- a/bookwyrm/tests/activitypub/test_person.py +++ b/bookwyrm/tests/activitypub/test_person.py @@ -20,8 +20,9 @@ class Person(TestCase): def test_user_to_model(self): activity = activitypub.Person(**self.user_data) - with patch("bookwyrm.models.user.set_remote_server.delay"): - user = activity.to_model(model=models.User) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + user = activity.to_model(model=models.User) self.assertEqual(user.username, "mouse@example.com") self.assertEqual(user.remote_id, "https://example.com/user/mouse") self.assertFalse(user.local) diff --git a/bookwyrm/tests/activitypub/test_quotation.py b/bookwyrm/tests/activitypub/test_quotation.py index 7d1b2869..59d4b1b6 100644 --- a/bookwyrm/tests/activitypub/test_quotation.py +++ b/bookwyrm/tests/activitypub/test_quotation.py @@ -12,16 +12,17 @@ class Quotation(TestCase): def setUp(self): """model objects we'll need""" - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.user = models.User.objects.create_user( - "mouse", - "mouse@mouse.mouse", - "mouseword", - local=False, - inbox="https://example.com/user/mouse/inbox", - outbox="https://example.com/user/mouse/outbox", - remote_id="https://example.com/user/mouse", - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.user = models.User.objects.create_user( + "mouse", + "mouse@mouse.mouse", + "mouseword", + local=False, + inbox="https://example.com/user/mouse/inbox", + outbox="https://example.com/user/mouse/outbox", + remote_id="https://example.com/user/mouse", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.book = models.Edition.objects.create( title="Example Edition", diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index e49d9671..e6e64a7d 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -82,7 +82,7 @@ class SelfConnector(TestCase): def test_search_multiple_editions(self): """it should get rid of duplicate editions for the same work""" - with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): work = models.Work.objects.create(title="Work Title") edition_1 = models.Edition.objects.create( title="Edition 1 Title", parent_work=work diff --git a/bookwyrm/tests/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index f6d24c53..1705cd34 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -23,16 +23,16 @@ class Activitystreams(TestCase): local=True, localname="nutria", ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.book = models.Edition.objects.create(title="test book") diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 348270ed..020d031d 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -25,16 +25,16 @@ class ActivitypubMixins(TestCase): ) self.local_user.remote_id = "http://example.com/a/b" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) self.object_mock = { "to": "to field", @@ -143,16 +143,17 @@ class ActivitypubMixins(TestCase): MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) - with patch("bookwyrm.models.user.set_remote_server.delay"): - another_remote_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.com", - "nutriaword", - local=False, - remote_id="https://example.com/users/nutria", - inbox="https://example.com/users/nutria/inbox", - outbox="https://example.com/users/nutria/outbox", - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + another_remote_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.com", + "nutriaword", + local=False, + remote_id="https://example.com/users/nutria", + inbox="https://example.com/users/nutria/inbox", + outbox="https://example.com/users/nutria/outbox", + ) MockSelf = namedtuple("Self", ("privacy", "user", "recipients")) mock_self = MockSelf("public", self.local_user, [another_remote_user]) @@ -166,16 +167,17 @@ class ActivitypubMixins(TestCase): MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) - with patch("bookwyrm.models.user.set_remote_server.delay"): - another_remote_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.com", - "nutriaword", - local=False, - remote_id="https://example.com/users/nutria", - inbox="https://example.com/users/nutria/inbox", - outbox="https://example.com/users/nutria/outbox", - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + another_remote_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.com", + "nutriaword", + local=False, + remote_id="https://example.com/users/nutria", + inbox="https://example.com/users/nutria/inbox", + outbox="https://example.com/users/nutria/outbox", + ) MockSelf = namedtuple("Self", ("privacy", "user", "recipients")) mock_self = MockSelf("direct", self.local_user, [another_remote_user]) @@ -187,17 +189,18 @@ class ActivitypubMixins(TestCase): """should combine users with the same shared_inbox""" self.remote_user.shared_inbox = "http://example.com/inbox" self.remote_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - another_remote_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.com", - "nutriaword", - local=False, - remote_id="https://example.com/users/nutria", - inbox="https://example.com/users/nutria/inbox", - shared_inbox="http://example.com/inbox", - outbox="https://example.com/users/nutria/outbox", - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + another_remote_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.com", + "nutriaword", + local=False, + remote_id="https://example.com/users/nutria", + inbox="https://example.com/users/nutria/inbox", + shared_inbox="http://example.com/inbox", + outbox="https://example.com/users/nutria/outbox", + ) MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) @@ -209,17 +212,18 @@ class ActivitypubMixins(TestCase): def test_get_recipients_software(self, _): """should differentiate between bookwyrm and other remote users""" - with patch("bookwyrm.models.user.set_remote_server.delay"): - another_remote_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.com", - "nutriaword", - local=False, - remote_id="https://example.com/users/nutria", - inbox="https://example.com/users/nutria/inbox", - outbox="https://example.com/users/nutria/outbox", - bookwyrm_user=False, - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + another_remote_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.com", + "nutriaword", + local=False, + remote_id="https://example.com/users/nutria", + inbox="https://example.com/users/nutria/inbox", + outbox="https://example.com/users/nutria/outbox", + bookwyrm_user=False, + ) MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index 8b0e55b7..496a8610 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -16,16 +16,16 @@ class BaseModel(TestCase): self.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( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) class BookWyrmTestModel(base_model.BookWyrmModel): """just making it not abstract""" diff --git a/bookwyrm/tests/models/test_federated_server.py b/bookwyrm/tests/models/test_federated_server.py index 43724568..fabd69ee 100644 --- a/bookwyrm/tests/models/test_federated_server.py +++ b/bookwyrm/tests/models/test_federated_server.py @@ -11,29 +11,30 @@ class FederatedServer(TestCase): def setUp(self): """we'll need a user""" self.server = models.FederatedServer.objects.create(server_name="test.server") - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - federated_server=self.server, - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) - self.inactive_remote_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.com", - "nutriaword", - federated_server=self.server, - local=False, - remote_id="https://example.com/users/nutria", - inbox="https://example.com/users/nutria/inbox", - outbox="https://example.com/users/nutria/outbox", - is_active=False, - deactivation_reason="self_deletion", - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + federated_server=self.server, + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) + self.inactive_remote_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.com", + "nutriaword", + federated_server=self.server, + local=False, + remote_id="https://example.com/users/nutria", + inbox="https://example.com/users/nutria/inbox", + outbox="https://example.com/users/nutria/outbox", + is_active=False, + deactivation_reason="self_deletion", + ) def test_block_unblock(self): """block a server and all users on it""" diff --git a/bookwyrm/tests/models/test_relationship_models.py b/bookwyrm/tests/models/test_relationship_models.py index 516bfeb1..0a630dd1 100644 --- a/bookwyrm/tests/models/test_relationship_models.py +++ b/bookwyrm/tests/models/test_relationship_models.py @@ -10,17 +10,17 @@ class Relationship(TestCase): def setUp(self): """we need some users for this""" - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 0005c507..db4475c7 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -25,16 +25,16 @@ class Status(TestCase): self.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( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.book = models.Edition.objects.create(title="Test Edition") @@ -356,11 +356,12 @@ class Status(TestCase): status = models.Status.objects.create( content="test content", user=self.local_user ) - fav = models.Favorite.objects.create(status=status, user=self.local_user) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + fav = models.Favorite.objects.create(status=status, user=self.local_user) - # can't fav a status twice - with self.assertRaises(IntegrityError): - models.Favorite.objects.create(status=status, user=self.local_user) + # can't fav a status twice + with self.assertRaises(IntegrityError): + models.Favorite.objects.create(status=status, user=self.local_user) activity = fav.to_activity() self.assertEqual(activity["type"], "Like") diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index 96ec955a..b6c71663 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -35,15 +35,16 @@ class User(TestCase): self.assertIsNotNone(self.user.key_pair.public_key) def test_remote_user(self): - with patch("bookwyrm.models.user.set_remote_server.delay"): - user = models.User.objects.create_user( - "rat", - "rat@rat.rat", - "ratword", - local=False, - remote_id="https://example.com/dfjkg", - bookwyrm_user=False, - ) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.set_remote_server.delay"): + user = models.User.objects.create_user( + "rat", + "rat@rat.rat", + "ratword", + local=False, + remote_id="https://example.com/dfjkg", + bookwyrm_user=False, + ) self.assertEqual(user.username, "rat@example.com") def test_user_shelves(self): diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index bbd6dff9..da335e89 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -22,16 +22,16 @@ class Activitystreams(TestCase): local=True, localname="nutria", ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.book = models.Edition.objects.create(title="test book") diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index 5a2f1b74..b9b1af26 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -119,9 +119,10 @@ class Signature(TestCase): status=200, ) - with patch("bookwyrm.models.user.get_remote_reviews.delay"): - response = self.send_test_request(sender=self.fake_remote) - self.assertEqual(response.status_code, 200) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.get_remote_reviews.delay"): + response = self.send_test_request(sender=self.fake_remote) + self.assertEqual(response.status_code, 200) @responses.activate def test_key_needs_refresh(self): @@ -142,22 +143,23 @@ class Signature(TestCase): data["publicKey"]["publicKeyPem"] = key_pair.public_key responses.add(responses.GET, self.fake_remote.remote_id, json=data, status=200) - with patch("bookwyrm.models.user.get_remote_reviews.delay"): - # Key correct: - response = self.send_test_request(sender=self.fake_remote) - self.assertEqual(response.status_code, 200) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + with patch("bookwyrm.models.user.get_remote_reviews.delay"): + # Key correct: + response = self.send_test_request(sender=self.fake_remote) + self.assertEqual(response.status_code, 200) - # Old key is cached, so still works: - response = self.send_test_request(sender=self.fake_remote) - self.assertEqual(response.status_code, 200) + # Old key is cached, so still works: + response = self.send_test_request(sender=self.fake_remote) + self.assertEqual(response.status_code, 200) - # Try with new key: - response = self.send_test_request(sender=new_sender) - self.assertEqual(response.status_code, 200) + # Try with new key: + response = self.send_test_request(sender=new_sender) + self.assertEqual(response.status_code, 200) - # Now the old key will fail: - response = self.send_test_request(sender=self.fake_remote) - self.assertEqual(response.status_code, 401) + # Now the old key will fail: + response = self.send_test_request(sender=self.fake_remote) + self.assertEqual(response.status_code, 401) @responses.activate def test_nonexistent_signer(self): diff --git a/bookwyrm/tests/test_templatetags.py b/bookwyrm/tests/test_templatetags.py index a472ac74..9a215cad 100644 --- a/bookwyrm/tests/test_templatetags.py +++ b/bookwyrm/tests/test_templatetags.py @@ -29,14 +29,14 @@ class TemplateTags(TestCase): local=True, localname="mouse", ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.rat", - "ratword", - remote_id="http://example.com/rat", - local=False, - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.rat", + "ratword", + remote_id="http://example.com/rat", + local=False, + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.book = models.Edition.objects.create(title="Test Book") @@ -146,19 +146,20 @@ class TemplateTags(TestCase): def test_get_book_description(self, _): """grab it from the edition or the parent""" - work = models.Work.objects.create(title="Test Work") - self.book.parent_work = work - self.book.save() + with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): + work = models.Work.objects.create(title="Test Work") + self.book.parent_work = work + self.book.save() - self.assertIsNone(bookwyrm_tags.get_book_description(self.book)) + self.assertIsNone(bookwyrm_tags.get_book_description(self.book)) - work.description = "hi" - work.save() - self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hi") + work.description = "hi" + work.save() + self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hi") - self.book.description = "hello" - self.book.save() - self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello") + self.book.description = "hello" + self.book.save() + self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello") def test_get_uuid(self, _): """uuid functionality""" diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py index ccd3a5e5..0ac813bb 100644 --- a/bookwyrm/tests/views/inbox/test_inbox.py +++ b/bookwyrm/tests/views/inbox/test_inbox.py @@ -29,16 +29,16 @@ class Inbox(TestCase): ) local_user.remote_id = "https://example.com/user/mouse" local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) self.create_json = { "id": "hi", "type": "Create", diff --git a/bookwyrm/tests/views/inbox/test_inbox_add.py b/bookwyrm/tests/views/inbox/test_inbox_add.py index c1fd90fe..2862fdf5 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_add.py +++ b/bookwyrm/tests/views/inbox/test_inbox_add.py @@ -23,16 +23,16 @@ class InboxAdd(TestCase): ) local_user.remote_id = "https://example.com/user/mouse" local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): work = models.Work.objects.create(title="work title") self.book = models.Edition.objects.create( diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index 853266ed..4815c689 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -23,16 +23,16 @@ class InboxActivities(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.activitystreams.ActivityStream.add_status"): diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index 310a6fa6..8c12e42b 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -22,16 +22,16 @@ class InboxBlock(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"): models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index 3f677bd2..a885239b 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -25,6 +25,16 @@ class InboxCreate(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.activitystreams.ActivityStream.add_status"): self.status = models.Status.objects.create( @@ -32,16 +42,6 @@ class InboxCreate(TestCase): content="Test status", remote_id="https://example.com/status/1", ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) self.create_json = { "id": "hi", diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 07b286a5..067a30ad 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -23,16 +23,16 @@ class InboxActivities(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.activitystreams.ActivityStream.add_status"): self.status = models.Status.objects.create( user=self.remote_user, @@ -119,7 +119,8 @@ class InboxActivities(TestCase): "object": self.remote_user.remote_id, } - views.inbox.activity_task(activity) + with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"): + views.inbox.activity_task(activity) self.assertFalse(models.User.objects.get(username="rat@example.com").is_active) def test_delete_user_unknown(self): diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index 5d5dcd4e..063ad5d3 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -23,17 +23,17 @@ class InboxRelationships(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"): 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 aa10f93f..5d072fb0 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -22,16 +22,16 @@ class InboxActivities(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.activitystreams.ActivityStream.add_status"): diff --git a/bookwyrm/tests/views/inbox/test_inbox_remove.py b/bookwyrm/tests/views/inbox/test_inbox_remove.py index 3c2e72d6..2812ef1f 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_remove.py +++ b/bookwyrm/tests/views/inbox/test_inbox_remove.py @@ -22,16 +22,16 @@ class InboxRemove(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.work = models.Work.objects.create(title="work title") diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index 78d694a2..39ac4a89 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -24,16 +24,16 @@ class InboxUpdate(TestCase): ) self.local_user.remote_id = "https://example.com/user/mouse" self.local_user.save(broadcast=False) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) self.create_json = { "id": "hi", diff --git a/bookwyrm/tests/views/test_block.py b/bookwyrm/tests/views/test_block.py index 80d20f11..d640617c 100644 --- a/bookwyrm/tests/views/test_block.py +++ b/bookwyrm/tests/views/test_block.py @@ -22,16 +22,16 @@ class BlockViews(TestCase): local=True, localname="mouse", ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"): models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_federation.py b/bookwyrm/tests/views/test_federation.py index b4d81d54..9ff12255 100644 --- a/bookwyrm/tests/views/test_federation.py +++ b/bookwyrm/tests/views/test_federation.py @@ -23,16 +23,16 @@ class FederationViews(TestCase): local=True, localname="mouse", ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"): models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index 8ea8accc..f37370cc 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -25,16 +25,16 @@ class BookViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - with patch("bookwyrm.models.user.set_remote_server"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@email.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@email.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + 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( Permission.objects.create( diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index bc99e69f..f0807c55 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -29,6 +29,17 @@ class ViewsHelpers(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) + with patch("bookwyrm.models.user.set_remote_server.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", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( @@ -36,17 +47,6 @@ class ViewsHelpers(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, ) - with patch("bookwyrm.models.user.set_remote_server.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", - ) datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") self.userdata = json.loads(datafile.read_bytes()) del self.userdata["icon"] diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 208d270c..cb974dcd 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -23,16 +23,16 @@ class InteractionViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - with patch("bookwyrm.models.user.set_remote_server"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@email.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@email.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): work = models.Work.objects.create(title="Test Work") diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 5a59ab99..1ffdde73 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -24,6 +24,16 @@ class ReadingViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@rat.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( @@ -31,16 +41,6 @@ class ReadingViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@rat.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) def test_start_reading(self, _): """begin a book""" diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index c12fd0c4..9253e6e5 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -24,16 +24,16 @@ class StatusViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - with patch("bookwyrm.models.user.set_remote_server"): - self.remote_user = models.User.objects.create_user( - "rat", - "rat@email.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server"): + self.remote_user = models.User.objects.create_user( + "rat", + "rat@email.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"): work = models.Work.objects.create(title="Test Work") diff --git a/bookwyrm/tests/views/test_wellknown.py b/bookwyrm/tests/views/test_wellknown.py index bd291d04..839240ed 100644 --- a/bookwyrm/tests/views/test_wellknown.py +++ b/bookwyrm/tests/views/test_wellknown.py @@ -27,16 +27,16 @@ class UserViews(TestCase): models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" ) - with patch("bookwyrm.models.user.set_remote_server.delay"): - models.User.objects.create_user( - "rat", - "rat@remote.com", - "ratword", - local=False, - remote_id="https://example.com/users/rat", - inbox="https://example.com/users/rat/inbox", - outbox="https://example.com/users/rat/outbox", - ) + with patch("bookwyrm.models.user.set_remote_server.delay"): + models.User.objects.create_user( + "rat", + "rat@remote.com", + "ratword", + local=False, + remote_id="https://example.com/users/rat", + inbox="https://example.com/users/rat/inbox", + outbox="https://example.com/users/rat/outbox", + ) with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"): models.SiteSettings.objects.create() self.anonymous_user = AnonymousUser