Merge branch 'main' into domain-block
This commit is contained in:
commit
4e0225749d
23 changed files with 331 additions and 144 deletions
|
@ -116,7 +116,9 @@ class Status(TestCase):
|
|||
|
||||
def test_status_to_activity_tombstone(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.remove_status"):
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
):
|
||||
status = models.Status.objects.create(
|
||||
content="test content",
|
||||
user=self.local_user,
|
||||
|
|
|
@ -47,18 +47,18 @@ class Activitystreams(TestCase):
|
|||
"{}-test-unread".format(self.local_user.id),
|
||||
)
|
||||
|
||||
def test_abstractstream_stream_users(self, *_):
|
||||
def test_abstractstream_get_audience(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="public"
|
||||
)
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
# remote users don't have feeds
|
||||
self.assertFalse(self.remote_user in users)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertTrue(self.another_user in users)
|
||||
|
||||
def test_abstractstream_stream_users_direct(self, *_):
|
||||
def test_abstractstream_get_audience_direct(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user,
|
||||
|
@ -66,7 +66,7 @@ class Activitystreams(TestCase):
|
|||
privacy="direct",
|
||||
)
|
||||
status.mention_users.add(self.local_user)
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
self.assertEqual(users, [])
|
||||
|
||||
status = models.Comment.objects.create(
|
||||
|
@ -76,22 +76,22 @@ class Activitystreams(TestCase):
|
|||
book=self.book,
|
||||
)
|
||||
status.mention_users.add(self.local_user)
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertFalse(self.another_user in users)
|
||||
self.assertFalse(self.remote_user in users)
|
||||
|
||||
def test_abstractstream_stream_users_followers_remote_user(self, *_):
|
||||
def test_abstractstream_get_audience_followers_remote_user(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user,
|
||||
content="hi",
|
||||
privacy="followers",
|
||||
)
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
self.assertFalse(users.exists())
|
||||
|
||||
def test_abstractstream_stream_users_followers_self(self, *_):
|
||||
def test_abstractstream_get_audience_followers_self(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Comment.objects.create(
|
||||
user=self.local_user,
|
||||
|
@ -99,12 +99,12 @@ class Activitystreams(TestCase):
|
|||
privacy="direct",
|
||||
book=self.book,
|
||||
)
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertFalse(self.another_user in users)
|
||||
self.assertFalse(self.remote_user in users)
|
||||
|
||||
def test_abstractstream_stream_users_followers_with_mention(self, *_):
|
||||
def test_abstractstream_get_audience_followers_with_mention(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Comment.objects.create(
|
||||
user=self.remote_user,
|
||||
|
@ -114,12 +114,12 @@ class Activitystreams(TestCase):
|
|||
)
|
||||
status.mention_users.add(self.local_user)
|
||||
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertFalse(self.another_user in users)
|
||||
self.assertFalse(self.remote_user in users)
|
||||
|
||||
def test_abstractstream_stream_users_followers_with_relationship(self, *_):
|
||||
def test_abstractstream_get_audience_followers_with_relationship(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
self.remote_user.followers.add(self.local_user)
|
||||
status = models.Comment.objects.create(
|
||||
|
@ -128,77 +128,77 @@ class Activitystreams(TestCase):
|
|||
privacy="direct",
|
||||
book=self.book,
|
||||
)
|
||||
users = self.test_stream.stream_users(status)
|
||||
users = self.test_stream.get_audience(status)
|
||||
self.assertFalse(self.local_user in users)
|
||||
self.assertFalse(self.another_user in users)
|
||||
self.assertFalse(self.remote_user in users)
|
||||
|
||||
def test_homestream_stream_users(self, *_):
|
||||
def test_homestream_get_audience(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="public"
|
||||
)
|
||||
users = activitystreams.HomeStream().stream_users(status)
|
||||
users = activitystreams.HomeStream().get_audience(status)
|
||||
self.assertFalse(users.exists())
|
||||
|
||||
def test_homestream_stream_users_with_mentions(self, *_):
|
||||
def test_homestream_get_audience_with_mentions(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="public"
|
||||
)
|
||||
status.mention_users.add(self.local_user)
|
||||
users = activitystreams.HomeStream().stream_users(status)
|
||||
users = activitystreams.HomeStream().get_audience(status)
|
||||
self.assertFalse(self.local_user in users)
|
||||
self.assertFalse(self.another_user in users)
|
||||
|
||||
def test_homestream_stream_users_with_relationship(self, *_):
|
||||
def test_homestream_get_audience_with_relationship(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
self.remote_user.followers.add(self.local_user)
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="public"
|
||||
)
|
||||
users = activitystreams.HomeStream().stream_users(status)
|
||||
users = activitystreams.HomeStream().get_audience(status)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertFalse(self.another_user in users)
|
||||
|
||||
def test_localstream_stream_users_remote_status(self, *_):
|
||||
def test_localstream_get_audience_remote_status(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="public"
|
||||
)
|
||||
users = activitystreams.LocalStream().stream_users(status)
|
||||
users = activitystreams.LocalStream().get_audience(status)
|
||||
self.assertEqual(users, [])
|
||||
|
||||
def test_localstream_stream_users_local_status(self, *_):
|
||||
def test_localstream_get_audience_local_status(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.local_user, content="hi", privacy="public"
|
||||
)
|
||||
users = activitystreams.LocalStream().stream_users(status)
|
||||
users = activitystreams.LocalStream().get_audience(status)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertTrue(self.another_user in users)
|
||||
|
||||
def test_localstream_stream_users_unlisted(self, *_):
|
||||
def test_localstream_get_audience_unlisted(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.local_user, content="hi", privacy="unlisted"
|
||||
)
|
||||
users = activitystreams.LocalStream().stream_users(status)
|
||||
users = activitystreams.LocalStream().get_audience(status)
|
||||
self.assertEqual(users, [])
|
||||
|
||||
def test_federatedstream_stream_users(self, *_):
|
||||
def test_federatedstream_get_audience(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="public"
|
||||
)
|
||||
users = activitystreams.FederatedStream().stream_users(status)
|
||||
users = activitystreams.FederatedStream().get_audience(status)
|
||||
self.assertTrue(self.local_user in users)
|
||||
self.assertTrue(self.another_user in users)
|
||||
|
||||
def test_federatedstream_stream_users_unlisted(self, *_):
|
||||
def test_federatedstream_get_audience_unlisted(self, *_):
|
||||
""" get a list of users that should see a status """
|
||||
status = models.Status.objects.create(
|
||||
user=self.remote_user, content="hi", privacy="unlisted"
|
||||
)
|
||||
users = activitystreams.FederatedStream().stream_users(status)
|
||||
users = activitystreams.FederatedStream().get_audience(status)
|
||||
self.assertEqual(users, [])
|
||||
|
|
|
@ -85,7 +85,9 @@ class TemplateTags(TestCase):
|
|||
second_child = models.Status.objects.create(
|
||||
reply_parent=parent, user=self.user, content="hi"
|
||||
)
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.remove_status"):
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
):
|
||||
third_child = models.Status.objects.create(
|
||||
reply_parent=parent,
|
||||
user=self.user,
|
||||
|
|
|
@ -446,7 +446,7 @@ class Inbox(TestCase):
|
|||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_status"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
@ -479,7 +479,7 @@ class Inbox(TestCase):
|
|||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_status"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
@ -574,6 +574,56 @@ class Inbox(TestCase):
|
|||
self.assertEqual(notification.user, self.local_user)
|
||||
self.assertEqual(notification.related_status, self.status)
|
||||
|
||||
@responses.activate
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_handle_boost_remote_status(self, redis_mock):
|
||||
""" boost a status """
|
||||
work = models.Work.objects.create(title="work title")
|
||||
book = models.Edition.objects.create(
|
||||
title="Test",
|
||||
remote_id="https://bookwyrm.social/book/37292",
|
||||
parent_work=work,
|
||||
)
|
||||
self.assertEqual(models.Notification.objects.count(), 0)
|
||||
activity = {
|
||||
"type": "Announce",
|
||||
"id": "%s/boost" % self.status.remote_id,
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": "https://remote.com/status/1",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||
}
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://remote.com/status/1",
|
||||
json={
|
||||
"id": "https://remote.com/status/1",
|
||||
"type": "Comment",
|
||||
"published": "2021-04-05T18:04:59.735190+00:00",
|
||||
"attributedTo": self.remote_user.remote_id,
|
||||
"content": "<p>a comment</p>",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc": ["https://b875df3d118b.ngrok.io/user/mouse/followers"],
|
||||
"inReplyTo": "",
|
||||
"inReplyToBook": book.remote_id,
|
||||
"summary": "",
|
||||
"tag": [],
|
||||
"sensitive": False,
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
},
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.status.Status.ignore_activity") as discarder:
|
||||
discarder.return_value = False
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
boost = models.Boost.objects.get()
|
||||
self.assertEqual(boost.boosted_status.remote_id, "https://remote.com/status/1")
|
||||
self.assertEqual(boost.boosted_status.comment.status_type, "Comment")
|
||||
self.assertEqual(boost.boosted_status.comment.book, book)
|
||||
|
||||
@responses.activate
|
||||
def test_handle_discarded_boost(self):
|
||||
""" test a boost of a mastodon status that will be discarded """
|
||||
|
@ -618,7 +668,7 @@ class Inbox(TestCase):
|
|||
},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_status"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
|
|
@ -164,7 +164,7 @@ class InteractionViews(TestCase):
|
|||
self.assertEqual(models.Boost.objects.count(), 1)
|
||||
self.assertEqual(models.Notification.objects.count(), 1)
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_status"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
view(request, status.id)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
|
|
@ -177,7 +177,9 @@ class StatusViews(TestCase):
|
|||
content="hi", book=self.book, user=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.remove_status") as mock:
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertTrue(mock.called)
|
||||
result.render()
|
||||
|
@ -196,7 +198,9 @@ class StatusViews(TestCase):
|
|||
book=self.book, rating=2.0, user=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.remove_status") as mock:
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertFalse(mock.called)
|
||||
self.assertEqual(result.status_code, 400)
|
||||
|
@ -214,7 +218,9 @@ class StatusViews(TestCase):
|
|||
content="hi", user=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.remove_status") as mock:
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertFalse(mock.called)
|
||||
self.assertEqual(result.status_code, 400)
|
||||
|
@ -316,7 +322,7 @@ class StatusViews(TestCase):
|
|||
request.user = self.local_user
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_status"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
view(request, status.id)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
@ -351,7 +357,7 @@ class StatusViews(TestCase):
|
|||
request.user.is_superuser = True
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_status"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
view(request, status.id)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue