Merge pull request #1254 from bookwyrm-social/activitystreams-celery
Move activitystreams updates to tasks
This commit is contained in:
@ -19,7 +19,9 @@ class Inbox(TestCase):
|
||||
self.client = Client()
|
||||
self.factory = RequestFactory()
|
||||
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
|
@ -13,7 +13,9 @@ class InboxAdd(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
|
@ -13,7 +13,9 @@ class InboxActivities(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -35,7 +37,7 @@ class InboxActivities(TestCase):
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
@ -53,9 +55,8 @@ class InboxActivities(TestCase):
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||
def test_boost(self, redis_mock, _):
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
def test_boost(self, _):
|
||||
"""boost a status"""
|
||||
self.assertEqual(models.Notification.objects.count(), 0)
|
||||
activity = {
|
||||
@ -71,9 +72,6 @@ class InboxActivities(TestCase):
|
||||
discarder.return_value = False
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
# boost added to redis activitystreams
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
||||
# boost created of correct status
|
||||
boost = models.Boost.objects.get()
|
||||
self.assertEqual(boost.boosted_status, self.status)
|
||||
@ -84,9 +82,8 @@ class InboxActivities(TestCase):
|
||||
self.assertEqual(notification.related_status, self.status)
|
||||
|
||||
@responses.activate
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||
def test_boost_remote_status(self, redis_mock, _):
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
def test_boost_remote_status(self, _):
|
||||
"""boost a status from a remote server"""
|
||||
work = models.Work.objects.create(title="work title")
|
||||
book = models.Edition.objects.create(
|
||||
@ -127,7 +124,6 @@ class InboxActivities(TestCase):
|
||||
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")
|
||||
@ -141,7 +137,7 @@ class InboxActivities(TestCase):
|
||||
content="hi",
|
||||
user=self.remote_user,
|
||||
)
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
status.save(broadcast=False)
|
||||
activity = {
|
||||
"type": "Announce",
|
||||
@ -158,8 +154,9 @@ class InboxActivities(TestCase):
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertEqual(models.Boost.objects.count(), 0)
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
@patch("bookwyrm.activitystreams.handle_boost_task.delay")
|
||||
@patch("bookwyrm.activitystreams.remove_status_task.delay")
|
||||
def test_unboost(self, *_):
|
||||
"""undo a boost"""
|
||||
boost = models.Boost.objects.create(
|
||||
|
@ -12,7 +12,9 @@ class InboxBlock(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -54,7 +56,7 @@ class InboxBlock(TestCase):
|
||||
}
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_user_statuses"
|
||||
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
@ -67,7 +69,8 @@ class InboxBlock(TestCase):
|
||||
self.assertFalse(models.UserFollows.objects.exists())
|
||||
self.assertFalse(models.UserFollowRequest.objects.exists())
|
||||
|
||||
def test_handle_unblock(self):
|
||||
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
|
||||
def test_handle_unblock(self, _):
|
||||
"""unblock a user"""
|
||||
self.remote_user.blocks.add(self.local_user)
|
||||
|
||||
@ -92,7 +95,7 @@ class InboxBlock(TestCase):
|
||||
},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.add_user_statuses"
|
||||
"bookwyrm.activitystreams.add_user_statuses_task.delay"
|
||||
) as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
|
@ -11,12 +11,15 @@ from bookwyrm.activitypub import ActivitySerializerError
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
class InboxCreate(TestCase):
|
||||
"""readthrough tests"""
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -47,7 +50,6 @@ class InboxCreate(TestCase):
|
||||
}
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_create_status(self, *_):
|
||||
"""the "it justs works" mode"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||
@ -61,9 +63,7 @@ class InboxCreate(TestCase):
|
||||
activity = self.create_json
|
||||
activity["object"] = status_data
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
status = models.Quotation.objects.get()
|
||||
self.assertEqual(
|
||||
@ -77,7 +77,6 @@ class InboxCreate(TestCase):
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertEqual(models.Status.objects.count(), 1)
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_create_comment_with_reading_status(self, *_):
|
||||
"""the "it justs works" mode"""
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_comment.json")
|
||||
@ -90,9 +89,7 @@ class InboxCreate(TestCase):
|
||||
activity = self.create_json
|
||||
activity["object"] = status_data
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
status = models.Comment.objects.get()
|
||||
self.assertEqual(status.remote_id, "https://example.com/user/mouse/comment/6")
|
||||
@ -104,7 +101,7 @@ class InboxCreate(TestCase):
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertEqual(models.Status.objects.count(), 1)
|
||||
|
||||
def test_create_status_remote_note_with_mention(self, _):
|
||||
def test_create_status_remote_note_with_mention(self, *_):
|
||||
"""should only create it under the right circumstances"""
|
||||
self.assertFalse(
|
||||
models.Notification.objects.filter(user=self.local_user).exists()
|
||||
@ -115,9 +112,8 @@ class InboxCreate(TestCase):
|
||||
activity = self.create_json
|
||||
activity["object"] = status_data
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
status = models.Status.objects.last()
|
||||
self.assertEqual(status.content, "test content in note")
|
||||
self.assertEqual(status.mention_users.first(), self.local_user)
|
||||
@ -126,14 +122,13 @@ class InboxCreate(TestCase):
|
||||
)
|
||||
self.assertEqual(models.Notification.objects.get().notification_type, "MENTION")
|
||||
|
||||
def test_create_status_remote_note_with_reply(self, _):
|
||||
def test_create_status_remote_note_with_reply(self, *_):
|
||||
"""should only create it under the right circumstances"""
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
parent_status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
parent_status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
self.assertEqual(models.Status.objects.count(), 1)
|
||||
self.assertFalse(models.Notification.objects.filter(user=self.local_user))
|
||||
@ -145,16 +140,14 @@ class InboxCreate(TestCase):
|
||||
activity = self.create_json
|
||||
activity["object"] = status_data
|
||||
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
views.inbox.activity_task(activity)
|
||||
status = models.Status.objects.last()
|
||||
self.assertEqual(status.content, "test content in note")
|
||||
self.assertEqual(status.reply_parent, parent_status)
|
||||
self.assertTrue(models.Notification.objects.filter(user=self.local_user))
|
||||
self.assertEqual(models.Notification.objects.get().notification_type, "REPLY")
|
||||
|
||||
def test_create_rating(self, _):
|
||||
def test_create_rating(self, *_):
|
||||
"""a remote rating activity"""
|
||||
book = models.Edition.objects.create(
|
||||
title="Test Book", remote_id="https://example.com/book/1"
|
||||
@ -184,14 +177,12 @@ class InboxCreate(TestCase):
|
||||
"rating": 3,
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
views.inbox.activity_task(activity)
|
||||
rating = models.ReviewRating.objects.first()
|
||||
self.assertEqual(rating.book, book)
|
||||
self.assertEqual(rating.rating, 3.0)
|
||||
|
||||
def test_create_list(self, _):
|
||||
def test_create_list(self, *_):
|
||||
"""a new list"""
|
||||
activity = self.create_json
|
||||
activity["object"] = {
|
||||
@ -215,7 +206,7 @@ class InboxCreate(TestCase):
|
||||
self.assertEqual(book_list.description, "summary text")
|
||||
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
||||
|
||||
def test_create_unsupported_type(self, _):
|
||||
def test_create_unsupported_type(self, *_):
|
||||
"""ignore activities we know we can't handle"""
|
||||
activity = self.create_json
|
||||
activity["object"] = {
|
||||
@ -225,7 +216,7 @@ class InboxCreate(TestCase):
|
||||
# just observer how it doesn't throw an error
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
def test_create_unknown_type(self, _):
|
||||
def test_create_unknown_type(self, *_):
|
||||
"""ignore activities we know we've never heard of"""
|
||||
activity = self.create_json
|
||||
activity["object"] = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
""" tests incoming activities"""
|
||||
"""tests incoming activities"""
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
@ -13,7 +13,9 @@ class InboxActivities(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -33,7 +35,7 @@ class InboxActivities(TestCase):
|
||||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.remote_user,
|
||||
content="Test status",
|
||||
@ -53,9 +55,7 @@ class InboxActivities(TestCase):
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
# deletion doens't remove the status, it turns it into a tombstone
|
||||
@ -84,9 +84,7 @@ class InboxActivities(TestCase):
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||
}
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
) as redis_mock:
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
# deletion doens't remove the status, it turns it into a tombstone
|
||||
|
@ -13,7 +13,9 @@ class InboxRelationships(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -181,7 +183,8 @@ class InboxRelationships(TestCase):
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertIsNone(self.local_user.followers.first())
|
||||
|
||||
def test_follow_accept(self):
|
||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||
def test_follow_accept(self, _):
|
||||
"""a remote user approved a follow request from local"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
rel = models.UserFollowRequest.objects.create(
|
||||
|
@ -12,7 +12,9 @@ class InboxActivities(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -34,7 +36,7 @@ class InboxActivities(TestCase):
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
|
@ -12,7 +12,9 @@ class InboxRemove(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
|
@ -14,7 +14,9 @@ class InboxUpdate(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
@ -81,7 +83,8 @@ class InboxUpdate(TestCase):
|
||||
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
||||
|
||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||
def test_update_user(self, _):
|
||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||
def test_update_user(self, *_):
|
||||
"""update an existing user"""
|
||||
models.UserFollows.objects.create(
|
||||
user_subject=self.local_user,
|
||||
|
Reference in New Issue
Block a user