2020-05-11 04:07:19 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2020-09-21 15:10:37 +00:00
|
|
|
from bookwyrm import models, broadcast
|
2020-05-11 04:07:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Book(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.user = models.User.objects.create_user(
|
|
|
|
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
|
|
|
|
|
|
|
follower = models.User.objects.create_user(
|
|
|
|
'rat', 'rat@mouse.mouse', 'ratword', local=False,
|
2020-05-13 01:56:28 +00:00
|
|
|
remote_id='http://example.com/u/1',
|
2020-05-11 04:07:19 +00:00
|
|
|
outbox='http://example.com/u/1/o',
|
|
|
|
shared_inbox='http://example.com/inbox',
|
|
|
|
inbox='http://example.com/u/1/inbox')
|
|
|
|
self.user.followers.add(follower)
|
|
|
|
|
|
|
|
no_inbox_follower = models.User.objects.create_user(
|
|
|
|
'hamster', 'hamster@mouse.mouse', 'hamword',
|
|
|
|
shared_inbox=None, local=False,
|
2020-05-13 01:56:28 +00:00
|
|
|
remote_id='http://example.com/u/2',
|
2020-05-11 04:07:19 +00:00
|
|
|
outbox='http://example.com/u/2/o',
|
|
|
|
inbox='http://example.com/u/2/inbox')
|
|
|
|
self.user.followers.add(no_inbox_follower)
|
|
|
|
|
2020-11-28 00:12:47 +00:00
|
|
|
non_bw_follower = models.User.objects.create_user(
|
2020-05-11 04:07:19 +00:00
|
|
|
'gerbil', 'gerb@mouse.mouse', 'gerbword',
|
2020-05-13 01:56:28 +00:00
|
|
|
remote_id='http://example.com/u/3',
|
2020-05-11 04:07:19 +00:00
|
|
|
outbox='http://example2.com/u/3/o',
|
|
|
|
inbox='http://example2.com/u/3/inbox',
|
|
|
|
shared_inbox='http://example2.com/inbox',
|
2020-09-21 15:10:37 +00:00
|
|
|
bookwyrm_user=False, local=False)
|
2020-11-28 00:12:47 +00:00
|
|
|
self.user.followers.add(non_bw_follower)
|
2020-05-11 04:07:19 +00:00
|
|
|
|
|
|
|
local_follower = models.User.objects.create_user(
|
|
|
|
'joe', 'joe@mouse.mouse', 'jeoword')
|
|
|
|
self.user.followers.add(local_follower)
|
|
|
|
|
|
|
|
models.User.objects.create_user(
|
|
|
|
'nutria', 'nutria@mouse.mouse', 'nuword',
|
2020-05-13 01:56:28 +00:00
|
|
|
remote_id='http://example.com/u/4',
|
2020-05-11 04:07:19 +00:00
|
|
|
outbox='http://example.com/u/4/o',
|
|
|
|
shared_inbox='http://example.com/inbox',
|
|
|
|
inbox='http://example.com/u/4/inbox',
|
|
|
|
local=False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_public_recipients(self):
|
|
|
|
expected = [
|
|
|
|
'http://example2.com/inbox',
|
|
|
|
'http://example.com/inbox',
|
|
|
|
'http://example.com/u/2/inbox',
|
|
|
|
]
|
|
|
|
|
|
|
|
recipients = broadcast.get_public_recipients(self.user)
|
|
|
|
self.assertEqual(recipients, expected)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_public_recipients_software(self):
|
|
|
|
expected = [
|
|
|
|
'http://example.com/inbox',
|
|
|
|
'http://example.com/u/2/inbox',
|
|
|
|
]
|
|
|
|
|
2020-09-21 15:10:37 +00:00
|
|
|
recipients = broadcast.get_public_recipients(self.user, software='bookwyrm')
|
2020-05-11 04:07:19 +00:00
|
|
|
self.assertEqual(recipients, expected)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_public_recipients_software_other(self):
|
|
|
|
expected = [
|
|
|
|
'http://example2.com/inbox',
|
|
|
|
]
|
|
|
|
|
|
|
|
recipients = broadcast.get_public_recipients(self.user, software='mastodon')
|
|
|
|
self.assertEqual(recipients, expected)
|