Adds test for incoming follow request

This commit is contained in:
Mouse Reeve 2020-10-15 17:32:24 -07:00
parent e8ef8f7101
commit db18014325
2 changed files with 53 additions and 5 deletions

View file

@ -124,10 +124,10 @@ def handle_follow(activity):
return
# figure out who the actor is
user = get_or_create_remote_user(activity['actor'])
actor = get_or_create_remote_user(activity['actor'])
try:
relationship = models.UserFollowRequest.objects.create(
user_subject=user,
user_subject=actor,
user_object=to_follow,
relationship_id=activity['id']
)
@ -143,14 +143,15 @@ def handle_follow(activity):
status_builder.create_notification(
to_follow,
'FOLLOW',
related_user=user
related_user=actor
)
outgoing.handle_accept(user, to_follow, relationship)
outgoing.handle_accept(actor, to_follow, relationship)
else:
# Accept will be triggered manually
status_builder.create_notification(
to_follow,
'FOLLOW_REQUEST',
related_user=user
related_user=actor
)

View file

@ -0,0 +1,47 @@
import json
from django.test import TestCase
from bookwyrm import models, incoming
class Follow(TestCase):
''' not too much going on in the books model but here we are '''
def setUp(self):
self.remote_user = models.User.objects.create_user(
'rat', 'rat@rat.com', 'ratword',
local=False,
remote_id='https://example.com/users/rat',
inbox='https://example.com/users/rat/inbox',
outbox='https://example.com/users/rat/outbox',
)
self.local_user = models.User.objects.create_user(
'mouse', 'mouse@mouse.com', 'mouseword')
self.local_user.remote_id = 'http://local.com/user/mouse'
self.local_user.save()
def test_handle_follow(self):
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/users/rat/follows/123",
"type": "Follow",
"actor": "https://example.com/users/rat",
"object": "http://local.com/user/mouse"
}
incoming.handle_follow(activity)
# notification created
notification = models.Notification.objects.get()
self.assertEqual(notification.user, self.local_user)
self.assertEqual(notification.notification_type, 'FOLLOW')
# the request should have been deleted
requests = models.UserFollowRequest.objects.all()
self.assertEqual(list(requests), [])
# the follow relationship should exist
follow = models.UserFollows.objects.get(user_object=self.local_user)
self.assertEqual(follow.user_subject, self.remote_user)
# an Accept should be sent out