Updates mocks across tests

This commit is contained in:
Mouse Reeve 2021-11-12 09:17:00 -08:00
parent f71ef286b6
commit e6a251fdad
57 changed files with 253 additions and 212 deletions

View file

@ -66,9 +66,10 @@ class BookDataModel(ObjectMixin, BookWyrmModel):
self.remote_id = None self.remote_id = None
return super().save(*args, **kwargs) return super().save(*args, **kwargs)
def broadcast(self, activity, sender, software="bookwyrm"): # pylint: disable=arguments-differ
def broadcast(self, activity, sender, software="bookwyrm", **kwargs):
"""only send book data updates to other bookwyrm instances""" """only send book data updates to other bookwyrm instances"""
super().broadcast(activity, sender, software=software) super().broadcast(activity, sender, software=software, **kwargs)
class Book(BookDataModel): class Book(BookDataModel):

View file

@ -146,7 +146,7 @@ class BaseActivity(TestCase):
self.user.avatar.file # pylint: disable=pointless-statement self.user.avatar.file # pylint: disable=pointless-statement
# this would trigger a broadcast because it's a local user # this would trigger a broadcast because it's a local user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
activity.to_model(model=models.User, instance=self.user) activity.to_model(model=models.User, instance=self.user)
self.assertIsNotNone(self.user.avatar.file) self.assertIsNotNone(self.user.avatar.file)
self.assertEqual(self.user.name, "New Name") self.assertEqual(self.user.name, "New Name")
@ -154,7 +154,7 @@ class BaseActivity(TestCase):
def test_to_model_many_to_many(self, *_): def test_to_model_many_to_many(self, *_):
"""annoying that these all need special handling""" """annoying that these all need special handling"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create( status = models.Status.objects.create(
content="test status", content="test status",
user=self.user, user=self.user,
@ -186,7 +186,7 @@ class BaseActivity(TestCase):
def test_to_model_one_to_many(self, *_): def test_to_model_one_to_many(self, *_):
"""these are reversed relationships, where the secondary object """these are reversed relationships, where the secondary object
keys the primary object but not vice versa""" keys the primary object but not vice versa"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create( status = models.Status.objects.create(
content="test status", content="test status",
user=self.user, user=self.user,
@ -224,7 +224,7 @@ class BaseActivity(TestCase):
@responses.activate @responses.activate
def test_set_related_field(self, *_): def test_set_related_field(self, *_):
"""celery task to add back-references to created objects""" """celery task to add back-references to created objects"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create( status = models.Status.objects.create(
content="test status", content="test status",
user=self.user, user=self.user,

View file

@ -4,7 +4,7 @@ from django.test import TestCase
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")

View file

@ -4,7 +4,7 @@ from django.test import TestCase
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")

View file

@ -4,7 +4,7 @@ from django.test import TestCase
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")

View file

@ -4,7 +4,7 @@ from django.test import TestCase
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")

View file

@ -4,7 +4,7 @@ from django.test import TestCase
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class ActivitystreamsSignals(TestCase): class ActivitystreamsSignals(TestCase):
"""using redis to build activity streams""" """using redis to build activity streams"""

View file

@ -34,7 +34,7 @@ class Activitystreams(TestCase):
) )
work = models.Work.objects.create(title="test work") work = models.Work.objects.create(title="test work")
self.book = models.Edition.objects.create(title="test book", parent_work=work) self.book = models.Edition.objects.create(title="test book", parent_work=work)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.status = models.Status.objects.create( self.status = models.Status.objects.create(
content="hi", user=self.local_user content="hi", user=self.local_user
) )
@ -133,7 +133,7 @@ class Activitystreams(TestCase):
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_boost_to_another_timeline(self, *_): def test_boost_to_another_timeline(self, *_):
"""boost from a non-follower doesn't remove original status from feed""" """boost from a non-follower doesn't remove original status from feed"""
status = models.Status.objects.create(user=self.local_user, content="hi") status = models.Status.objects.create(user=self.local_user, content="hi")
@ -155,7 +155,7 @@ class Activitystreams(TestCase):
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_boost_to_another_timeline_remote(self, *_): def test_boost_to_another_timeline_remote(self, *_):
"""boost from a remote non-follower doesn't remove original status from feed""" """boost from a remote non-follower doesn't remove original status from feed"""
status = models.Status.objects.create(user=self.local_user, content="hi") status = models.Status.objects.create(user=self.local_user, content="hi")
@ -177,7 +177,7 @@ class Activitystreams(TestCase):
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_boost_to_following_timeline(self, *_): def test_boost_to_following_timeline(self, *_):
"""add a boost and deduplicate the boosted status on the timeline""" """add a boost and deduplicate the boosted status on the timeline"""
self.local_user.following.add(self.another_user) self.local_user.following.add(self.another_user)
@ -199,7 +199,7 @@ class Activitystreams(TestCase):
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores") @patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_boost_to_same_timeline(self, *_): def test_boost_to_same_timeline(self, *_):
"""add a boost and deduplicate the boosted status on the timeline""" """add a boost and deduplicate the boosted status on the timeline"""
status = models.Status.objects.create(user=self.local_user, content="hi") status = models.Status.objects.create(user=self.local_user, content="hi")

View file

@ -91,7 +91,7 @@ class GoodreadsImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public" self.importer.service, self.local_user, import_item, False, "public"
) )
@ -115,7 +115,7 @@ class GoodreadsImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, True, "unlisted" self.importer.service, self.local_user, import_item, True, "unlisted"
) )
@ -135,7 +135,7 @@ class GoodreadsImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, True, "unlisted" self.importer.service, self.local_user, import_item, True, "unlisted"
) )

View file

@ -114,7 +114,7 @@ class LibrarythingImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public" self.importer.service, self.local_user, import_item, False, "public"
) )
@ -129,7 +129,7 @@ class LibrarythingImport(TestCase):
def test_handle_imported_book_already_shelved(self, *_): def test_handle_imported_book_already_shelved(self, *_):
"""librarything import added a book, this adds related connections""" """librarything import added a book, this adds related connections"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
shelf = self.local_user.shelf_set.filter(identifier="to-read").first() shelf = self.local_user.shelf_set.filter(identifier="to-read").first()
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
shelf=shelf, user=self.local_user, book=self.book shelf=shelf, user=self.local_user, book=self.book
@ -142,7 +142,7 @@ class LibrarythingImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public" self.importer.service, self.local_user, import_item, False, "public"
) )
@ -166,7 +166,7 @@ class LibrarythingImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, True, "unlisted" self.importer.service, self.local_user, import_item, True, "unlisted"
) )

View file

@ -95,7 +95,7 @@ class StorygraphImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, False, "public" self.importer.service, self.local_user, import_item, False, "public"
) )
@ -116,7 +116,7 @@ class StorygraphImport(TestCase):
import_item.book = self.book import_item.book = self.book
import_item.save() import_item.save()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
handle_imported_book( handle_imported_book(
self.importer.service, self.local_user, import_item, True, "unlisted" self.importer.service, self.local_user, import_item, True, "unlisted"
) )

View file

@ -6,7 +6,7 @@ from bookwyrm import models
from bookwyrm.management.commands.populate_streams import populate_streams from bookwyrm.management.commands.populate_streams import populate_streams
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class Activitystreams(TestCase): class Activitystreams(TestCase):
"""using redis to build activity streams""" """using redis to build activity streams"""

View file

@ -21,7 +21,7 @@ from bookwyrm.settings import PAGE_LENGTH
# pylint: disable=invalid-name # pylint: disable=invalid-name
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class ActivitypubMixins(TestCase): class ActivitypubMixins(TestCase):
"""functionality shared across models""" """functionality shared across models"""

View file

@ -5,7 +5,7 @@ from django.test import TestCase
from bookwyrm import models, settings from bookwyrm import models, settings
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class Group(TestCase): class Group(TestCase):
"""some activitypub oddness ahead""" """some activitypub oddness ahead"""
@ -87,7 +87,7 @@ class Group(TestCase):
def test_group_members_can_see_followers_only_lists(self, _): def test_group_members_can_see_followers_only_lists(self, _):
"""follower-only group booklists should not be excluded from group booklist listing for group members who do not follower list owner""" """follower-only group booklists should not be excluded from group booklist listing for group members who do not follower list owner"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
followers_list = models.List.objects.create( followers_list = models.List.objects.create(
name="Followers List", name="Followers List",
curation="group", curation="group",
@ -107,7 +107,7 @@ class Group(TestCase):
def test_group_members_can_see_private_lists(self, _): def test_group_members_can_see_private_lists(self, _):
"""private group booklists should not be excluded from group booklist listing for group members""" """private group booklists should not be excluded from group booklist listing for group members"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
private_list = models.List.objects.create( private_list = models.List.objects.create(
name="Private List", name="Private List",

View file

@ -5,7 +5,7 @@ from django.test import TestCase
from bookwyrm import models, settings from bookwyrm import models, settings
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class List(TestCase): class List(TestCase):
"""some activitypub oddness ahead""" """some activitypub oddness ahead"""
@ -22,7 +22,7 @@ class List(TestCase):
def test_remote_id(self, _): def test_remote_id(self, _):
"""shelves use custom remote ids""" """shelves use custom remote ids"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
book_list = models.List.objects.create( book_list = models.List.objects.create(
name="Test List", user=self.local_user name="Test List", user=self.local_user
) )
@ -31,7 +31,7 @@ class List(TestCase):
def test_to_activity(self, _): def test_to_activity(self, _):
"""jsonify it""" """jsonify it"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
book_list = models.List.objects.create( book_list = models.List.objects.create(
name="Test List", user=self.local_user name="Test List", user=self.local_user
) )
@ -45,7 +45,7 @@ class List(TestCase):
def test_list_item(self, _): def test_list_item(self, _):
"""a list entry""" """a list entry"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
book_list = models.List.objects.create( book_list = models.List.objects.create(
name="Test List", user=self.local_user, privacy="unlisted" name="Test List", user=self.local_user, privacy="unlisted"
) )
@ -63,7 +63,7 @@ class List(TestCase):
def test_list_item_pending(self, _): def test_list_item_pending(self, _):
"""a list entry""" """a list entry"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
book_list = models.List.objects.create( book_list = models.List.objects.create(
name="Test List", user=self.local_user name="Test List", user=self.local_user
) )

View file

@ -33,11 +33,13 @@ class Relationship(TestCase):
def test_user_follows_from_request(self, _): def test_user_follows_from_request(self, _):
"""convert a follow request into a follow""" """convert a follow request into a follow"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
request = models.UserFollowRequest.objects.create( request = models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_object=self.remote_user user_subject=self.local_user, user_object=self.remote_user
) )
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Follow") self.assertEqual(activity["type"], "Follow")
self.assertEqual( self.assertEqual(
request.remote_id, "http://local.com/user/mouse#follows/%d" % request.id request.remote_id, "http://local.com/user/mouse#follows/%d" % request.id
@ -54,7 +56,7 @@ class Relationship(TestCase):
def test_user_follows_from_request_custom_remote_id(self, _): def test_user_follows_from_request_custom_remote_id(self, _):
"""store a specific remote id for a relationship provided by remote""" """store a specific remote id for a relationship provided by remote"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
request = models.UserFollowRequest.objects.create( request = models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_subject=self.local_user,
user_object=self.remote_user, user_object=self.remote_user,
@ -69,19 +71,19 @@ class Relationship(TestCase):
self.assertEqual(rel.user_subject, self.local_user) self.assertEqual(rel.user_subject, self.local_user)
self.assertEqual(rel.user_object, self.remote_user) self.assertEqual(rel.user_object, self.remote_user)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_follow_request_activity(self, broadcast_mock, _): def test_follow_request_activity(self, broadcast_mock, _):
"""accept a request and make it a relationship""" """accept a request and make it a relationship"""
models.UserFollowRequest.objects.create( models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_subject=self.local_user,
user_object=self.remote_user, user_object=self.remote_user,
) )
activity = json.loads(broadcast_mock.call_args[0][1]) activity = json.loads(broadcast_mock.call_args[1]["args"][1])
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"], self.remote_user.remote_id) self.assertEqual(activity["object"], self.remote_user.remote_id)
self.assertEqual(activity["type"], "Follow") self.assertEqual(activity["type"], "Follow")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_follow_request_accept(self, broadcast_mock, _): def test_follow_request_accept(self, broadcast_mock, _):
"""accept a request and make it a relationship""" """accept a request and make it a relationship"""
self.local_user.manually_approves_followers = True self.local_user.manually_approves_followers = True
@ -96,7 +98,7 @@ class Relationship(TestCase):
) )
request.accept() request.accept()
activity = json.loads(broadcast_mock.call_args[0][1]) activity = json.loads(broadcast_mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Accept") self.assertEqual(activity["type"], "Accept")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["id"], "https://www.hi.com/") self.assertEqual(activity["object"]["id"], "https://www.hi.com/")
@ -107,7 +109,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_subject, self.remote_user) self.assertEqual(rel.user_subject, self.remote_user)
self.assertEqual(rel.user_object, self.local_user) self.assertEqual(rel.user_object, self.local_user)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_follow_request_reject(self, broadcast_mock, _): def test_follow_request_reject(self, broadcast_mock, _):
"""accept a request and make it a relationship""" """accept a request and make it a relationship"""
self.local_user.manually_approves_followers = True self.local_user.manually_approves_followers = True
@ -120,7 +122,7 @@ class Relationship(TestCase):
) )
request.reject() request.reject()
activity = json.loads(broadcast_mock.call_args[0][1]) activity = json.loads(broadcast_mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Reject") self.assertEqual(activity["type"], "Reject")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["id"], request.remote_id) self.assertEqual(activity["object"]["id"], request.remote_id)

View file

@ -27,7 +27,7 @@ class Shelf(TestCase):
def test_remote_id(self, *_): def test_remote_id(self, *_):
"""shelves use custom remote ids""" """shelves use custom remote ids"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
@ -36,7 +36,7 @@ class Shelf(TestCase):
def test_to_activity(self, *_): def test_to_activity(self, *_):
"""jsonify it""" """jsonify it"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
@ -51,19 +51,23 @@ class Shelf(TestCase):
def test_create_update_shelf(self, *_): def test_create_update_shelf(self, *_):
"""create and broadcast shelf creation""" """create and broadcast shelf creation"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Create") self.assertEqual(activity["type"], "Create")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["name"], "Test Shelf") self.assertEqual(activity["object"]["name"], "Test Shelf")
shelf.name = "arthur russel" shelf.name = "arthur russel"
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
shelf.save() shelf.save()
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Update") self.assertEqual(activity["type"], "Update")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["name"], "arthur russel") self.assertEqual(activity["object"]["name"], "arthur russel")
@ -71,27 +75,31 @@ class Shelf(TestCase):
def test_shelve(self, *_): def test_shelve(self, *_):
"""create and broadcast shelf creation""" """create and broadcast shelf creation"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
shelf_book = models.ShelfBook.objects.create( shelf_book = models.ShelfBook.objects.create(
shelf=shelf, user=self.local_user, book=self.book shelf=shelf, user=self.local_user, book=self.book
) )
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["id"], shelf_book.remote_id) self.assertEqual(activity["object"]["id"], shelf_book.remote_id)
self.assertEqual(activity["target"], shelf.remote_id) self.assertEqual(activity["target"], shelf.remote_id)
self.assertEqual(shelf.books.first(), self.book) self.assertEqual(shelf.books.first(), self.book)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
shelf_book.delete() shelf_book.delete()
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Remove") self.assertEqual(activity["type"], "Remove")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["id"], shelf_book.remote_id) self.assertEqual(activity["object"]["id"], shelf_book.remote_id)

View file

@ -165,12 +165,12 @@ class User(TestCase):
"""deactivate a user""" """deactivate a user"""
self.assertTrue(self.user.is_active) self.assertTrue(self.user.is_active)
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as broadcast_mock: ) as broadcast_mock:
self.user.delete() self.user.delete()
self.assertEqual(broadcast_mock.call_count, 1) self.assertEqual(broadcast_mock.call_count, 1)
activity = json.loads(broadcast_mock.call_args[0][1]) activity = json.loads(broadcast_mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["object"], self.user.remote_id) self.assertEqual(activity["object"], self.user.remote_id)
self.assertFalse(self.user.is_active) self.assertFalse(self.user.is_active)

View file

@ -5,7 +5,7 @@ from django.test import TestCase
from bookwyrm import models from bookwyrm import models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class PostgresTriggers(TestCase): class PostgresTriggers(TestCase):
"""special migrations, fancy stuff ya know""" """special migrations, fancy stuff ya know"""

View file

@ -9,7 +9,7 @@ from bookwyrm import models
from bookwyrm.suggested_users import suggested_users, get_annotated_users from bookwyrm.suggested_users import suggested_users, get_annotated_users
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@ -168,7 +168,7 @@ class SuggestedUsers(TestCase):
remote_id="https://example.com/book/1", remote_id="https://example.com/book/1",
parent_work=work, parent_work=work,
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
# 1 shared follow # 1 shared follow
self.local_user.following.add(user_2) self.local_user.following.add(user_2)
user_1.followers.add(user_2) user_1.followers.add(user_2)
@ -213,7 +213,7 @@ class SuggestedUsers(TestCase):
user.following.add(user_1) user.following.add(user_1)
user.followers.add(self.local_user) user.followers.add(self.local_user)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
for i in range(3): for i in range(3):
book = models.Edition.objects.create( book = models.Edition.objects.create(
title=i, title=i,

View file

@ -44,7 +44,7 @@ class TemplateTags(TestCase):
def test_get_user_rating(self, *_): def test_get_user_rating(self, *_):
"""get a user's most recent rating of a book""" """get a user's most recent rating of a book"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.Review.objects.create(user=self.user, book=self.book, rating=3) models.Review.objects.create(user=self.user, book=self.book, rating=3)
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3) self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3)
@ -63,7 +63,7 @@ class TemplateTags(TestCase):
utilities.get_user_identifier(self.remote_user), "rat@example.com" utilities.get_user_identifier(self.remote_user), "rat@example.com"
) )
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_get_replies(self, *_): def test_get_replies(self, *_):
"""direct replies to a status""" """direct replies to a status"""
parent = models.Review.objects.create( parent = models.Review.objects.create(
@ -90,7 +90,7 @@ class TemplateTags(TestCase):
def test_get_parent(self, *_): def test_get_parent(self, *_):
"""get the reply parent of a status""" """get the reply parent of a status"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
parent = models.Review.objects.create( parent = models.Review.objects.create(
user=self.user, book=self.book, content="hi" user=self.user, book=self.book, content="hi"
) )
@ -107,7 +107,7 @@ class TemplateTags(TestCase):
status = models.Review.objects.create(user=self.remote_user, book=self.book) status = models.Review.objects.create(user=self.remote_user, book=self.book)
self.assertFalse(interaction.get_user_liked(self.user, status)) self.assertFalse(interaction.get_user_liked(self.user, status))
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.Favorite.objects.create(user=self.user, status=status) models.Favorite.objects.create(user=self.user, status=status)
self.assertTrue(interaction.get_user_liked(self.user, status)) self.assertTrue(interaction.get_user_liked(self.user, status))
@ -116,13 +116,13 @@ class TemplateTags(TestCase):
status = models.Review.objects.create(user=self.remote_user, book=self.book) status = models.Review.objects.create(user=self.remote_user, book=self.book)
self.assertFalse(interaction.get_user_boosted(self.user, status)) self.assertFalse(interaction.get_user_boosted(self.user, status))
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.Boost.objects.create(user=self.user, boosted_status=status) models.Boost.objects.create(user=self.user, boosted_status=status)
self.assertTrue(interaction.get_user_boosted(self.user, status)) self.assertTrue(interaction.get_user_boosted(self.user, status))
def test_get_boosted(self, *_): def test_get_boosted(self, *_):
"""load a boosted status""" """load a boosted status"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Review.objects.create(user=self.remote_user, book=self.book) status = models.Review.objects.create(user=self.remote_user, book=self.book)
boost = models.Boost.objects.create(user=self.user, boosted_status=status) boost = models.Boost.objects.create(user=self.user, boosted_status=status)
boosted = status_display.get_boosted(boost) boosted = status_display.get_boosted(boost)
@ -166,7 +166,7 @@ class TemplateTags(TestCase):
def test_related_status(self, *_): def test_related_status(self, *_):
"""gets the subclass model for a notification status""" """gets the subclass model for a notification status"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create(content="hi", user=self.user) status = models.Status.objects.create(content="hi", user=self.user)
notification = models.Notification.objects.create( notification = models.Notification.objects.create(
user=self.user, notification_type="MENTION", related_status=status user=self.user, notification_type="MENTION", related_status=status

View file

@ -151,10 +151,12 @@ class ReportViews(TestCase):
request.user.is_superuser = True request.user.is_superuser = True
# de-activate # de-activate
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.moderator_delete_user(request, self.rat.id) views.moderator_delete_user(request, self.rat.id)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["type"], "Delete")
self.rat.refresh_from_db() self.rat.refresh_from_db()

View file

@ -67,7 +67,7 @@ class UserAdminViews(TestCase):
request.user = self.local_user request.user = self.local_user
request.user.is_superuser = True request.user.is_superuser = True
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
result = view(request, self.local_user.id) result = view(request, self.local_user.id)
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)

View file

@ -78,7 +78,7 @@ class BookViews(TestCase):
self.assertIsInstance(result, ActivitypubResponse) self.assertIsInstance(result, ActivitypubResponse)
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
def test_book_page_statuses(self, *_): def test_book_page_statuses(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
@ -169,7 +169,7 @@ class BookViews(TestCase):
request.user = self.local_user request.user = self.local_user
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
views.upload_cover(request, self.book.id) views.upload_cover(request, self.book.id)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)
@ -188,7 +188,7 @@ class BookViews(TestCase):
request.user = self.local_user request.user = self.local_user
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
views.upload_cover(request, self.book.id) views.upload_cover(request, self.book.id)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)
@ -202,7 +202,7 @@ class BookViews(TestCase):
request = self.factory.post("", {"description": "new description hi"}) request = self.factory.post("", {"description": "new description hi"})
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.add_description(request, self.book.id) views.add_description(request, self.book.id)
self.book.refresh_from_db() self.book.refresh_from_db()

View file

@ -79,7 +79,7 @@ class EditBookViews(TestCase):
request = self.factory.post("", form.data) request = self.factory.post("", form.data)
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, self.book.id) view(request, self.book.id)
self.book.refresh_from_db() self.book.refresh_from_db()
@ -115,7 +115,7 @@ class EditBookViews(TestCase):
request = self.factory.post("", form.data) request = self.factory.post("", form.data)
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, self.book.id) view(request, self.book.id)
self.book.refresh_from_db() self.book.refresh_from_db()
@ -136,7 +136,7 @@ class EditBookViews(TestCase):
request = self.factory.post("", form.data) request = self.factory.post("", form.data)
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, self.book.id) view(request, self.book.id)
self.book.refresh_from_db() self.book.refresh_from_db()
self.assertEqual(self.book.title, "New Title") self.assertEqual(self.book.title, "New Title")
@ -207,7 +207,7 @@ class EditBookViews(TestCase):
request.user = self.local_user request.user = self.local_user
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
views.upload_cover(request, self.book.id) views.upload_cover(request, self.book.id)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)

View file

@ -111,7 +111,7 @@ class BookViews(TestCase):
work = models.Work.objects.create(title="test work") work = models.Work.objects.create(title="test work")
edition1 = models.Edition.objects.create(title="first ed", parent_work=work) edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
edition2 = models.Edition.objects.create(title="second ed", parent_work=work) edition2 = models.Edition.objects.create(title="second ed", parent_work=work)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user) shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user)
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=edition1, book=edition1,
@ -124,7 +124,7 @@ class BookViews(TestCase):
self.assertEqual(models.ReadThrough.objects.get().book, edition1) self.assertEqual(models.ReadThrough.objects.get().book, edition1)
request = self.factory.post("", {"edition": edition2.id}) request = self.factory.post("", {"edition": edition2.id})
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.switch_edition(request) views.switch_edition(request)
self.assertEqual(models.ShelfBook.objects.get().book, edition2) self.assertEqual(models.ShelfBook.objects.get().book, edition2)

View file

@ -36,7 +36,7 @@ class InboxActivities(TestCase):
outbox="https://example.com/users/rat/outbox", outbox="https://example.com/users/rat/outbox",
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
with patch("bookwyrm.activitystreams.add_status_task.delay"): with patch("bookwyrm.activitystreams.add_status_task.delay"):
self.status = models.Status.objects.create( self.status = models.Status.objects.create(
user=self.local_user, user=self.local_user,

View file

@ -40,7 +40,7 @@ class InboxBlock(TestCase):
def test_handle_blocks(self): def test_handle_blocks(self):
"""create a "block" database entry from an activity""" """create a "block" database entry from an activity"""
self.local_user.followers.add(self.remote_user) self.local_user.followers.add(self.remote_user)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.UserFollowRequest.objects.create( models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_object=self.remote_user user_subject=self.local_user, user_object=self.remote_user
) )

View file

@ -10,7 +10,7 @@ from bookwyrm.activitypub import ActivitySerializerError
# pylint: disable=too-many-public-methods # pylint: disable=too-many-public-methods
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
class InboxCreate(TestCase): class InboxCreate(TestCase):
"""readthrough tests""" """readthrough tests"""

View file

@ -49,10 +49,12 @@ class InboxRelationships(TestCase):
} }
self.assertFalse(models.UserFollowRequest.objects.exists()) self.assertFalse(models.UserFollowRequest.objects.exists())
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
response_activity = json.loads(mock.call_args[0][1]) response_activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(response_activity["type"], "Accept") self.assertEqual(response_activity["type"], "Accept")
# notification created # notification created
@ -77,17 +79,19 @@ class InboxRelationships(TestCase):
"object": "https://example.com/user/mouse", "object": "https://example.com/user/mouse",
} }
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
# the follow relationship should exist # the follow relationship should exist
follow = models.UserFollows.objects.get(user_object=self.local_user) follow = models.UserFollows.objects.get(user_object=self.local_user)
self.assertEqual(follow.user_subject, self.remote_user) self.assertEqual(follow.user_subject, self.remote_user)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
response_activity = json.loads(mock.call_args[0][1]) response_activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(response_activity["type"], "Accept") self.assertEqual(response_activity["type"], "Accept")
# the follow relationship should STILL exist # the follow relationship should STILL exist
@ -109,7 +113,7 @@ class InboxRelationships(TestCase):
broadcast=False, update_fields=["manually_approves_followers"] broadcast=False, update_fields=["manually_approves_followers"]
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.inbox.activity_task(activity) views.inbox.activity_task(activity)
# notification created # notification created
@ -132,7 +136,7 @@ class InboxRelationships(TestCase):
self.local_user.save( self.local_user.save(
broadcast=False, update_fields=["manually_approves_followers"] broadcast=False, update_fields=["manually_approves_followers"]
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
request = models.UserFollowRequest.objects.create( request = models.UserFollowRequest.objects.create(
user_subject=self.remote_user, user_object=self.local_user user_subject=self.remote_user, user_object=self.local_user
) )
@ -160,7 +164,7 @@ class InboxRelationships(TestCase):
def test_unfollow(self): def test_unfollow(self):
"""remove a relationship""" """remove a relationship"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
rel = models.UserFollows.objects.create( rel = models.UserFollows.objects.create(
user_subject=self.remote_user, user_object=self.local_user user_subject=self.remote_user, user_object=self.local_user
) )
@ -186,7 +190,7 @@ class InboxRelationships(TestCase):
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay") @patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
def test_follow_accept(self, _): def test_follow_accept(self, _):
"""a remote user approved a follow request from local""" """a remote user approved a follow request from local"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
rel = models.UserFollowRequest.objects.create( rel = models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_object=self.remote_user user_subject=self.local_user, user_object=self.remote_user
) )
@ -217,7 +221,7 @@ class InboxRelationships(TestCase):
def test_follow_reject(self): def test_follow_reject(self):
"""turn down a follow request""" """turn down a follow request"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
rel = models.UserFollowRequest.objects.create( rel = models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_object=self.remote_user user_subject=self.local_user, user_object=self.remote_user
) )

View file

@ -35,7 +35,7 @@ class InboxActivities(TestCase):
outbox="https://example.com/users/rat/outbox", outbox="https://example.com/users/rat/outbox",
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
with patch("bookwyrm.activitystreams.add_status_task.delay"): with patch("bookwyrm.activitystreams.add_status_task.delay"):
self.status = models.Status.objects.create( self.status = models.Status.objects.create(
user=self.local_user, user=self.local_user,

View file

@ -75,7 +75,7 @@ class InboxRemove(TestCase):
def test_handle_remove_book_from_list(self): def test_handle_remove_book_from_list(self):
"""listing a book""" """listing a book"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
booklist = models.List.objects.create( booklist = models.List.objects.create(
name="test list", name="test list",
user=self.local_user, user=self.local_user,

View file

@ -50,7 +50,7 @@ class InboxUpdate(TestCase):
def test_update_list(self): def test_update_list(self):
"""a new list""" """a new list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
book_list = models.List.objects.create( book_list = models.List.objects.create(
name="hi", remote_id="https://example.com/list/22", user=self.local_user name="hi", remote_id="https://example.com/list/22", user=self.local_user
) )
@ -171,7 +171,7 @@ class InboxUpdate(TestCase):
book = models.Work.objects.get(id=book.id) book = models.Work.objects.get(id=book.id)
self.assertEqual(book.title, "Piranesi") self.assertEqual(book.title, "Piranesi")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
def test_update_status(self, *_): def test_update_status(self, *_):
"""edit a status""" """edit a status"""

View file

@ -9,7 +9,7 @@ from bookwyrm import models, views
from bookwyrm.tests.validate_html import validate_html from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class BlockViews(TestCase): class BlockViews(TestCase):
"""view user and edit profile""" """view user and edit profile"""

View file

@ -35,9 +35,9 @@ class DeleteUserViews(TestCase):
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="test", parent_work=models.Work.objects.create(title="test work") title="test", parent_work=models.Work.objects.create(title="test work")
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"), patch( with patch(
"bookwyrm.activitystreams.add_book_statuses_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
): ), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, book=self.book,
user=self.local_user, user=self.local_user,
@ -70,11 +70,11 @@ class DeleteUserViews(TestCase):
self.assertIsNone(self.local_user.name) self.assertIsNone(self.local_user.name)
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
view(request) view(request)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)
activity = json.loads(delay_mock.call_args[0][1]) activity = json.loads(delay_mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual( self.assertEqual(

View file

@ -38,9 +38,9 @@ class EditUserViews(TestCase):
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="test", parent_work=models.Work.objects.create(title="test work") title="test", parent_work=models.Work.objects.create(title="test work")
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"), patch( with patch(
"bookwyrm.activitystreams.add_book_statuses_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
): ), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, book=self.book,
user=self.local_user, user=self.local_user,
@ -74,7 +74,7 @@ class EditUserViews(TestCase):
self.assertIsNone(self.local_user.name) self.assertIsNone(self.local_user.name)
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
view(request) view(request)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)
@ -100,7 +100,7 @@ class EditUserViews(TestCase):
request.user = self.local_user request.user = self.local_user
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
view(request) view(request)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)

View file

@ -11,7 +11,7 @@ from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.tests.validate_html import validate_html from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@ -39,7 +39,7 @@ class ShelfViews(TestCase):
remote_id="https://example.com/book/1", remote_id="https://example.com/book/1",
parent_work=self.work, parent_work=self.work,
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.shelf = models.Shelf.objects.create( self.shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
@ -142,7 +142,7 @@ class ShelfViews(TestCase):
"", {"privacy": "public", "user": self.local_user.id, "name": "cool name"} "", {"privacy": "public", "user": self.local_user.id, "name": "cool name"}
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, request.user.username, shelf.identifier) view(request, request.user.username, shelf.identifier)
shelf.refresh_from_db() shelf.refresh_from_db()
@ -159,7 +159,7 @@ class ShelfViews(TestCase):
"", {"privacy": "public", "user": self.local_user.id, "name": "cool name"} "", {"privacy": "public", "user": self.local_user.id, "name": "cool name"}
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, request.user.username, shelf.identifier) view(request, request.user.username, shelf.identifier)
self.assertEqual(shelf.name, "To Read") self.assertEqual(shelf.name, "To Read")

View file

@ -9,7 +9,7 @@ from django.test.client import RequestFactory
from bookwyrm import forms, models, views from bookwyrm import forms, models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@ -37,7 +37,7 @@ class ShelfActionViews(TestCase):
remote_id="https://example.com/book/1", remote_id="https://example.com/book/1",
parent_work=self.work, parent_work=self.work,
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.shelf = models.Shelf.objects.create( self.shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
@ -49,11 +49,13 @@ class ShelfActionViews(TestCase):
"", {"book": self.book.id, "shelf": self.shelf.identifier} "", {"book": self.book.id, "shelf": self.shelf.identifier}
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.shelve(request) views.shelve(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
item = models.ShelfBook.objects.get() item = models.ShelfBook.objects.get()
@ -69,7 +71,7 @@ class ShelfActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.shelve(request) views.shelve(request)
# make sure the book is on the shelf # make sure the book is on the shelf
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -82,7 +84,7 @@ class ShelfActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.shelve(request) views.shelve(request)
# make sure the book is on the shelf # make sure the book is on the shelf
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -95,7 +97,7 @@ class ShelfActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.shelve(request) views.shelve(request)
# make sure the book is on the shelf # make sure the book is on the shelf
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -118,7 +120,7 @@ class ShelfActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.shelve(request) views.shelve(request)
# make sure the book is on the shelf # make sure the book is on the shelf
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -126,7 +128,7 @@ class ShelfActionViews(TestCase):
def test_unshelve(self, *_): def test_unshelve(self, *_):
"""remove a book from a shelf""" """remove a book from a shelf"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, user=self.local_user, shelf=self.shelf book=self.book, user=self.local_user, shelf=self.shelf
) )
@ -136,9 +138,11 @@ class ShelfActionViews(TestCase):
self.assertEqual(self.shelf.books.count(), 1) self.assertEqual(self.shelf.books.count(), 1)
request = self.factory.post("", {"book": self.book.id, "shelf": self.shelf.id}) request = self.factory.post("", {"book": self.book.id, "shelf": self.shelf.id})
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.unshelve(request) views.unshelve(request)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Remove") self.assertEqual(activity["type"], "Remove")
self.assertEqual(activity["object"]["id"], item.remote_id) self.assertEqual(activity["object"]["id"], item.remote_id)
self.assertEqual(self.shelf.books.count(), 0) self.assertEqual(self.shelf.books.count(), 0)
@ -192,7 +196,7 @@ class ShelfActionViews(TestCase):
def test_delete_shelf_has_book(self, *_): def test_delete_shelf_has_book(self, *_):
"""delete a brand new custom shelf""" """delete a brand new custom shelf"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, user=self.local_user, shelf=self.shelf book=self.book, user=self.local_user, shelf=self.shelf
) )

View file

@ -111,7 +111,7 @@ class AuthorViews(TestCase):
request = self.factory.post("", form.data) request = self.factory.post("", form.data)
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, author.id) view(request, author.id)
author.refresh_from_db() author.refresh_from_db()
self.assertEqual(author.name, "New Name") self.assertEqual(author.name, "New Name")

View file

@ -41,7 +41,7 @@ class DiscoverViews(TestCase):
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
result.render() result.render()
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
def test_discover_page(self, *_): def test_discover_page(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""

View file

@ -57,7 +57,7 @@ class FeedViews(TestCase):
def test_status_page(self, *_): def test_status_page(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.Status.as_view() view = views.Status.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create(content="hi", user=self.local_user) status = models.Status.objects.create(content="hi", user=self.local_user)
request = self.factory.get("") request = self.factory.get("")
request.user = self.local_user request.user = self.local_user
@ -95,7 +95,7 @@ class FeedViews(TestCase):
local=True, local=True,
localname="rat", localname="rat",
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create(content="hi", user=another_user) status = models.Status.objects.create(content="hi", user=another_user)
request = self.factory.get("") request = self.factory.get("")
@ -115,7 +115,7 @@ class FeedViews(TestCase):
image = Image.open(image_file) image = Image.open(image_file)
output = BytesIO() output = BytesIO()
image.save(output, format=image.format) image.save(output, format=image.format)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Review.objects.create( status = models.Review.objects.create(
content="hi", content="hi",
user=self.local_user, user=self.local_user,
@ -144,7 +144,7 @@ class FeedViews(TestCase):
def test_replies_page(self, *_): def test_replies_page(self, *_):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.Replies.as_view() view = views.Replies.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
status = models.Status.objects.create(content="hi", user=self.local_user) status = models.Status.objects.create(content="hi", user=self.local_user)
request = self.factory.get("") request = self.factory.get("")
request.user = self.local_user request.user = self.local_user
@ -171,7 +171,7 @@ class FeedViews(TestCase):
result.render() result.render()
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
def test_get_suggested_book(self, *_): def test_get_suggested_book(self, *_):
"""gets books the ~*~ algorithm ~*~ thinks you want to post about""" """gets books the ~*~ algorithm ~*~ thinks you want to post about"""

View file

@ -59,7 +59,7 @@ class FollowViews(TestCase):
request.user = self.local_user request.user = self.local_user
self.assertEqual(models.UserFollowRequest.objects.count(), 0) self.assertEqual(models.UserFollowRequest.objects.count(), 0)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.follow(request) views.follow(request)
rel = models.UserFollowRequest.objects.get() rel = models.UserFollowRequest.objects.get()
@ -86,7 +86,7 @@ class FollowViews(TestCase):
request.user = self.local_user request.user = self.local_user
self.assertEqual(models.UserFollowRequest.objects.count(), 0) self.assertEqual(models.UserFollowRequest.objects.count(), 0)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.follow(request) views.follow(request)
rel = models.UserFollowRequest.objects.get() rel = models.UserFollowRequest.objects.get()
@ -111,7 +111,7 @@ class FollowViews(TestCase):
request.user = self.local_user request.user = self.local_user
self.assertEqual(models.UserFollowRequest.objects.count(), 0) self.assertEqual(models.UserFollowRequest.objects.count(), 0)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.follow(request) views.follow(request)
rel = models.UserFollows.objects.get() rel = models.UserFollows.objects.get()
@ -127,10 +127,12 @@ class FollowViews(TestCase):
request.user = self.local_user request.user = self.local_user
self.remote_user.followers.add(self.local_user) self.remote_user.followers.add(self.local_user)
self.assertEqual(self.remote_user.followers.count(), 1) self.assertEqual(self.remote_user.followers.count(), 1)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.unfollow(request) views.unfollow(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args_list[0][0][1]) activity = json.loads(mock.call_args_list[0][1]["args"][1])
self.assertEqual(activity["type"], "Undo") self.assertEqual(activity["type"], "Undo")
self.assertEqual(self.remote_user.followers.count(), 0) self.assertEqual(self.remote_user.followers.count(), 0)
@ -147,7 +149,7 @@ class FollowViews(TestCase):
user_subject=self.remote_user, user_object=self.local_user user_subject=self.remote_user, user_object=self.local_user
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.accept_follow_request(request) views.accept_follow_request(request)
# request should be deleted # request should be deleted
self.assertEqual(models.UserFollowRequest.objects.filter(id=rel.id).count(), 0) self.assertEqual(models.UserFollowRequest.objects.filter(id=rel.id).count(), 0)
@ -166,7 +168,7 @@ class FollowViews(TestCase):
user_subject=self.remote_user, user_object=self.local_user user_subject=self.remote_user, user_object=self.local_user
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.delete_follow_request(request) views.delete_follow_request(request)
# request should be deleted # request should be deleted
self.assertEqual(models.UserFollowRequest.objects.filter(id=rel.id).count(), 0) self.assertEqual(models.UserFollowRequest.objects.filter(id=rel.id).count(), 0)

View file

@ -56,7 +56,7 @@ class GetStartedViews(TestCase):
self.assertIsNone(self.local_user.name) self.assertIsNone(self.local_user.name)
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
view(request) view(request)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)
@ -98,7 +98,7 @@ class GetStartedViews(TestCase):
self.assertFalse(self.local_user.shelfbook_set.exists()) self.assertFalse(self.local_user.shelfbook_set.exists())
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as delay_mock: ) as delay_mock:
view(request) view(request)
self.assertEqual(delay_mock.call_count, 1) self.assertEqual(delay_mock.call_count, 1)

View file

@ -123,7 +123,7 @@ class GoalViews(TestCase):
}, },
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, self.local_user.localname, self.year) view(request, self.local_user.localname, self.year)
goal = models.AnnualGoal.objects.get() goal = models.AnnualGoal.objects.get()

View file

@ -10,7 +10,7 @@ from bookwyrm import models, views, forms
from bookwyrm.tests.validate_html import validate_html from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class GroupViews(TestCase): class GroupViews(TestCase):
"""view group and edit details""" """view group and edit details"""

View file

@ -55,7 +55,7 @@ class ViewsHelpers(TestCase):
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
self.userdata = json.loads(datafile.read_bytes()) self.userdata = json.loads(datafile.read_bytes())
del self.userdata["icon"] del self.userdata["icon"]
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.shelf = models.Shelf.objects.create( self.shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
@ -166,7 +166,7 @@ class ViewsHelpers(TestCase):
def test_handle_reading_status_to_read(self, *_): def test_handle_reading_status_to_read(self, *_):
"""posts shelve activities""" """posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="to-read") shelf = self.local_user.shelf_set.get(identifier="to-read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.helpers.handle_reading_status( views.helpers.handle_reading_status(
self.local_user, shelf, self.book, "public" self.local_user, shelf, self.book, "public"
) )
@ -178,7 +178,7 @@ class ViewsHelpers(TestCase):
def test_handle_reading_status_reading(self, *_): def test_handle_reading_status_reading(self, *_):
"""posts shelve activities""" """posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="reading") shelf = self.local_user.shelf_set.get(identifier="reading")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.helpers.handle_reading_status( views.helpers.handle_reading_status(
self.local_user, shelf, self.book, "public" self.local_user, shelf, self.book, "public"
) )
@ -190,7 +190,7 @@ class ViewsHelpers(TestCase):
def test_handle_reading_status_read(self, *_): def test_handle_reading_status_read(self, *_):
"""posts shelve activities""" """posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="read") shelf = self.local_user.shelf_set.get(identifier="read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.helpers.handle_reading_status( views.helpers.handle_reading_status(
self.local_user, shelf, self.book, "public" self.local_user, shelf, self.book, "public"
) )
@ -201,7 +201,7 @@ class ViewsHelpers(TestCase):
def test_handle_reading_status_other(self, *_): def test_handle_reading_status_other(self, *_):
"""posts shelve activities""" """posts shelve activities"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.helpers.handle_reading_status( views.helpers.handle_reading_status(
self.local_user, self.shelf, self.book, "public" self.local_user, self.shelf, self.book, "public"
) )

View file

@ -7,7 +7,7 @@ from django.test.client import RequestFactory
from bookwyrm import models, views from bookwyrm import models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.remove_status_task.delay") @patch("bookwyrm.activitystreams.remove_status_task.delay")
class InteractionViews(TestCase): class InteractionViews(TestCase):
"""viewing and creating statuses""" """viewing and creating statuses"""
@ -74,7 +74,7 @@ class InteractionViews(TestCase):
self.assertEqual(models.Favorite.objects.count(), 1) self.assertEqual(models.Favorite.objects.count(), 1)
self.assertEqual(models.Notification.objects.count(), 1) self.assertEqual(models.Notification.objects.count(), 1)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, status.id) view(request, status.id)
self.assertEqual(models.Favorite.objects.count(), 0) self.assertEqual(models.Favorite.objects.count(), 0)
self.assertEqual(models.Notification.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0)
@ -110,12 +110,12 @@ class InteractionViews(TestCase):
status = models.Status.objects.create(user=self.local_user, content="hi") status = models.Status.objects.create(user=self.local_user, content="hi")
with patch( with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as broadcast_mock: ) as broadcast_mock:
view(request, status.id) view(request, status.id)
self.assertEqual(broadcast_mock.call_count, 1) self.assertEqual(broadcast_mock.call_count, 1)
activity = json.loads(broadcast_mock.call_args[0][1]) activity = json.loads(broadcast_mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Announce") self.assertEqual(activity["type"], "Announce")
boost = models.Boost.objects.get() boost = models.Boost.objects.get()

View file

@ -61,7 +61,7 @@ class ListViews(TestCase):
parent_work=work_four, parent_work=work_four,
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.list = models.List.objects.create( self.list = models.List.objects.create(
name="Test List", user=self.local_user name="Test List", user=self.local_user
) )
@ -73,7 +73,7 @@ class ListViews(TestCase):
def test_lists_page(self): def test_lists_page(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.Lists.as_view() view = views.Lists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create( models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user name="Private list", privacy="direct", user=self.local_user
@ -96,7 +96,7 @@ class ListViews(TestCase):
def test_saved_lists_page(self): def test_saved_lists_page(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.SavedLists.as_view() view = views.SavedLists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
booklist = models.List.objects.create( booklist = models.List.objects.create(
name="Public list", user=self.local_user name="Public list", user=self.local_user
) )
@ -116,7 +116,7 @@ class ListViews(TestCase):
def test_saved_lists_page_empty(self): def test_saved_lists_page_empty(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.SavedLists.as_view() view = views.SavedLists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create( models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user name="Private list", privacy="direct", user=self.local_user
@ -153,11 +153,13 @@ class ListViews(TestCase):
}, },
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
result = view(request) result = view(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Create") self.assertEqual(activity["type"], "Create")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
@ -172,7 +174,7 @@ class ListViews(TestCase):
view = views.List.as_view() view = views.List.as_view()
request = self.factory.get("") request = self.factory.get("")
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -191,7 +193,7 @@ class ListViews(TestCase):
def test_list_page_sorted(self): def test_list_page_sorted(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.List.as_view() view = views.List.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
for (i, book) in enumerate([self.book, self.book_two, self.book_three]): for (i, book) in enumerate([self.book, self.book_two, self.book_three]):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
@ -253,7 +255,7 @@ class ListViews(TestCase):
def test_list_page_logged_out(self): def test_list_page_logged_out(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.List.as_view() view = views.List.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -276,7 +278,7 @@ class ListViews(TestCase):
view = views.List.as_view() view = views.List.as_view()
request = self.factory.get("") request = self.factory.get("")
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -320,11 +322,13 @@ class ListViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
result = view(request, self.list.id) result = view(request, self.list.id)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Update") self.assertEqual(activity["type"], "Update")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["id"], self.list.remote_id) self.assertEqual(activity["object"]["id"], self.list.remote_id)
@ -340,7 +344,7 @@ class ListViews(TestCase):
def test_curate_page(self): def test_curate_page(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.Curate.as_view() view = views.Curate.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create( models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user name="Private list", privacy="direct", user=self.local_user
@ -360,7 +364,7 @@ class ListViews(TestCase):
def test_user_lists_page(self): def test_user_lists_page(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.UserLists.as_view() view = views.UserLists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.List.objects.create(name="Public list", user=self.local_user) models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create( models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user name="Private list", privacy="direct", user=self.local_user

View file

@ -61,7 +61,7 @@ class ListActionViews(TestCase):
parent_work=work_four, parent_work=work_four,
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.list = models.List.objects.create( self.list = models.List.objects.create(
name="Test List", user=self.local_user name="Test List", user=self.local_user
) )
@ -71,7 +71,7 @@ class ListActionViews(TestCase):
def test_delete_list(self): def test_delete_list(self):
"""delete an entire list""" """delete an entire list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -88,9 +88,11 @@ class ListActionViews(TestCase):
) )
request = self.factory.post("") request = self.factory.post("")
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.delete_list(request, self.list.id) views.delete_list(request, self.list.id)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["object"]["id"], self.list.remote_id) self.assertEqual(activity["object"]["id"], self.list.remote_id)
@ -110,7 +112,7 @@ class ListActionViews(TestCase):
def test_curate_approve(self): def test_curate_approve(self):
"""approve a pending item""" """approve a pending item"""
view = views.Curate.as_view() view = views.Curate.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
pending = models.ListItem.objects.create( pending = models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -128,11 +130,13 @@ class ListActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
view(request, self.list.id) view(request, self.list.id)
self.assertEqual(mock.call_count, 2) self.assertEqual(mock.call_count, 2)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["target"], self.list.remote_id) self.assertEqual(activity["target"], self.list.remote_id)
@ -145,7 +149,7 @@ class ListActionViews(TestCase):
def test_curate_reject(self): def test_curate_reject(self):
"""approve a pending item""" """approve a pending item"""
view = views.Curate.as_view() view = views.Curate.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
pending = models.ListItem.objects.create( pending = models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -179,10 +183,12 @@ class ListActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.list.add_book(request) views.list.add_book(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["target"], self.list.remote_id) self.assertEqual(activity["target"], self.list.remote_id)
@ -214,7 +220,7 @@ class ListActionViews(TestCase):
}, },
) )
request_two.user = self.local_user request_two.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.list.add_book(request_one) views.list.add_book(request_one)
views.list.add_book(request_two) views.list.add_book(request_two)
@ -256,7 +262,7 @@ class ListActionViews(TestCase):
) )
request_three.user = self.local_user request_three.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.list.add_book(request_one) views.list.add_book(request_one)
views.list.add_book(request_two) views.list.add_book(request_two)
views.list.add_book(request_three) views.list.add_book(request_three)
@ -271,7 +277,7 @@ class ListActionViews(TestCase):
remove_request = self.factory.post("", {"item": items[1].id}) remove_request = self.factory.post("", {"item": items[1].id})
remove_request.user = self.local_user remove_request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.list.remove_book(remove_request, self.list.id) views.list.remove_book(remove_request, self.list.id)
items = self.list.listitem_set.order_by("order").all() items = self.list.listitem_set.order_by("order").all()
self.assertEqual(items[0].book, self.book) self.assertEqual(items[0].book, self.book)
@ -293,7 +299,7 @@ class ListActionViews(TestCase):
}, },
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -330,7 +336,7 @@ class ListActionViews(TestCase):
its order should be at the end of the approved books and before the its order should be at the end of the approved books and before the
remaining pending books. remaining pending books.
""" """
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create( models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -370,7 +376,7 @@ class ListActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
view(request, self.list.id) view(request, self.list.id)
items = self.list.listitem_set.order_by("order").all() items = self.list.listitem_set.order_by("order").all()
@ -422,7 +428,7 @@ class ListActionViews(TestCase):
) )
request_three.user = self.local_user request_three.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.list.add_book(request_one) views.list.add_book(request_one)
views.list.add_book(request_two) views.list.add_book(request_two)
views.list.add_book(request_three) views.list.add_book(request_three)
@ -437,7 +443,7 @@ class ListActionViews(TestCase):
set_position_request = self.factory.post("", {"position": 1}) set_position_request = self.factory.post("", {"position": 1})
set_position_request.user = self.local_user set_position_request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.list.set_book_position(set_position_request, items[2].id) views.list.set_book_position(set_position_request, items[2].id)
items = self.list.listitem_set.order_by("order").all() items = self.list.listitem_set.order_by("order").all()
self.assertEqual(items[0].book, self.book_three) self.assertEqual(items[0].book, self.book_three)
@ -460,10 +466,12 @@ class ListActionViews(TestCase):
) )
request.user = self.rat request.user = self.rat
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.list.add_book(request) views.list.add_book(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
self.assertEqual(activity["actor"], self.rat.remote_id) self.assertEqual(activity["actor"], self.rat.remote_id)
self.assertEqual(activity["target"], self.list.remote_id) self.assertEqual(activity["target"], self.list.remote_id)
@ -486,11 +494,13 @@ class ListActionViews(TestCase):
) )
request.user = self.rat request.user = self.rat
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.list.add_book(request) views.list.add_book(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
self.assertEqual(activity["actor"], self.rat.remote_id) self.assertEqual(activity["actor"], self.rat.remote_id)
@ -516,10 +526,12 @@ class ListActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
views.list.add_book(request) views.list.add_book(request)
self.assertEqual(mock.call_count, 1) self.assertEqual(mock.call_count, 1)
activity = json.loads(mock.call_args[0][1]) activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Add") self.assertEqual(activity["type"], "Add")
self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["target"], self.list.remote_id) self.assertEqual(activity["target"], self.list.remote_id)
@ -532,7 +544,7 @@ class ListActionViews(TestCase):
def test_remove_book(self): def test_remove_book(self):
"""take an item off a list""" """take an item off a list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
item = models.ListItem.objects.create( item = models.ListItem.objects.create(
book_list=self.list, book_list=self.list,
user=self.local_user, user=self.local_user,
@ -549,13 +561,13 @@ class ListActionViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.list.remove_book(request, self.list.id) views.list.remove_book(request, self.list.id)
self.assertFalse(self.list.listitem_set.exists()) self.assertFalse(self.list.listitem_set.exists())
def test_remove_book_unauthorized(self): def test_remove_book_unauthorized(self):
"""take an item off a list""" """take an item off a list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
item = models.ListItem.objects.create( item = models.ListItem.objects.create(
book_list=self.list, user=self.local_user, book=self.book, order=1 book_list=self.list, user=self.local_user, book=self.book, order=1
) )

View file

@ -25,7 +25,7 @@ class NotificationViews(TestCase):
local=True, local=True,
localname="mouse", localname="mouse",
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.status = models.Status.objects.create( self.status = models.Status.objects.create(
content="hi", content="hi",
user=self.local_user, user=self.local_user,

View file

@ -11,7 +11,7 @@ from bookwyrm.settings import USER_AGENT
# pylint: disable=too-many-public-methods # pylint: disable=too-many-public-methods
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class OutboxView(TestCase): class OutboxView(TestCase):
"""sends out activities""" """sends out activities"""

View file

@ -64,7 +64,7 @@ class ReadingViews(TestCase):
}, },
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.ReadingStatus.as_view()(request, "start", self.book.id) views.ReadingStatus.as_view()(request, "start", self.book.id)
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -100,7 +100,7 @@ class ReadingViews(TestCase):
}, },
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.ReadingStatus.as_view()(request, "start", self.book.id) views.ReadingStatus.as_view()(request, "start", self.book.id)
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -124,7 +124,7 @@ class ReadingViews(TestCase):
def test_start_reading_reshelve(self, *_): def test_start_reading_reshelve(self, *_):
"""begin a book""" """begin a book"""
to_read_shelf = self.local_user.shelf_set.get(identifier=models.Shelf.TO_READ) to_read_shelf = self.local_user.shelf_set.get(identifier=models.Shelf.TO_READ)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
shelf=to_read_shelf, book=self.book, user=self.local_user shelf=to_read_shelf, book=self.book, user=self.local_user
) )
@ -135,7 +135,7 @@ class ReadingViews(TestCase):
request = self.factory.post("") request = self.factory.post("")
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.ReadingStatus.as_view()(request, "start", self.book.id) views.ReadingStatus.as_view()(request, "start", self.book.id)
self.assertFalse(to_read_shelf.books.exists()) self.assertFalse(to_read_shelf.books.exists())
@ -162,7 +162,7 @@ class ReadingViews(TestCase):
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.ReadingStatus.as_view()(request, "finish", self.book.id) views.ReadingStatus.as_view()(request, "finish", self.book.id)
self.assertEqual(shelf.books.get(), self.book) self.assertEqual(shelf.books.get(), self.book)
@ -267,7 +267,7 @@ class ReadingViews(TestCase):
}, },
) )
request.user = self.local_user request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
views.update_progress(request, self.book.id) views.update_progress(request, self.book.id)
status = models.Comment.objects.get() status = models.Comment.objects.get()

View file

@ -9,7 +9,7 @@ from bookwyrm import models
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay") @patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
class ReadThrough(TestCase): class ReadThrough(TestCase):
@ -32,7 +32,7 @@ class ReadThrough(TestCase):
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.client.force_login(self.user) self.client.force_login(self.user)
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")

View file

@ -6,7 +6,7 @@ from bookwyrm import models
from bookwyrm.views import rss_feed from bookwyrm.views import rss_feed
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay")
class RssFeedView(TestCase): class RssFeedView(TestCase):

View file

@ -139,7 +139,7 @@ class Views(TestCase):
def test_search_lists(self): def test_search_lists(self):
"""searches remote connectors""" """searches remote connectors"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
booklist = models.List.objects.create( booklist = models.List.objects.create(
user=self.local_user, name="test list" user=self.local_user, name="test list"
) )

View file

@ -14,7 +14,7 @@ from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.remove_status_task.delay") @patch("bookwyrm.activitystreams.remove_status_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class StatusViews(TestCase): class StatusViews(TestCase):
"""viewing and creating statuses""" """viewing and creating statuses"""
@ -310,7 +310,7 @@ http://www.fish.com/"""
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock: with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
view(request, status.id) view(request, status.id)
self.assertTrue(redis_mock.called) self.assertTrue(redis_mock.called)
activity = json.loads(mock.call_args_list[1][0][1]) activity = json.loads(mock.call_args_list[1][1]["args"][1])
self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["object"]["type"], "Tombstone") self.assertEqual(activity["object"]["type"], "Tombstone")
status.refresh_from_db() status.refresh_from_db()
@ -344,7 +344,7 @@ http://www.fish.com/"""
with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock: with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock:
view(request, status.id) view(request, status.id)
self.assertTrue(redis_mock.called) self.assertTrue(redis_mock.called)
activity = json.loads(mock.call_args_list[1][0][1]) activity = json.loads(mock.call_args_list[1][1]["args"][1])
self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["object"]["type"], "Tombstone") self.assertEqual(activity["object"]["type"], "Tombstone")
status.refresh_from_db() status.refresh_from_db()
@ -396,7 +396,7 @@ http://www.fish.com/"""
request.user = self.local_user request.user = self.local_user
view(request, "comment", existing_status_id=status.id) view(request, "comment", existing_status_id=status.id)
activity = json.loads(mock.call_args_list[1][0][1]) activity = json.loads(mock.call_args_list[1][1]["args"][1])
self.assertEqual(activity["type"], "Update") self.assertEqual(activity["type"], "Update")
self.assertEqual(activity["object"]["id"], status.remote_id) self.assertEqual(activity["object"]["id"], status.remote_id)

View file

@ -34,9 +34,11 @@ class UserViews(TestCase):
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="test", parent_work=models.Work.objects.create(title="test work") title="test", parent_work=models.Work.objects.create(title="test work")
) )
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"), patch( with patch(
"bookwyrm.suggested_users.rerank_suggestions_task.delay" "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"): ), patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.add_book_statuses_task.delay"
):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(
book=self.book, book=self.book,
user=self.local_user, user=self.local_user,