From 7b21a0a2081af5271aa3322ad6effbe93e307aa8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 17 Feb 2021 12:23:55 -0800 Subject: [PATCH] Fix things, unfix things, refix things, break things, fix things --- bookwyrm/activitypub/base_activity.py | 6 ++++-- bookwyrm/models/relationship.py | 5 +---- bookwyrm/tests/views/test_follow.py | 2 ++ bookwyrm/tests/views/test_inbox.py | 8 +++++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index dbd4eacc..c360711d 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -79,8 +79,10 @@ class ActivityObject: value = value.to_activity() # parse a dict into the appropriate activity elif is_subclass and isinstance(value, dict): - value = naive_parse( - activity_objects, value, serializer=field.type) + if activity_objects: + value = naive_parse(activity_objects, value) + else: + value = naive_parse(activity_objects, value, serializer=field.type) except KeyError: if field.default == MISSING and \ diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index 3e6ac0fb..764cada6 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -105,10 +105,7 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship): except (UserFollows.DoesNotExist, UserBlocks.DoesNotExist): pass - # this was calling itself which is not my idea of "super" ... - if not self.id: - super().save(*args, **kwargs) - return + super().save(*args, **kwargs) if broadcast and self.user_subject.local and not self.user_object.local: self.broadcast(self.to_activity(), self.user_subject) diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index 5f61ab03..62543d2d 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -135,6 +135,8 @@ class BookViews(TestCase): def test_handle_reject(self): ''' reject a follow request ''' + self.local_user.manually_approves_followers = True + self.local_user.save(broadcast=False) request = self.factory.post('', {'user': self.remote_user.username}) request.user = self.local_user rel = models.UserFollowRequest.objects.create( diff --git a/bookwyrm/tests/views/test_inbox.py b/bookwyrm/tests/views/test_inbox.py index 0251d8a2..1e597cb1 100644 --- a/bookwyrm/tests/views/test_inbox.py +++ b/bookwyrm/tests/views/test_inbox.py @@ -236,7 +236,7 @@ class Inbox(TestCase): self.assertEqual(book_list.remote_id, 'https://example.com/list/22') - def test_handle_follow(self): + def test_handle_follow_x(self): ''' remote user wants to follow local user ''' activity = { "@context": "https://www.w3.org/ns/activitystreams", @@ -246,7 +246,9 @@ class Inbox(TestCase): "object": "https://example.com/user/mouse" } - with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay') as mock: + self.assertFalse(models.UserFollowRequest.objects.exists()) + with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay') \ + as mock: views.inbox.activity_task(activity) self.assertEqual(mock.call_count, 1) @@ -736,6 +738,6 @@ class Inbox(TestCase): "type": "Block", "actor": "https://example.com/users/rat", "object": "https://example.com/user/mouse" - }} + }} views.inbox.activity_task(activity) self.assertFalse(models.UserBlocks.objects.exists())