fixes unit tests for incoming and outgoing follows
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
from unittest.mock import patch
|
||||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models, incoming
|
||||
@ -18,29 +19,30 @@ class IncomingFollow(TestCase):
|
||||
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)
|
||||
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"
|
||||
}
|
||||
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay') as _:
|
||||
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)
|
||||
|
||||
|
||||
def test_handle_follow_manually_approved(self):
|
||||
@ -55,7 +57,8 @@ class IncomingFollow(TestCase):
|
||||
self.local_user.manually_approves_followers = True
|
||||
self.local_user.save()
|
||||
|
||||
incoming.handle_follow(activity)
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay') as _:
|
||||
incoming.handle_follow(activity)
|
||||
|
||||
# notification created
|
||||
notification = models.Notification.objects.get()
|
||||
@ -81,7 +84,8 @@ class IncomingFollow(TestCase):
|
||||
"object": "http://local.com/user/nonexistent-user"
|
||||
}
|
||||
|
||||
incoming.handle_follow(activity)
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay') as _:
|
||||
incoming.handle_follow(activity)
|
||||
|
||||
# do nothing
|
||||
notifications = models.Notification.objects.all()
|
||||
|
Reference in New Issue
Block a user