forked from mirrors/bookwyrm
More tests
This commit is contained in:
parent
d212cbfd3c
commit
ae81d6cf71
3 changed files with 32 additions and 8 deletions
bookwyrm
|
@ -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"""
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue