def test_get_recipients_software(self): ''' should differentiate between bookwyrm and other remote users ''' with patch('bookwyrm.models.user.set_remote_server.delay'): another_remote_user = models.User.objects.create_user( 'nutria', '*****@*****.**', 'nutriaword', local=False, remote_id='https://example.com/users/nutria', inbox='https://example.com/users/nutria/inbox', outbox='https://example.com/users/nutria/outbox', bookwyrm_user=False, ) MockSelf = namedtuple('Self', ('privacy', 'user')) mock_self = MockSelf('public', self.local_user) self.local_user.followers.add(self.remote_user) self.local_user.followers.add(another_remote_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 2) recipients = ActivitypubMixin.get_recipients(mock_self, software='bookwyrm') self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], self.remote_user.inbox) recipients = ActivitypubMixin.get_recipients(mock_self, software='other') self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], another_remote_user.inbox)
def test_get_recipients_software(self, *_): """should differentiate between bookwyrm and other remote users""" with patch("bookwyrm.models.user.set_remote_server.delay"): another_remote_user = models.User.objects.create_user( "nutria", "*****@*****.**", "nutriaword", local=False, remote_id="https://example.com/users/nutria", inbox="https://example.com/users/nutria/inbox", outbox="https://example.com/users/nutria/outbox", bookwyrm_user=False, ) MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) self.local_user.followers.add(another_remote_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 2) recipients = ActivitypubMixin.get_recipients(mock_self, software="bookwyrm") self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], self.remote_user.inbox) recipients = ActivitypubMixin.get_recipients(mock_self, software="other") self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], another_remote_user.inbox)
def test_get_recipients_public_user_object_no_followers(self, *_): """determines the recipients for a user's object broadcast""" MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 0)
def test_get_recipients_public_object(self, *_): """determines the recipients for an object's broadcast""" MockSelf = namedtuple("Self", ("privacy")) mock_self = MockSelf("public") recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], self.remote_user.inbox)
def test_get_recipients_public_object(self): ''' determines the recipients for an object's broadcast ''' MockSelf = namedtuple('Self', ('privacy')) mock_self = MockSelf('public') recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], self.remote_user.inbox)
def test_get_recipients_public_user_object_no_followers(self): ''' determines the recipients for a user's object broadcast ''' MockSelf = namedtuple('Self', ('privacy', 'user')) mock_self = MockSelf('public', self.local_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 0)
def test_get_recipients_public_user_object(self): """ determines the recipients for a user's object broadcast """ MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], self.remote_user.inbox)
def test_get_recipients_direct(self, *_): """determines the recipients for a user's object broadcast""" MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) with patch("bookwyrm.models.user.set_remote_server.delay"): another_remote_user = models.User.objects.create_user( "nutria", "*****@*****.**", "nutriaword", local=False, remote_id="https://example.com/users/nutria", inbox="https://example.com/users/nutria/inbox", outbox="https://example.com/users/nutria/outbox", ) MockSelf = namedtuple("Self", ("privacy", "user", "recipients")) mock_self = MockSelf("direct", self.local_user, [another_remote_user]) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], another_remote_user.inbox)
def test_get_recipients_direct(self): ''' determines the recipients for a user's object broadcast ''' MockSelf = namedtuple('Self', ('privacy', 'user')) mock_self = MockSelf('public', self.local_user) self.local_user.followers.add(self.remote_user) with patch('bookwyrm.models.user.set_remote_server.delay'): another_remote_user = models.User.objects.create_user( 'nutria', '*****@*****.**', 'nutriaword', local=False, remote_id='https://example.com/users/nutria', inbox='https://example.com/users/nutria/inbox', outbox='https://example.com/users/nutria/outbox', ) MockSelf = namedtuple('Self', ('privacy', 'user', 'recipients')) mock_self = MockSelf('direct', self.local_user, [another_remote_user]) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], another_remote_user.inbox)
def test_get_recipients_combine_inboxes(self, *_): """should combine users with the same shared_inbox""" self.remote_user.shared_inbox = "http://example.com/inbox" self.remote_user.save(broadcast=False, update_fields=["shared_inbox"]) with patch("bookwyrm.models.user.set_remote_server.delay"): another_remote_user = models.User.objects.create_user( "nutria", "*****@*****.**", "nutriaword", local=False, remote_id="https://example.com/users/nutria", inbox="https://example.com/users/nutria/inbox", shared_inbox="http://example.com/inbox", outbox="https://example.com/users/nutria/outbox", ) MockSelf = namedtuple("Self", ("privacy", "user")) mock_self = MockSelf("public", self.local_user) self.local_user.followers.add(self.remote_user) self.local_user.followers.add(another_remote_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], "http://example.com/inbox")
def test_get_recipients_combine_inboxes(self): ''' should combine users with the same shared_inbox ''' self.remote_user.shared_inbox = 'http://example.com/inbox' self.remote_user.save(broadcast=False) with patch('bookwyrm.models.user.set_remote_server.delay'): another_remote_user = models.User.objects.create_user( 'nutria', '*****@*****.**', 'nutriaword', local=False, remote_id='https://example.com/users/nutria', inbox='https://example.com/users/nutria/inbox', shared_inbox='http://example.com/inbox', outbox='https://example.com/users/nutria/outbox', ) MockSelf = namedtuple('Self', ('privacy', 'user')) mock_self = MockSelf('public', self.local_user) self.local_user.followers.add(self.remote_user) self.local_user.followers.add(another_remote_user) recipients = ActivitypubMixin.get_recipients(mock_self) self.assertEqual(len(recipients), 1) self.assertEqual(recipients[0], 'http://example.com/inbox')