diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 94fbc015..d3c9471f 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -142,10 +142,10 @@ class ActivitypubMixin: def to_undo_activity(self, user): ''' undo an action ''' return activitypub.Undo( - id='%s#undo' % user.remote_id, + id='%s#undo' % self.remote_id, actor=user.remote_id, object=self.to_activity() - ) + ).serialize() class OrderedCollectionPageMixin(ActivitypubMixin): diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index 40306d91..b187284a 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -105,7 +105,6 @@ class BaseModel(TestCase): lambda *args: {} ) activity = ActivitypubMixin.to_update_activity(mock_self, user) - print(activity['id']) self.assertIsNotNone( re.match( r'^https:\/\/example\.com\/status\/1#update\/.*', @@ -118,3 +117,21 @@ class BaseModel(TestCase): activity['to'], ['https://www.w3.org/ns/activitystreams#Public']) self.assertEqual(activity['object'], {}) + + def test_to_undo_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_undo_activity(mock_self, user) + self.assertEqual( + activity['id'], + 'https://example.com/status/1#undo' + ) + self.assertEqual(activity['actor'], user.remote_id) + self.assertEqual(activity['type'], 'Undo') + self.assertEqual(activity['object'], {})