From 9e23bfe7c0677efebebf87868f66ff3ece39d6e8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 23 Mar 2021 10:25:52 -0700 Subject: [PATCH] Updates activitypub tests --- .../tests/activitypub/test_base_activity.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index f3d3decde..8ec0b703f 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -19,6 +19,7 @@ from bookwyrm.activitypub import ActivitySerializerError from bookwyrm import models +@patch("bookwyrm.activitystreams.ActivityStream.add_status") class BaseActivity(TestCase): """ the super class for model-linked activitypub dataclasses """ @@ -43,24 +44,24 @@ class BaseActivity(TestCase): image.save(output, format=image.format) self.image_data = output.getvalue() - def test_init(self): + def test_init(self, _): """ simple successfuly init """ instance = ActivityObject(id="a", type="b") self.assertTrue(hasattr(instance, "id")) self.assertTrue(hasattr(instance, "type")) - def test_init_missing(self): + def test_init_missing(self, _): """ init with missing required params """ with self.assertRaises(ActivitySerializerError): ActivityObject() - def test_init_extra_fields(self): + def test_init_extra_fields(self, _): """ init ignoring additional fields """ instance = ActivityObject(id="a", type="b", fish="c") self.assertTrue(hasattr(instance, "id")) self.assertTrue(hasattr(instance, "type")) - def test_init_default_field(self): + def test_init_default_field(self, _): """ replace an existing required field with a default field """ @dataclass(init=False) @@ -73,7 +74,7 @@ class BaseActivity(TestCase): self.assertEqual(instance.id, "a") self.assertEqual(instance.type, "TestObject") - def test_serialize(self): + def test_serialize(self, _): """ simple function for converting dataclass to dict """ instance = ActivityObject(id="a", type="b") serialized = instance.serialize() @@ -82,7 +83,7 @@ class BaseActivity(TestCase): self.assertEqual(serialized["type"], "b") @responses.activate - def test_resolve_remote_id(self): + def test_resolve_remote_id(self, _): """ look up or load remote data """ # existing item result = resolve_remote_id("http://example.com/a/b", model=models.User) @@ -104,14 +105,14 @@ class BaseActivity(TestCase): self.assertEqual(result.remote_id, "https://example.com/user/mouse") self.assertEqual(result.name, "MOUSE?? MOUSE!!") - def test_to_model_invalid_model(self): + def test_to_model_invalid_model(self, _): """ catch mismatch between activity type and model type """ instance = ActivityObject(id="a", type="b") with self.assertRaises(ActivitySerializerError): instance.to_model(model=models.User) @responses.activate - def test_to_model_image(self): + def test_to_model_image(self, _): """ update an image field """ activity = activitypub.Person( id=self.user.remote_id, @@ -144,7 +145,7 @@ class BaseActivity(TestCase): self.assertEqual(self.user.name, "New Name") self.assertEqual(self.user.key_pair.public_key, "hi") - def test_to_model_many_to_many(self): + def test_to_model_many_to_many(self, _): """ annoying that these all need special handling """ with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): status = models.Status.objects.create( @@ -175,7 +176,7 @@ class BaseActivity(TestCase): self.assertEqual(status.mention_books.first(), book) @responses.activate - def test_to_model_one_to_many(self): + def test_to_model_one_to_many(self, _): """these are reversed relationships, where the secondary object keys the primary object but not vice versa""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): @@ -214,7 +215,7 @@ class BaseActivity(TestCase): self.assertIsNone(status.attachments.first()) @responses.activate - def test_set_related_field(self): + def test_set_related_field(self, _): """ celery task to add back-references to created objects """ with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): status = models.Status.objects.create(