From ae81d6cf71b44468b15eb14e06e35322410795e0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 11:55:04 -0700 Subject: [PATCH] More tests --- bookwyrm/models/activitypub_mixin.py | 10 ++++++++ .../tests/views/inbox/test_inbox_delete.py | 25 +++++++++++++------ bookwyrm/tests/views/test_list_actions.py | 5 ++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index f287b752..3e9e1940 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -369,6 +369,16 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin): if self.user.local and broadcast: self.broadcast(activity, self.user) + def to_delete_activity(self, user): + """notice of deletion""" + return activitypub.Delete( + id=self.remote_id + "/activity", + actor=user.remote_id, + to=["%s/followers" % user.remote_id], + cc=["https://www.w3.org/ns/activitystreams#Public"], + object=self.remote_id, + ).serialize() + class CollectionItemMixin(ActivitypubMixin): """for items that are part of an (Ordered)Collection""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 1566c05a..fef5ce51 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -40,14 +40,6 @@ class InboxActivities(TestCase): remote_id="https://example.com/status/1", ) - self.create_json = { - "id": "hi", - "type": "Create", - "actor": "hi", - "to": ["https://www.w3.org/ns/activitystreams#public"], - "cc": ["https://example.com/user/mouse/followers"], - "object": {}, - } models.SiteSettings.objects.create() def test_delete_status(self): @@ -137,3 +129,20 @@ class InboxActivities(TestCase): # nothing happens. views.inbox.activity_task(activity) self.assertEqual(models.User.objects.filter(is_active=True).count(), 2) + + def test_delete_list(self): + """delete a list""" + book_list = models.List.objects.create( + name="test list", + user=self.remote_user, + ) + activity = { + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://example.com/users/test-user#delete", + "type": "Delete", + "actor": "https://example.com/users/test-user", + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "object": book_list.remote_id, + } + views.inbox.activity_task(activity) + self.assertFalse(models.List.objects.exists()) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index 710d83de..e268905d 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -87,6 +87,11 @@ class ListActionViews(TestCase): request.user = self.local_user with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: views.delete_list(request, self.list.id) + activity = json.loads(mock.call_args[0][1]) + self.assertEqual(activity["type"], "Delete") + self.assertEqual(activity["actor"], self.local_user.remote_id) + self.assertEqual(activity["object"], self.list.remote_id) + self.assertEqual(mock.call_count, 1) self.assertFalse(models.List.objects.exists()) self.assertFalse(models.ListItem.objects.exists())