mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +00:00
Adds test for incoming follow request
This commit is contained in:
parent
e8ef8f7101
commit
db18014325
2 changed files with 53 additions and 5 deletions
|
@ -124,10 +124,10 @@ def handle_follow(activity):
|
||||||
return
|
return
|
||||||
|
|
||||||
# figure out who the actor is
|
# figure out who the actor is
|
||||||
user = get_or_create_remote_user(activity['actor'])
|
actor = get_or_create_remote_user(activity['actor'])
|
||||||
try:
|
try:
|
||||||
relationship = models.UserFollowRequest.objects.create(
|
relationship = models.UserFollowRequest.objects.create(
|
||||||
user_subject=user,
|
user_subject=actor,
|
||||||
user_object=to_follow,
|
user_object=to_follow,
|
||||||
relationship_id=activity['id']
|
relationship_id=activity['id']
|
||||||
)
|
)
|
||||||
|
@ -143,14 +143,15 @@ def handle_follow(activity):
|
||||||
status_builder.create_notification(
|
status_builder.create_notification(
|
||||||
to_follow,
|
to_follow,
|
||||||
'FOLLOW',
|
'FOLLOW',
|
||||||
related_user=user
|
related_user=actor
|
||||||
)
|
)
|
||||||
outgoing.handle_accept(user, to_follow, relationship)
|
outgoing.handle_accept(actor, to_follow, relationship)
|
||||||
else:
|
else:
|
||||||
|
# Accept will be triggered manually
|
||||||
status_builder.create_notification(
|
status_builder.create_notification(
|
||||||
to_follow,
|
to_follow,
|
||||||
'FOLLOW_REQUEST',
|
'FOLLOW_REQUEST',
|
||||||
related_user=user
|
related_user=actor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
47
bookwyrm/tests/test_incoming_follow.py
Normal file
47
bookwyrm/tests/test_incoming_follow.py
Normal 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
|
Loading…
Reference in a new issue