Merge pull request #879 from mouse-reeve/redis-stores
Created generic redis class for activitystreams
This commit is contained in:
@ -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,
|
||||
|
@ -444,7 +444,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)
|
||||
@ -477,7 +477,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)
|
||||
@ -666,7 +666,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)
|
||||
|
Reference in New Issue
Block a user