-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3320 from dato/better-fmt-patch-calls
bulk-fmt: bracket-wrap calls to patch() for better readability
- Loading branch information
Showing
133 changed files
with
1,507 additions
and
1,191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,16 +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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "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") | ||
|
@@ -232,10 +234,12 @@ def test_to_model_one_to_many(self, *_): | |
) | ||
|
||
# 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "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" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
"[email protected]", | ||
"mouseword", | ||
|
@@ -23,7 +23,7 @@ def setUpTestData(self): # pylint: disable=bad-classmethod-argument | |
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", | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,23 +16,25 @@ 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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "password", local=True, localname="mouse" | ||
) | ||
self.another_user = models.User.objects.create_user( | ||
cls.another_user = models.User.objects.create_user( | ||
"nutria", | ||
"[email protected]", | ||
"password", | ||
local=True, | ||
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", | ||
"[email protected]", | ||
"ratword", | ||
|
@@ -42,7 +44,7 @@ def setUpTestData(self): # pylint: disable=bad-classmethod-argument | |
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""" | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "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", | ||
"[email protected]", | ||
"ratword", | ||
|
@@ -34,7 +36,7 @@ def setUpTestData(self): # pylint: disable=bad-classmethod-argument | |
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""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,23 +13,25 @@ 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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "password", local=True, localname="mouse" | ||
) | ||
self.another_user = models.User.objects.create_user( | ||
cls.another_user = models.User.objects.create_user( | ||
"nutria", | ||
"[email protected]", | ||
"password", | ||
local=True, | ||
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", | ||
"[email protected]", | ||
"ratword", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,23 +13,25 @@ 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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "password", local=True, localname="mouse" | ||
) | ||
self.another_user = models.User.objects.create_user( | ||
cls.another_user = models.User.objects.create_user( | ||
"nutria", | ||
"[email protected]", | ||
"password", | ||
local=True, | ||
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", | ||
"[email protected]", | ||
"ratword", | ||
|
@@ -39,7 +41,7 @@ def setUpTestData(self): # pylint: disable=bad-classmethod-argument | |
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""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "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", | ||
"[email protected]", | ||
"ratword", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,23 +8,25 @@ 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( | ||
with ( | ||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), | ||
patch("bookwyrm.activitystreams.populate_stream_task.delay"), | ||
patch("bookwyrm.lists_stream.populate_lists_task.delay"), | ||
): | ||
cls.local_user = models.User.objects.create_user( | ||
"mouse", "[email protected]", "password", local=True, localname="mouse" | ||
) | ||
self.another_user = models.User.objects.create_user( | ||
cls.another_user = models.User.objects.create_user( | ||
"nutria", | ||
"[email protected]", | ||
"password", | ||
local=True, | ||
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", | ||
"[email protected]", | ||
"ratword", | ||
|
@@ -34,11 +36,9 @@ def setUpTestData(self): # pylint: disable=bad-classmethod-argument | |
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""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.