Fixes model tests

This commit is contained in:
Mouse Reeve
2021-03-23 10:41:18 -07:00
parent 9e23bfe7c0
commit 7f271dbde7
4 changed files with 54 additions and 50 deletions

View File

@ -13,6 +13,7 @@ from bookwyrm.models.activitypub_mixin import ActivitypubMixin
from bookwyrm.models.activitypub_mixin import ActivityMixin, ObjectMixin
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
class ActivitypubMixins(TestCase):
""" functionality shared across models """
@ -44,7 +45,7 @@ class ActivitypubMixins(TestCase):
}
# ActivitypubMixin
def test_to_activity(self):
def test_to_activity(self, _):
""" model to ActivityPub json """
@dataclass(init=False)
@ -65,7 +66,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(activity["id"], "https://www.example.com/test")
self.assertEqual(activity["type"], "Test")
def test_find_existing_by_remote_id(self):
def test_find_existing_by_remote_id(self, _):
""" attempt to match a remote id to an object in the db """
# uses a different remote id scheme
# this isn't really part of this test directly but it's helpful to state
@ -98,7 +99,7 @@ class ActivitypubMixins(TestCase):
# test subclass match
result = models.Status.find_existing_by_remote_id("https://comment.net")
def test_find_existing(self):
def test_find_existing(self, _):
""" match a blob of data to a model """
book = models.Edition.objects.create(
title="Test edition",
@ -108,7 +109,7 @@ class ActivitypubMixins(TestCase):
result = models.Edition.find_existing({"openlibraryKey": "OL1234"})
self.assertEqual(result, book)
def test_get_recipients_public_object(self):
def test_get_recipients_public_object(self, _):
""" determines the recipients for an object's broadcast """
MockSelf = namedtuple("Self", ("privacy"))
mock_self = MockSelf("public")
@ -116,7 +117,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(len(recipients), 1)
self.assertEqual(recipients[0], self.remote_user.inbox)
def test_get_recipients_public_user_object_no_followers(self):
def test_get_recipients_public_user_object_no_followers(self, _):
""" determines the recipients for a user's object broadcast """
MockSelf = namedtuple("Self", ("privacy", "user"))
mock_self = MockSelf("public", self.local_user)
@ -124,7 +125,7 @@ class ActivitypubMixins(TestCase):
recipients = ActivitypubMixin.get_recipients(mock_self)
self.assertEqual(len(recipients), 0)
def test_get_recipients_public_user_object(self):
def test_get_recipients_public_user_object(self, _):
""" determines the recipients for a user's object broadcast """
MockSelf = namedtuple("Self", ("privacy", "user"))
mock_self = MockSelf("public", self.local_user)
@ -134,7 +135,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(len(recipients), 1)
self.assertEqual(recipients[0], self.remote_user.inbox)
def test_get_recipients_public_user_object_with_mention(self):
def test_get_recipients_public_user_object_with_mention(self, _):
""" determines the recipients for a user's object broadcast """
MockSelf = namedtuple("Self", ("privacy", "user"))
mock_self = MockSelf("public", self.local_user)
@ -157,7 +158,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(recipients[0], another_remote_user.inbox)
self.assertEqual(recipients[1], self.remote_user.inbox)
def test_get_recipients_direct(self):
def test_get_recipients_direct(self, _):
""" determines the recipients for a user's object broadcast """
MockSelf = namedtuple("Self", ("privacy", "user"))
mock_self = MockSelf("public", self.local_user)
@ -179,7 +180,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(len(recipients), 1)
self.assertEqual(recipients[0], another_remote_user.inbox)
def test_get_recipients_combine_inboxes(self):
def test_get_recipients_combine_inboxes(self, _):
""" should combine users with the same shared_inbox """
self.remote_user.shared_inbox = "http://example.com/inbox"
self.remote_user.save(broadcast=False)
@ -203,7 +204,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(len(recipients), 1)
self.assertEqual(recipients[0], "http://example.com/inbox")
def test_get_recipients_software(self):
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(
@ -233,7 +234,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(recipients[0], another_remote_user.inbox)
# ObjectMixin
def test_object_save_create(self):
def test_object_save_create(self, _):
""" should save uneventufully when broadcast is disabled """
class Success(Exception):
@ -264,7 +265,7 @@ class ActivitypubMixins(TestCase):
ObjectModel(user=self.local_user).save(broadcast=False)
ObjectModel(user=None).save()
def test_object_save_update(self):
def test_object_save_update(self, _):
""" should save uneventufully when broadcast is disabled """
class Success(Exception):
@ -290,7 +291,7 @@ class ActivitypubMixins(TestCase):
with self.assertRaises(Success):
UpdateObjectModel(id=1, last_edited_by=self.local_user).save()
def test_object_save_delete(self):
def test_object_save_delete(self, _):
""" should create delete activities when objects are deleted by flag """
class ActivitySuccess(Exception):
@ -312,7 +313,7 @@ class ActivitypubMixins(TestCase):
with self.assertRaises(ActivitySuccess):
DeletableObjectModel(id=1, user=self.local_user, deleted=True).save()
def test_to_delete_activity(self):
def test_to_delete_activity(self, _):
""" wrapper for Delete activity """
MockSelf = namedtuple("Self", ("remote_id", "to_activity"))
mock_self = MockSelf(
@ -327,7 +328,7 @@ class ActivitypubMixins(TestCase):
activity["cc"], ["https://www.w3.org/ns/activitystreams#Public"]
)
def test_to_update_activity(self):
def test_to_update_activity(self, _):
""" ditto above but for Update """
MockSelf = namedtuple("Self", ("remote_id", "to_activity"))
mock_self = MockSelf(
@ -345,7 +346,7 @@ class ActivitypubMixins(TestCase):
self.assertIsInstance(activity["object"], dict)
# Activity mixin
def test_to_undo_activity(self):
def test_to_undo_activity(self, _):
""" and again, for Undo """
MockSelf = namedtuple("Self", ("remote_id", "to_activity", "user"))
mock_self = MockSelf(