mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Fixes follows
Yikes
This commit is contained in:
parent
5ca1e0a827
commit
363609e7be
2 changed files with 48 additions and 2 deletions
|
@ -40,7 +40,7 @@ class BookViews(TestCase):
|
|||
parent_work=self.work
|
||||
)
|
||||
|
||||
def test_handle_follow(self):
|
||||
def test_handle_follow_remote(self):
|
||||
''' send a follow request '''
|
||||
request = self.factory.post('', {'user': self.remote_user.username})
|
||||
request.user = self.local_user
|
||||
|
@ -56,6 +56,49 @@ class BookViews(TestCase):
|
|||
self.assertEqual(rel.status, 'follow_request')
|
||||
|
||||
|
||||
def test_handle_follow_local_manually_approves(self):
|
||||
''' send a follow request '''
|
||||
rat = models.User.objects.create_user(
|
||||
'rat@local.com', 'rat@rat.com', 'ratword',
|
||||
local=True, localname='rat',
|
||||
remote_id='https://example.com/users/rat',
|
||||
manually_approves_followers=True,
|
||||
)
|
||||
request = self.factory.post('', {'user': rat})
|
||||
request.user = self.local_user
|
||||
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
||||
|
||||
with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
|
||||
views.follow(request)
|
||||
rel = models.UserFollowRequest.objects.get()
|
||||
|
||||
self.assertEqual(rel.user_subject, self.local_user)
|
||||
self.assertEqual(rel.user_object, rat)
|
||||
self.assertEqual(rel.status, 'follow_request')
|
||||
|
||||
|
||||
|
||||
def test_handle_follow_local(self):
|
||||
''' send a follow request '''
|
||||
rat = models.User.objects.create_user(
|
||||
'rat@local.com', 'rat@rat.com', 'ratword',
|
||||
local=True, localname='rat',
|
||||
remote_id='https://example.com/users/rat',
|
||||
)
|
||||
request = self.factory.post('', {'user': rat})
|
||||
request.user = self.local_user
|
||||
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
||||
|
||||
with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
|
||||
views.follow(request)
|
||||
|
||||
rel = models.UserFollows.objects.get()
|
||||
|
||||
self.assertEqual(rel.user_subject, self.local_user)
|
||||
self.assertEqual(rel.user_object, rat)
|
||||
self.assertEqual(rel.status, 'follows')
|
||||
|
||||
|
||||
def test_handle_unfollow(self):
|
||||
''' send an unfollow '''
|
||||
request = self.factory.post('', {'user': self.remote_user.username})
|
||||
|
|
|
@ -17,10 +17,13 @@ def follow(request):
|
|||
except models.User.DoesNotExist:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
models.UserFollowRequest.objects.get_or_create(
|
||||
rel, _ = models.UserFollowRequest.objects.get_or_create(
|
||||
user_subject=request.user,
|
||||
user_object=to_follow,
|
||||
)
|
||||
|
||||
if to_follow.local and not to_follow.manually_approves_followers:
|
||||
rel.accept()
|
||||
return redirect(to_follow.local_path)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue