From 8d27f02a9a39a03cb7bf9484ccc350981ce8fe07 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 14 Dec 2020 11:46:31 -0800 Subject: [PATCH] Fixes typo in handle_unfollow --- bookwyrm/incoming.py | 2 +- bookwyrm/tests/test_incoming.py | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/bookwyrm/incoming.py b/bookwyrm/incoming.py index 734549f4..3fa9c23d 100644 --- a/bookwyrm/incoming.py +++ b/bookwyrm/incoming.py @@ -141,7 +141,7 @@ def handle_follow(activity): def handle_unfollow(activity): ''' unfollow a local user ''' obj = activity['object'] - requester = activitypub.resolve_remote_id(models.user, obj['actor']) + requester = activitypub.resolve_remote_id(models.User, obj['actor']) to_unfollow = models.User.objects.get(remote_id=obj['object']) # raises models.User.DoesNotExist diff --git a/bookwyrm/tests/test_incoming.py b/bookwyrm/tests/test_incoming.py index 8b226792..4639e9fb 100644 --- a/bookwyrm/tests/test_incoming.py +++ b/bookwyrm/tests/test_incoming.py @@ -159,6 +159,26 @@ class Incoming(TestCase): self.assertEqual(list(follow), []) + def test_handle_unfollow(self): + ''' remove a relationship ''' + activity = { + "type": "Undo", + "@context": "https://www.w3.org/ns/activitystreams", + "object": { + "id": "https://example.com/users/rat/follows/123", + "type": "Follow", + "actor": "https://example.com/users/rat", + "object": "http://local.com/user/mouse" + } + } + models.UserFollows.objects.create( + user_subject=self.remote_user, user_object=self.local_user) + self.assertEqual(self.remote_user, self.local_user.followers.first()) + + incoming.handle_unfollow(activity) + self.assertIsNone(self.local_user.followers.first()) + + def test_handle_follow_accept(self): ''' a remote user approved a follow request from local ''' activity = { @@ -191,6 +211,37 @@ class Incoming(TestCase): self.assertEqual(follows.first(), self.local_user) + def test_handle_follow_reject(self): + ''' turn down a follow request ''' + activity = { + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://example.com/users/rat/follows/123#accepts", + "type": "Reject", + "actor": "https://example.com/users/rat", + "object": { + "id": "https://example.com/users/rat/follows/123", + "type": "Follow", + "actor": "http://local.com/user/mouse", + "object": "https://example.com/users/rat" + } + } + + models.UserFollowRequest.objects.create( + user_subject=self.local_user, + user_object=self.remote_user + ) + self.assertEqual(models.UserFollowRequest.objects.count(), 1) + + incoming.handle_follow_reject(activity) + + # request should be deleted + self.assertEqual(models.UserFollowRequest.objects.count(), 0) + + # relationship should be created + follows = self.remote_user.followers + self.assertEqual(follows.count(), 0) + + def test_handle_favorite(self): ''' fav a status ''' activity = {