Fix things, unfix things, refix things, break things, fix things

This commit is contained in:
Mouse Reeve 2021-02-17 12:23:55 -08:00
parent 08dc5b4d86
commit 7b21a0a208
4 changed files with 12 additions and 9 deletions

View file

@ -79,8 +79,10 @@ class ActivityObject:
value = value.to_activity() value = value.to_activity()
# parse a dict into the appropriate activity # parse a dict into the appropriate activity
elif is_subclass and isinstance(value, dict): elif is_subclass and isinstance(value, dict):
value = naive_parse( if activity_objects:
activity_objects, value, serializer=field.type) value = naive_parse(activity_objects, value)
else:
value = naive_parse(activity_objects, value, serializer=field.type)
except KeyError: except KeyError:
if field.default == MISSING and \ if field.default == MISSING and \

View file

@ -105,10 +105,7 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship):
except (UserFollows.DoesNotExist, UserBlocks.DoesNotExist): except (UserFollows.DoesNotExist, UserBlocks.DoesNotExist):
pass pass
# this was calling itself which is not my idea of "super" ... super().save(*args, **kwargs)
if not self.id:
super().save(*args, **kwargs)
return
if broadcast and self.user_subject.local and not self.user_object.local: if broadcast and self.user_subject.local and not self.user_object.local:
self.broadcast(self.to_activity(), self.user_subject) self.broadcast(self.to_activity(), self.user_subject)

View file

@ -135,6 +135,8 @@ class BookViews(TestCase):
def test_handle_reject(self): def test_handle_reject(self):
''' reject a follow request ''' ''' 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 = self.factory.post('', {'user': self.remote_user.username})
request.user = self.local_user request.user = self.local_user
rel = models.UserFollowRequest.objects.create( rel = models.UserFollowRequest.objects.create(

View file

@ -236,7 +236,7 @@ class Inbox(TestCase):
self.assertEqual(book_list.remote_id, 'https://example.com/list/22') 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 ''' ''' remote user wants to follow local user '''
activity = { activity = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
@ -246,7 +246,9 @@ class Inbox(TestCase):
"object": "https://example.com/user/mouse" "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) views.inbox.activity_task(activity)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
@ -736,6 +738,6 @@ class Inbox(TestCase):
"type": "Block", "type": "Block",
"actor": "https://example.com/users/rat", "actor": "https://example.com/users/rat",
"object": "https://example.com/user/mouse" "object": "https://example.com/user/mouse"
}} }}
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertFalse(models.UserBlocks.objects.exists()) self.assertFalse(models.UserBlocks.objects.exists())