mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-04 14:28:49 +00:00
Fixes remote_id on Update activities
This commit is contained in:
parent
2e4aff90a3
commit
39307ce1cd
2 changed files with 50 additions and 1 deletions
|
@ -130,7 +130,7 @@ class ActivitypubMixin:
|
||||||
|
|
||||||
def to_update_activity(self, user):
|
def to_update_activity(self, user):
|
||||||
''' wrapper for Updates to an activity '''
|
''' wrapper for Updates to an activity '''
|
||||||
activity_id = '%s#update/%s' % (user.remote_id, uuid4())
|
activity_id = '%s#update/%s' % (self.remote_id, uuid4())
|
||||||
return activitypub.Update(
|
return activitypub.Update(
|
||||||
id=activity_id,
|
id=activity_id,
|
||||||
actor=user.remote_id,
|
actor=user.remote_id,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
''' testing models '''
|
''' testing models '''
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
import re
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
@ -62,6 +63,7 @@ class BaseModel(TestCase):
|
||||||
'https://example.com/status/1/activity'
|
'https://example.com/status/1/activity'
|
||||||
)
|
)
|
||||||
self.assertEqual(activity['actor'], user.remote_id)
|
self.assertEqual(activity['actor'], user.remote_id)
|
||||||
|
self.assertEqual(activity['type'], 'Create')
|
||||||
self.assertEqual(activity['to'], 'to field')
|
self.assertEqual(activity['to'], 'to field')
|
||||||
self.assertEqual(activity['cc'], 'cc field')
|
self.assertEqual(activity['cc'], 'cc field')
|
||||||
self.assertEqual(activity['object'], object_activity)
|
self.assertEqual(activity['object'], object_activity)
|
||||||
|
@ -69,3 +71,50 @@ class BaseModel(TestCase):
|
||||||
activity['signature'].creator,
|
activity['signature'].creator,
|
||||||
'%s#main-key' % user.remote_id
|
'%s#main-key' % user.remote_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_to_delete_activity(self):
|
||||||
|
user = models.User.objects.create_user(
|
||||||
|
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||||
|
|
||||||
|
MockSelf = namedtuple('Self', ('remote_id', 'to_activity'))
|
||||||
|
mock_self = MockSelf(
|
||||||
|
'https://example.com/status/1',
|
||||||
|
lambda *args: {}
|
||||||
|
)
|
||||||
|
activity = ActivitypubMixin.to_delete_activity(mock_self, user)
|
||||||
|
self.assertEqual(
|
||||||
|
activity['id'],
|
||||||
|
'https://example.com/status/1/activity'
|
||||||
|
)
|
||||||
|
self.assertEqual(activity['actor'], user.remote_id)
|
||||||
|
self.assertEqual(activity['type'], 'Delete')
|
||||||
|
self.assertEqual(
|
||||||
|
activity['to'],
|
||||||
|
['%s/followers' % user.remote_id])
|
||||||
|
self.assertEqual(
|
||||||
|
activity['cc'],
|
||||||
|
['https://www.w3.org/ns/activitystreams#Public'])
|
||||||
|
|
||||||
|
def test_to_update_activity(self):
|
||||||
|
user = models.User.objects.create_user(
|
||||||
|
'mouse', 'mouse@mouse.com', 'mouseword', local=True)
|
||||||
|
|
||||||
|
MockSelf = namedtuple('Self', ('remote_id', 'to_activity'))
|
||||||
|
mock_self = MockSelf(
|
||||||
|
'https://example.com/status/1',
|
||||||
|
lambda *args: {}
|
||||||
|
)
|
||||||
|
activity = ActivitypubMixin.to_update_activity(mock_self, user)
|
||||||
|
print(activity['id'])
|
||||||
|
self.assertIsNotNone(
|
||||||
|
re.match(
|
||||||
|
r'^https:\/\/example\.com\/status\/1#update\/.*',
|
||||||
|
activity['id']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.assertEqual(activity['actor'], user.remote_id)
|
||||||
|
self.assertEqual(activity['type'], 'Update')
|
||||||
|
self.assertEqual(
|
||||||
|
activity['to'],
|
||||||
|
['https://www.w3.org/ns/activitystreams#Public'])
|
||||||
|
self.assertEqual(activity['object'], {})
|
||||||
|
|
Loading…
Reference in a new issue