From 800ddf2a6b9144508a69807be32790fe7abc9e9d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 4 Dec 2020 11:52:01 -0800 Subject: [PATCH] fixes inconsistency in to_undo activity helper --- bookwyrm/models/base_model.py | 4 ++-- bookwyrm/tests/models/test_base_model.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 94fbc0154..d3c9471f6 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 40306d91c..b187284ae 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'], {})