forked from mirrors/bookwyrm
Test re-following a user
This commit is contained in:
parent
094012085b
commit
d5b27e2202
1 changed files with 36 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
""" tests incoming activities"""
|
""" tests incoming activities"""
|
||||||
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -34,7 +35,7 @@ class InboxRelationships(TestCase):
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_follow(self):
|
def test_follow(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",
|
||||||
|
@ -48,6 +49,8 @@ class InboxRelationships(TestCase):
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock:
|
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)
|
||||||
|
response_activity = json.loads(mock.call_args[0][1])
|
||||||
|
self.assertEqual(response_activity["type"], "Accept")
|
||||||
|
|
||||||
# notification created
|
# notification created
|
||||||
notification = models.Notification.objects.get()
|
notification = models.Notification.objects.get()
|
||||||
|
@ -61,7 +64,34 @@ class InboxRelationships(TestCase):
|
||||||
follow = models.UserFollows.objects.get(user_object=self.local_user)
|
follow = models.UserFollows.objects.get(user_object=self.local_user)
|
||||||
self.assertEqual(follow.user_subject, self.remote_user)
|
self.assertEqual(follow.user_subject, self.remote_user)
|
||||||
|
|
||||||
def test_handle_follow_manually_approved(self):
|
def test_follow_duplicate(self):
|
||||||
|
""" remote user wants to follow local user twice """
|
||||||
|
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": "https://example.com/user/mouse",
|
||||||
|
}
|
||||||
|
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
views.inbox.activity_task(activity)
|
||||||
|
|
||||||
|
# the follow relationship should exist
|
||||||
|
follow = models.UserFollows.objects.get(user_object=self.local_user)
|
||||||
|
self.assertEqual(follow.user_subject, self.remote_user)
|
||||||
|
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock:
|
||||||
|
views.inbox.activity_task(activity)
|
||||||
|
self.assertEqual(mock.call_count, 1)
|
||||||
|
response_activity = json.loads(mock.call_args[0][1])
|
||||||
|
self.assertEqual(response_activity["type"], "Accept")
|
||||||
|
|
||||||
|
# the follow relationship should STILL exist
|
||||||
|
follow = models.UserFollows.objects.get(user_object=self.local_user)
|
||||||
|
self.assertEqual(follow.user_subject, self.remote_user)
|
||||||
|
|
||||||
|
def test_follow_manually_approved(self):
|
||||||
""" needs approval before following """
|
""" needs approval before following """
|
||||||
activity = {
|
activity = {
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
@ -91,7 +121,7 @@ class InboxRelationships(TestCase):
|
||||||
follow = models.UserFollows.objects.all()
|
follow = models.UserFollows.objects.all()
|
||||||
self.assertEqual(list(follow), [])
|
self.assertEqual(list(follow), [])
|
||||||
|
|
||||||
def test_handle_undo_follow_request(self):
|
def test_undo_follow_request(self):
|
||||||
""" the requester cancels a follow request """
|
""" the requester cancels a follow request """
|
||||||
self.local_user.manually_approves_followers = True
|
self.local_user.manually_approves_followers = True
|
||||||
self.local_user.save(broadcast=False)
|
self.local_user.save(broadcast=False)
|
||||||
|
@ -121,7 +151,7 @@ class InboxRelationships(TestCase):
|
||||||
|
|
||||||
self.assertFalse(self.local_user.follower_requests.exists())
|
self.assertFalse(self.local_user.follower_requests.exists())
|
||||||
|
|
||||||
def test_handle_unfollow(self):
|
def test_unfollow(self):
|
||||||
""" remove a relationship """
|
""" remove a relationship """
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
rel = models.UserFollows.objects.create(
|
rel = models.UserFollows.objects.create(
|
||||||
|
@ -146,7 +176,7 @@ class InboxRelationships(TestCase):
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
self.assertIsNone(self.local_user.followers.first())
|
self.assertIsNone(self.local_user.followers.first())
|
||||||
|
|
||||||
def test_handle_follow_accept(self):
|
def test_follow_accept(self):
|
||||||
""" a remote user approved a follow request from local """
|
""" a remote user approved a follow request from local """
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
rel = models.UserFollowRequest.objects.create(
|
rel = models.UserFollowRequest.objects.create(
|
||||||
|
@ -177,7 +207,7 @@ class InboxRelationships(TestCase):
|
||||||
self.assertEqual(follows.count(), 1)
|
self.assertEqual(follows.count(), 1)
|
||||||
self.assertEqual(follows.first(), self.local_user)
|
self.assertEqual(follows.first(), self.local_user)
|
||||||
|
|
||||||
def test_handle_follow_reject(self):
|
def test_follow_reject(self):
|
||||||
""" turn down a follow request """
|
""" turn down a follow request """
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
rel = models.UserFollowRequest.objects.create(
|
rel = models.UserFollowRequest.objects.create(
|
||||||
|
|
Loading…
Reference in a new issue