1
0
Fork 0

Use setUpTestData() to speed up tests

Pylint's `bad-classmethod-argument` is disabled for each definition
to avoid rewriting the method bodies just to rename `self` → `cls`.
This can be done gradually, as the setUpTestData methods are modified
along the way.
This commit is contained in:
Adeodato Simó 2023-11-30 02:56:16 -03:00
parent cf1afefc84
commit 9d502f5ee2
No known key found for this signature in database
GPG key ID: CDF447845F1A986F
129 changed files with 644 additions and 327 deletions

View file

@ -11,7 +11,7 @@ from bookwyrm.settings import DOMAIN
from bookwyrm.tests.validate_html import validate_html
# pylint: disable=invalid-name
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class StatusTransactions(TransactionTestCase):
"""Test full database transactions"""
@ -74,9 +74,9 @@ class StatusTransactions(TransactionTestCase):
class StatusViews(TestCase):
"""viewing and creating statuses"""
def setUp(self):
@classmethod
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
"""we need basic test data and mocks"""
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
@ -106,7 +106,6 @@ class StatusViews(TestCase):
inbox="https://example.com/users/rat/inbox",
outbox="https://example.com/users/rat/outbox",
)
work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create(
title="Example Edition",
@ -115,6 +114,10 @@ class StatusViews(TestCase):
)
models.SiteSettings.objects.create()
def setUp(self):
"""individual test setup"""
self.factory = RequestFactory()
def test_create_status_comment(self, *_):
"""create a status"""
view = views.CreateStatus.as_view()
@ -323,14 +326,14 @@ class StatusViews(TestCase):
def test_find_mentions_unknown_remote(self, *_):
"""mention a user that isn't in the database"""
with patch("bookwyrm.views.status.handle_remote_webfinger") as rw:
rw.return_value = self.another_user
with patch("bookwyrm.views.status.handle_remote_webfinger") as rwf:
rwf.return_value = self.another_user
result = find_mentions(self.local_user, "@beep@beep.com")
self.assertEqual(result["@nutria"], self.another_user)
self.assertEqual(result[f"@nutria@{DOMAIN}"], self.another_user)
with patch("bookwyrm.views.status.handle_remote_webfinger") as rw:
rw.return_value = None
with patch("bookwyrm.views.status.handle_remote_webfinger") as rwf:
rwf.return_value = None
result = find_mentions(self.local_user, "@beep@beep.com")
self.assertEqual(result, {})