Skip to content

Commit

Permalink
Bracket-wrap calls to patch() for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Mar 17, 2024
1 parent 8cf52e0 commit 1b9e054
Show file tree
Hide file tree
Showing 123 changed files with 883 additions and 559 deletions.
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitypub/test_base_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "mouseword", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitypub/test_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "mouseword", local=True, localname="mouse"
)
Expand Down
16 changes: 10 additions & 6 deletions bookwyrm/tests/activitystreams/test_abstractstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down Expand Up @@ -105,9 +107,11 @@ def test_get_activity_stream(self, *_):
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)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitystreams/test_booksstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitystreams/test_homestream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitystreams/test_localstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitystreams/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/activitystreams/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
13 changes: 8 additions & 5 deletions bookwyrm/tests/connectors/test_inventaire_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,14 @@ def test_get_edition_from_work_data(self):
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)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/importers/test_calibre_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def setUp(self):
@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", "[email protected]", "password", local=True
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/importers/test_goodreads_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def setUp(self):
@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", "[email protected]", "password", local=True
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/importers/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def setUp(self):
@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", "[email protected]", "password", local=True
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/importers/test_librarything_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ def setUp(self):
@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", "[email protected]", "password", local=True
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/importers/test_openlibrary_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def setUp(self):
@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", "[email protected]", "password", local=True
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/importers/test_storygraph_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def setUp(self):
@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", "[email protected]", "password", local=True
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/lists_stream/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/lists_stream/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
15 changes: 9 additions & 6 deletions bookwyrm/tests/lists_stream/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand All @@ -36,9 +38,10 @@ def setUpTestData(self): # pylint: disable=bad-classmethod-argument
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"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/management/test_populate_lists_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down
17 changes: 9 additions & 8 deletions bookwyrm/tests/management/test_populate_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "password", local=True, localname="mouse"
)
Expand Down Expand Up @@ -53,11 +55,10 @@ def test_populate_streams(self, _):
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
8 changes: 5 additions & 3 deletions bookwyrm/tests/models/test_activitypub_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "mouseword", local=True, localname="mouse"
)
Expand Down
8 changes: 5 additions & 3 deletions bookwyrm/tests/models/test_automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"[email protected]",
"[email protected]",
Expand Down
Loading

0 comments on commit 1b9e054

Please sign in to comment.