From 1fbca70820af0434f46be4b33ea324f6ce4b7524 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Aug 2021 19:54:47 -0700 Subject: [PATCH 01/23] Move activitystreams updates to tasks --- bookwyrm/activitystreams.py | 116 +++++++++++++++++++++++++++--------- celerywyrm/celery.py | 1 + 2 files changed, 90 insertions(+), 27 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index a49a7ce4d..543a8a7e1 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -1,9 +1,11 @@ """ access the activity streams stored in redis """ from django.dispatch import receiver +from django.db import transaction from django.db.models import signals, Q from bookwyrm import models from bookwyrm.redis_store import RedisStore, r +from bookwyrm.tasks import app from bookwyrm.views.helpers import privacy_filter @@ -190,16 +192,20 @@ def add_status_on_create(sender, instance, created, *args, **kwargs): return if instance.deleted: - for stream in streams.values(): - stream.remove_object_from_related_stores(instance) + remove_status_task.delay(instance.id) return if not created: return + # when creating new things, gotta wait on the transaction + transaction.on_commit(lambda: add_status_on_create_command(sender, instance)) + + +def add_status_on_create_command(sender, instance): + """runs this code only after the database commit completes""" # iterates through Home, Local, Federated - for stream in streams.values(): - stream.add_status(instance) + add_status_task.delay(instance.id) if sender != models.Boost: return @@ -208,23 +214,19 @@ def add_status_on_create(sender, instance, created, *args, **kwargs): old_versions = models.Boost.objects.filter( boosted_status__id=boosted.id, created_date__lt=instance.created_date, - ) - for stream in streams.values(): - stream.remove_object_from_related_stores(boosted) - for status in old_versions: - stream.remove_object_from_related_stores(status) + ).values_list("id", flat=True) + remove_status_task.delay(boosted.id) + remove_status_task.delay(old_versions) @receiver(signals.post_delete, sender=models.Boost) # pylint: disable=unused-argument def remove_boost_on_delete(sender, instance, *args, **kwargs): """boosts are deleted""" - # we're only interested in new statuses - for stream in streams.values(): - # remove the boost - stream.remove_object_from_related_stores(instance) - # re-add the original status - stream.add_status(instance.boosted_status) + # remove the boost + remove_status_task.delay(instance.id) + # re-add the original status + add_status_task.delay(instance.boosted_status.id) @receiver(signals.post_save, sender=models.UserFollows) @@ -233,7 +235,9 @@ def add_statuses_on_follow(sender, instance, created, *args, **kwargs): """add a newly followed user's statuses to feeds""" if not created or not instance.user_subject.local: return - HomeStream().add_user_statuses(instance.user_subject, instance.user_object) + add_user_statuses_task.delay( + instance.user_subject.id, instance.user_object.id, stream_list=["home"] + ) @receiver(signals.post_delete, sender=models.UserFollows) @@ -242,7 +246,9 @@ def remove_statuses_on_unfollow(sender, instance, *args, **kwargs): """remove statuses from a feed on unfollow""" if not instance.user_subject.local: return - HomeStream().remove_user_statuses(instance.user_subject, instance.user_object) + remove_user_statuses_task.delay( + instance.user_subject.id, instance.user_object.id, stream_list=["home"] + ) @receiver(signals.post_save, sender=models.UserBlocks) @@ -251,29 +257,36 @@ def remove_statuses_on_block(sender, instance, *args, **kwargs): """remove statuses from all feeds on block""" # blocks apply ot all feeds if instance.user_subject.local: - for stream in streams.values(): - stream.remove_user_statuses(instance.user_subject, instance.user_object) + remove_user_statuses_task.delay( + instance.user_subject.id, instance.user_object.id + ) # and in both directions if instance.user_object.local: - for stream in streams.values(): - stream.remove_user_statuses(instance.user_object, instance.user_subject) + remove_user_statuses_task.delay( + instance.user_object.id, instance.user_subject.id + ) @receiver(signals.post_delete, sender=models.UserBlocks) # pylint: disable=unused-argument def add_statuses_on_unblock(sender, instance, *args, **kwargs): """remove statuses from all feeds on block""" - public_streams = [LocalStream(), FederatedStream()] # add statuses back to streams with statuses from anyone if instance.user_subject.local: - for stream in public_streams: - stream.add_user_statuses(instance.user_subject, instance.user_object) + add_user_statuses_task.delay( + instance.user_subject.id, + instance.user_object.id, + stream_list=["local", "federated"], + ) # add statuses back to streams with statuses from anyone if instance.user_object.local: - for stream in public_streams: - stream.add_user_statuses(instance.user_object, instance.user_subject) + add_user_statuses_task.delay( + instance.user_object.id, + instance.user_subject.id, + stream_list=["local", "federated"], + ) @receiver(signals.post_save, sender=models.User) @@ -283,5 +296,54 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg if not created or not instance.local: return + populate_streams_task.delay(instance.id) + + +# ---- TASKS + +@app.task +def populate_streams_task(user_id): + """create a user's streams""" + user = models.User.objects.get(id=user_id) for stream in streams.values(): - stream.populate_streams(instance) + stream.populate_streams(user) + +@app.task +def remove_status_task(status_ids): + """remove a status from any stream it might be in""" + # this can take an id or a list of ids + if not isinstance(status_ids, list): + status_ids = [status_ids] + statuses = models.Status.objects.filter(id__in=status_ids) + + for stream in streams.values(): + for status in statuses: + stream.remove_object_from_related_stores(status) + + +@app.task +def add_status_task(status_id): + """remove a status from any stream it might be in""" + status = models.Status.objects.get(id=status_id) + for stream in streams.values(): + stream.add_status(status) + + +@app.task +def remove_user_statuses_task(viewer_id, user_id, stream_list=None): + """remove all statuses by a user from a viewer's stream""" + stream_list = [streams[s] for s in stream_list] if stream_list else streams.values() + viewer = models.User.objects.get(id=viewer_id) + user = models.User.objects.get(id=user_id) + for stream in stream_list: + stream.remove_user_statuses(viewer, user) + + +@app.task +def add_user_statuses_task(viewer_id, user_id, stream_list=None): + """remove all statuses by a user from a viewer's stream""" + stream_list = [streams[s] for s in stream_list] if stream_list else streams.values() + viewer = models.User.objects.get(id=viewer_id) + user = models.User.objects.get(id=user_id) + for stream in stream_list: + stream.add_user_statuses(viewer, user) diff --git a/celerywyrm/celery.py b/celerywyrm/celery.py index 3ab338621..de5e56304 100644 --- a/celerywyrm/celery.py +++ b/celerywyrm/celery.py @@ -20,6 +20,7 @@ app.config_from_object("django.conf:settings", namespace="CELERY") # Load task modules from all registered Django app configs. app.autodiscover_tasks() app.autodiscover_tasks(["bookwyrm"], related_name="activitypub.base_activity") +app.autodiscover_tasks(["bookwyrm"], related_name="activitystreams") app.autodiscover_tasks(["bookwyrm"], related_name="broadcast") app.autodiscover_tasks(["bookwyrm"], related_name="connectors.abstract_connector") app.autodiscover_tasks(["bookwyrm"], related_name="emailing") From 6841a66e76c3acd45acc3e56bf310f1bad6763db Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Aug 2021 19:57:39 -0700 Subject: [PATCH 02/23] Python formatting --- bookwyrm/activitystreams.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 543a8a7e1..4e48a0444 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -301,6 +301,7 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg # ---- TASKS + @app.task def populate_streams_task(user_id): """create a user's streams""" @@ -308,6 +309,7 @@ def populate_streams_task(user_id): for stream in streams.values(): stream.populate_streams(user) + @app.task def remove_status_task(status_ids): """remove a status from any stream it might be in""" From 120938bee98725cf4c490b9d607147d04e246152 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 5 Aug 2021 19:28:05 -0700 Subject: [PATCH 03/23] Update books feed on shelve --- bookwyrm/activitystreams.py | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 961b9797c..4137c6bf6 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -201,6 +201,40 @@ class BooksStream(ActivityStream): privacy_levels=["public"], ) + def add_book_statuses(self, user, book): + """add statuses about a book to a user's feed""" + work = book.parent_work + statuses = privacy_filter( + user, + models.Status.objects.select_subclasses() + .filter( + Q(comment__book__parent_work=work) + | Q(quotation__book__parent_work=work) + | Q(review__book__parent_work=work) + | Q(mention_books__parent_work=work) + ) + .distinct(), + privacy_levels=["public"], + ) + self.bulk_add_objects_to_store(statuses, self.stream_id(user)) + + def remove_book_statuses(self, user, book): + """add statuses about a book to a user's feed""" + work = book.parent_work + statuses = privacy_filter( + user, + models.Status.objects.select_subclasses() + .filter( + Q(comment__book__parent_work=work) + | Q(quotation__book__parent_work=work) + | Q(review__book__parent_work=work) + | Q(mention_books__parent_work=work) + ) + .distinct(), + privacy_levels=["public"], + ) + self.bulk_remove_objects_from_store(statuses, self.stream_id(user)) + # determine which streams are enabled in settings.py available_streams = [s["key"] for s in STREAMS] @@ -331,6 +365,36 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg populate_streams_task.delay(instance.id) +@receiver(signals.pre_save, sender=models.ShelfBook) +# pylint: disable=unused-argument +def add_statuses_on_shelve(sender, instance, created, *args, **kwargs): + """update books stream when user shelves a book""" + if not created or not instance.user.local: + return + # check if the book is already on the user's shelves + if models.ShelfBook.objects.filter( + user=instance.user, book__in=instance.book.parent_work.editions.all() + ).exists(): + return + + BooksStream().add_book_statuses(instance.user, instance.book) + + +@receiver(signals.post_delete, sender=models.ShelfBook) +# pylint: disable=unused-argument +def remove_statuses_on_shelve(sender, instance, *args, **kwargs): + """update books stream when user unshelves a book""" + if not instance.user.local: + return + # check if the book is actually unshelved, not just moved + if models.ShelfBook.objects.filter( + user=instance.user, book__in=instance.book.parent_work.editions.all() + ).exists(): + return + + BooksStream().remove_book_statuses(instance.user, instance.book) + + # ---- TASKS From 061deaefda40ca3016514a6d514373a0f0b19b71 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 5 Aug 2021 17:13:47 -0700 Subject: [PATCH 04/23] Removes invalid argument --- bookwyrm/activitystreams.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 4137c6bf6..ebe2cbd97 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -367,9 +367,9 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg @receiver(signals.pre_save, sender=models.ShelfBook) # pylint: disable=unused-argument -def add_statuses_on_shelve(sender, instance, created, *args, **kwargs): +def add_statuses_on_shelve(sender, instance, *args, **kwargs): """update books stream when user shelves a book""" - if not created or not instance.user.local: + if not instance.user.local: return # check if the book is already on the user's shelves if models.ShelfBook.objects.filter( From 6b7e3f2061d38c131a4098575e0edd6bf4595c21 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 5 Aug 2021 17:19:39 -0700 Subject: [PATCH 05/23] Adds books stream mock --- bookwyrm/tests/test_activitystreams.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index ba4950895..ac57d8b3d 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -6,6 +6,7 @@ from bookwyrm import activitystreams, models @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.BooksStream.add_book_statuses") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class Activitystreams(TestCase): """using redis to build activity streams""" From b3fa8de65aaf547edadaec224e9f39a01298b79c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 5 Aug 2021 17:47:28 -0700 Subject: [PATCH 06/23] fixes book mock in user view tests --- bookwyrm/tests/views/test_edit_user.py | 4 +++- bookwyrm/tests/views/test_user.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/test_edit_user.py b/bookwyrm/tests/views/test_edit_user.py index ccfb4c90d..df89d5b09 100644 --- a/bookwyrm/tests/views/test_edit_user.py +++ b/bookwyrm/tests/views/test_edit_user.py @@ -34,7 +34,9 @@ class EditUserViews(TestCase): "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" ) - self.book = models.Edition.objects.create(title="test") + self.book = models.Edition.objects.create( + title="test", parent_work=models.Work.objects.create(title="test work") + ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): models.ShelfBook.objects.create( book=self.book, diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 0efdf16a3..740f0d299 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -28,7 +28,9 @@ class UserViews(TestCase): self.rat = models.User.objects.create_user( "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" ) - self.book = models.Edition.objects.create(title="test") + self.book = models.Edition.objects.create( + title="test", parent_work=models.Work.objects.create(title="test work") + ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): models.ShelfBook.objects.create( From c3ff7fcf9b68848a56f8979378f1cb15437ba8b1 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 30 Aug 2021 13:44:19 -0700 Subject: [PATCH 07/23] Resolves merge weirdness --- bookwyrm/activitystreams.py | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 0755314bc..621f06dab 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -360,7 +360,8 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg if not created or not instance.local: return - populate_streams_task.delay(instance.id) + for stream in streams.values(): + populate_stream_task.delay(stream, instance.id) @receiver(signals.pre_save, sender=models.ShelfBook) @@ -393,28 +394,6 @@ def remove_statuses_on_shelve(sender, instance, *args, **kwargs): BooksStream().remove_book_statuses(instance.user, instance.book) -@receiver(signals.pre_save, sender=models.ShelfBook) -# pylint: disable=unused-argument -def add_statuses_on_shelve(sender, instance, *args, **kwargs): - """update books stream when user shelves a book""" - if not instance.user.local: - return - book = None - if hasattr(instance, "book"): - book = instance.book - elif instance.mention_books.exists(): - book = instance.mention_books.first() - if not book: - return - - # check if the book is already on the user's shelves - editions = book.parent_work.editions.all() - if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists(): - return - - BooksStream().add_book_statuses(instance.user, book) - - @receiver(signals.post_delete, sender=models.ShelfBook) # pylint: disable=unused-argument def remove_statuses_on_unshelve(sender, instance, *args, **kwargs): @@ -439,16 +418,6 @@ def remove_statuses_on_unshelve(sender, instance, *args, **kwargs): # ---- TASKS -# TODO: merge conflict: reconcile these tasks - -@app.task -def populate_streams_task(user_id): - """create a user's streams""" - user = models.User.objects.get(id=user_id) - for stream in streams.values(): - stream.populate_streams(user) - - @app.task def populate_stream_task(stream, user_id): """background task for populating an empty activitystream""" @@ -495,4 +464,4 @@ def add_user_statuses_task(viewer_id, user_id, stream_list=None): viewer = models.User.objects.get(id=viewer_id) user = models.User.objects.get(id=user_id) for stream in stream_list: - stream.add_user_statuses(viewer, user) \ No newline at end of file + stream.add_user_statuses(viewer, user) From 32f044445f1baa2b3b694282ab0d7fdffd91be22 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 30 Aug 2021 13:50:54 -0700 Subject: [PATCH 08/23] Fix merge weirdness around shelve/unshelve --- bookwyrm/activitystreams.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index a5f95ac9d..aa627b7a1 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -373,28 +373,20 @@ def add_statuses_on_shelve(sender, instance, *args, **kwargs): """update books stream when user shelves a book""" if not instance.user.local: return + book = None + if hasattr(instance, "book"): + book = instance.book + elif instance.mention_books.exists(): + book = instance.mention_books.first() + if not book: + return + # check if the book is already on the user's shelves - if models.ShelfBook.objects.filter( - user=instance.user, book__in=instance.book.parent_work.editions.all() - ).exists(): + editions = book.parent_work.editions.all() + if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists(): return - BooksStream().add_book_statuses(instance.user, instance.book) - - -@receiver(signals.post_delete, sender=models.ShelfBook) -# pylint: disable=unused-argument -def remove_statuses_on_shelve(sender, instance, *args, **kwargs): - """update books stream when user unshelves a book""" - if not instance.user.local: - return - # check if the book is actually unshelved, not just moved - if models.ShelfBook.objects.filter( - user=instance.user, book__in=instance.book.parent_work.editions.all() - ).exists(): - return - - BooksStream().remove_book_statuses(instance.user, instance.book) + BooksStream().add_book_statuses(instance.user, book) @receiver(signals.post_delete, sender=models.ShelfBook) @@ -421,6 +413,7 @@ def remove_statuses_on_unshelve(sender, instance, *args, **kwargs): # ---- TASKS + @app.task def populate_stream_task(stream, user_id): """background task for populating an empty activitystream""" From d7557926f7a2eba1d8444d8e0e25048b3dcb2f68 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 30 Aug 2021 14:06:29 -0700 Subject: [PATCH 09/23] Create task for shelve updates --- bookwyrm/activitystreams.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index aa627b7a1..cb59f1a7f 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -373,20 +373,14 @@ def add_statuses_on_shelve(sender, instance, *args, **kwargs): """update books stream when user shelves a book""" if not instance.user.local: return - book = None - if hasattr(instance, "book"): - book = instance.book - elif instance.mention_books.exists(): - book = instance.mention_books.first() - if not book: - return + book = instance.book # check if the book is already on the user's shelves editions = book.parent_work.editions.all() if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists(): return - BooksStream().add_book_statuses(instance.user, book) + add_book_statuses_task.delay(instance.user.id, book.id) @receiver(signals.post_delete, sender=models.ShelfBook) @@ -396,24 +390,35 @@ def remove_statuses_on_unshelve(sender, instance, *args, **kwargs): if not instance.user.local: return - book = None - if hasattr(instance, "book"): - book = instance.book - elif instance.mention_books.exists(): - book = instance.mention_books.first() - if not book: - return + book = instance.book + # check if the book is actually unshelved, not just moved editions = book.parent_work.editions.all() if models.ShelfBook.objects.filter(user=instance.user, book__in=editions).exists(): return - BooksStream().remove_book_statuses(instance.user, instance.book) + remove_book_statuses_task.delay(instance.user.id, book.id) # ---- TASKS +@app.task +def add_book_statuses_task(user_id, book_id): + """add statuses related to a book on shelve""" + user = models.User.objects.get(id=user_id) + book = models.Edition.objects.get(id=book_id) + BooksStream().add_book_statuses(user, book) + + +@app.task +def remove_book_statuses_task(user_id, book_id): + """remove statuses about a book from a user's books feed""" + user = models.User.objects.get(id=user_id) + book = models.Edition.objects.get(id=book_id) + BooksStream().remove_book_statuses(user, book) + + @app.task def populate_stream_task(stream, user_id): """background task for populating an empty activitystream""" From a6b0ba1826f53cd865cd5eacbf81e72a22a5d74c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 13:53:49 -0700 Subject: [PATCH 10/23] Updates activistreams add_status mock --- .../tests/activitypub/test_base_activity.py | 2 +- .../tests/importers/test_goodreads_import.py | 4 ++-- .../importers/test_librarything_import.py | 2 +- .../tests/management/test_populate_streams.py | 2 +- .../tests/models/test_activitypub_mixin.py | 2 +- bookwyrm/tests/models/test_base_model.py | 6 ++--- bookwyrm/tests/models/test_fields.py | 2 +- bookwyrm/tests/models/test_status_model.py | 2 +- bookwyrm/tests/test_activitystreams.py | 2 +- bookwyrm/tests/test_suggested_users.py | 2 +- bookwyrm/tests/test_templatetags.py | 2 +- .../tests/views/inbox/test_inbox_announce.py | 10 ++++---- .../tests/views/inbox/test_inbox_create.py | 16 ++++++------- .../tests/views/inbox/test_inbox_delete.py | 2 +- bookwyrm/tests/views/inbox/test_inbox_like.py | 2 +- bookwyrm/tests/views/test_book.py | 2 +- bookwyrm/tests/views/test_discover.py | 3 +-- bookwyrm/tests/views/test_feed.py | 2 +- bookwyrm/tests/views/test_goal.py | 2 +- bookwyrm/tests/views/test_helpers.py | 2 +- bookwyrm/tests/views/test_interaction.py | 18 +++++++------- bookwyrm/tests/views/test_outbox.py | 8 +++---- bookwyrm/tests/views/test_reading.py | 2 +- bookwyrm/tests/views/test_rss_feed.py | 2 +- bookwyrm/tests/views/test_status.py | 24 +++++++++---------- 25 files changed, 61 insertions(+), 62 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index 0758fe99a..1b2dd7988 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -19,7 +19,7 @@ from bookwyrm.activitypub import ActivitySerializerError from bookwyrm import models -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index e92bdb354..2f1a8318b 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -215,7 +215,7 @@ class GoodreadsImport(TestCase): self.assertEqual(readthrough.start_date, make_date(2020, 10, 21)) self.assertEqual(readthrough.finish_date, make_date(2020, 10, 25)) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_handle_imported_book_review(self, *_): """goodreads review import""" import_job = models.ImportJob.objects.create(user=self.user) @@ -237,7 +237,7 @@ class GoodreadsImport(TestCase): self.assertEqual(review.published_date, make_date(2019, 7, 8)) self.assertEqual(review.privacy, "unlisted") - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_handle_imported_book_rating(self, *_): """goodreads rating import""" import_job = models.ImportJob.objects.create(user=self.user) diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 504951c2f..3a9cf8c99 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -197,7 +197,7 @@ class LibrarythingImport(TestCase): self.assertEqual(readthrough.start_date, make_date(2007, 4, 16)) self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8)) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_handle_imported_book_review(self, *_): """librarything review import""" import_job = models.ImportJob.objects.create(user=self.user) diff --git a/bookwyrm/tests/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index 50192a713..5b1139f94 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -37,7 +37,7 @@ class Activitystreams(TestCase): def test_populate_streams(self, _): """make sure the function on the redis manager gets called""" - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): models.Comment.objects.create( user=self.local_user, content="hi", book=self.book ) diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 01d06e02f..30aa91173 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -20,7 +20,7 @@ from bookwyrm.settings import PAGE_LENGTH # pylint: disable=invalid-name -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") class ActivitypubMixins(TestCase): """functionality shared across models""" diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index 43cd5d3f4..1aed644ee 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -62,7 +62,7 @@ class BaseModel(TestCase): base_model.set_remote_id(None, instance, False) self.assertIsNone(instance.remote_id) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_object_visible_to_user(self, _): """does a user have permission to view an object""" obj = models.Status.objects.create( @@ -91,7 +91,7 @@ class BaseModel(TestCase): obj.mention_users.add(self.local_user) self.assertTrue(obj.visible_to_user(self.local_user)) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_object_visible_to_user_follower(self, _): """what you can see if you follow a user""" self.remote_user.followers.add(self.local_user) @@ -111,7 +111,7 @@ class BaseModel(TestCase): obj.mention_users.add(self.local_user) self.assertTrue(obj.visible_to_user(self.local_user)) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_object_visible_to_user_blocked(self, _): """you can't see it if they block you""" self.remote_user.blocks.add(self.local_user) diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index 6730d37b9..88b07a296 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -206,7 +206,7 @@ class ModelFields(TestCase): self.assertEqual(model_instance.privacy_field, "followers") @patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast") - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_privacy_field_set_activity_from_field(self, *_): """translate between to/cc fields and privacy""" user = User.objects.create_user( diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 22b959224..91db382e2 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -15,7 +15,7 @@ from bookwyrm import activitypub, models, settings # pylint: disable=too-many-public-methods @patch("bookwyrm.models.Status.broadcast") -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") class Status(TestCase): """lotta types of statuses""" diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index 56ba844ad..a5b7e17fc 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -5,7 +5,7 @@ from bookwyrm import activitystreams, models @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.BooksStream.add_book_statuses") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") # pylint: disable=too-many-public-methods diff --git a/bookwyrm/tests/test_suggested_users.py b/bookwyrm/tests/test_suggested_users.py index 7e4a9d00f..6d45e9157 100644 --- a/bookwyrm/tests/test_suggested_users.py +++ b/bookwyrm/tests/test_suggested_users.py @@ -10,7 +10,7 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") diff --git a/bookwyrm/tests/test_templatetags.py b/bookwyrm/tests/test_templatetags.py index d75d368c1..f30ab6f7a 100644 --- a/bookwyrm/tests/test_templatetags.py +++ b/bookwyrm/tests/test_templatetags.py @@ -15,7 +15,7 @@ from bookwyrm.templatetags import ( ) -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") class TemplateTags(TestCase): """lotta different things here""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index 8bc6cd1d0..ec827d753 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -35,7 +35,7 @@ class InboxActivities(TestCase): ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): self.status = models.Status.objects.create( user=self.local_user, content="Test status", @@ -53,7 +53,7 @@ class InboxActivities(TestCase): models.SiteSettings.objects.create() - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") def test_boost(self, redis_mock, _): """boost a status""" @@ -84,7 +84,7 @@ class InboxActivities(TestCase): self.assertEqual(notification.related_status, self.status) @responses.activate - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") def test_boost_remote_status(self, redis_mock, _): """boost a status from a remote server""" @@ -141,7 +141,7 @@ class InboxActivities(TestCase): content="hi", user=self.remote_user, ) - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status.save(broadcast=False) activity = { "type": "Announce", @@ -158,7 +158,7 @@ class InboxActivities(TestCase): views.inbox.activity_task(activity) self.assertEqual(models.Boost.objects.count(), 0) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") def test_unboost(self, *_): """undo a boost""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index 059d05223..cb5cd2169 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -47,7 +47,7 @@ class InboxCreate(TestCase): } models.SiteSettings.objects.create() - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_create_status(self, *_): """the "it justs works" mode""" datafile = pathlib.Path(__file__).parent.joinpath( @@ -61,7 +61,7 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) @@ -77,7 +77,7 @@ class InboxCreate(TestCase): views.inbox.activity_task(activity) self.assertEqual(models.Status.objects.count(), 1) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_create_comment_with_reading_status(self, *_): """the "it justs works" mode""" datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_comment.json") @@ -90,7 +90,7 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) @@ -115,7 +115,7 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) status = models.Status.objects.last() @@ -128,7 +128,7 @@ class InboxCreate(TestCase): def test_create_status_remote_note_with_reply(self, _): """should only create it under the right circumstances""" - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): parent_status = models.Status.objects.create( user=self.local_user, content="Test status", @@ -145,7 +145,7 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) status = models.Status.objects.last() @@ -184,7 +184,7 @@ class InboxCreate(TestCase): "rating": 3, "@context": "https://www.w3.org/ns/activitystreams", } - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) rating = models.ReviewRating.objects.first() diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 1566c05a2..a58e0a4bc 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -33,7 +33,7 @@ class InboxActivities(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): self.status = models.Status.objects.create( user=self.remote_user, content="Test status", diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index 56f21e894..2f6e39710 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -34,7 +34,7 @@ class InboxActivities(TestCase): ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): self.status = models.Status.objects.create( user=self.local_user, content="Test status", diff --git a/bookwyrm/tests/views/test_book.py b/bookwyrm/tests/views/test_book.py index 2cd50302f..3b2ab6976 100644 --- a/bookwyrm/tests/views/test_book.py +++ b/bookwyrm/tests/views/test_book.py @@ -74,7 +74,7 @@ class BookViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_book_page_statuses(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Book.as_view() diff --git a/bookwyrm/tests/views/test_discover.py b/bookwyrm/tests/views/test_discover.py index eff62cb6f..7b08f260e 100644 --- a/bookwyrm/tests/views/test_discover.py +++ b/bookwyrm/tests/views/test_discover.py @@ -1,7 +1,6 @@ """ test for app action functionality """ from unittest.mock import patch from django.contrib.auth.models import AnonymousUser -from django.template.response import TemplateResponse from django.test import TestCase from django.test.client import RequestFactory @@ -41,7 +40,7 @@ class DiscoverViews(TestCase): result.render() @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_discover_page(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Discover.as_view() diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index e13dd7f8a..805fa2c95 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -15,7 +15,7 @@ from bookwyrm.activitypub import ActivitypubResponse @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") class FeedViews(TestCase): diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index 23bd8e1a8..ea0cd1c9e 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -104,7 +104,7 @@ class GoalViews(TestCase): result = view(request, self.local_user.localname, self.year) self.assertEqual(result.status_code, 404) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_create_goal(self, _): """create a new goal""" view = views.Goal.as_view() diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index b9a82e681..f3797cc5d 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -11,7 +11,7 @@ from bookwyrm import models, views from bookwyrm.settings import USER_AGENT -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") class ViewsHelpers(TestCase): diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index d83fc1190..63b690072 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -8,7 +8,7 @@ from bookwyrm import models, views @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") -@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") +@patch("bookwyrm.activitystreams.remove_object_from_related_stores") class InteractionViews(TestCase): """viewing and creating statuses""" @@ -47,7 +47,7 @@ class InteractionViews(TestCase): view = views.Favorite.as_view() request = self.factory.post("") request.user = self.remote_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") view(request, status.id) @@ -65,7 +65,7 @@ class InteractionViews(TestCase): view = views.Unfavorite.as_view() request = self.factory.post("") request.user = self.remote_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") views.Favorite.as_view()(request, status.id) @@ -82,7 +82,7 @@ class InteractionViews(TestCase): view = views.Boost.as_view() request = self.factory.post("") request.user = self.remote_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") view(request, status.id) @@ -104,7 +104,7 @@ class InteractionViews(TestCase): view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") with patch( @@ -128,7 +128,7 @@ class InteractionViews(TestCase): view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create( user=self.local_user, content="hi", privacy="unlisted" ) @@ -143,7 +143,7 @@ class InteractionViews(TestCase): view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create( user=self.local_user, content="hi", privacy="followers" ) @@ -156,14 +156,14 @@ class InteractionViews(TestCase): view = views.Boost.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") view(request, status.id) view(request, status.id) self.assertEqual(models.Boost.objects.count(), 1) - @patch("bookwyrm.activitystreams.ActivityStream.add_status") + @patch("bookwyrm.activitystreams.add_status_task.delay") def test_unboost(self, *_): """undo a boost""" view = views.Unboost.as_view() diff --git a/bookwyrm/tests/views/test_outbox.py b/bookwyrm/tests/views/test_outbox.py index fe493bb87..eef9ed888 100644 --- a/bookwyrm/tests/views/test_outbox.py +++ b/bookwyrm/tests/views/test_outbox.py @@ -56,7 +56,7 @@ class OutboxView(TestCase): def test_outbox_privacy(self, _): """don't show dms et cetera in outbox""" - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): models.Status.objects.create( content="PRIVATE!!", user=self.local_user, privacy="direct" ) @@ -79,7 +79,7 @@ class OutboxView(TestCase): def test_outbox_filter(self, _): """if we only care about reviews, only get reviews""" - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): models.Review.objects.create( content="look at this", name="hi", @@ -105,7 +105,7 @@ class OutboxView(TestCase): def test_outbox_bookwyrm_request_true(self, _): """should differentiate between bookwyrm and outside requests""" - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): models.Review.objects.create( name="hi", content="look at this", @@ -123,7 +123,7 @@ class OutboxView(TestCase): def test_outbox_bookwyrm_request_false(self, _): """should differentiate between bookwyrm and outside requests""" - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): models.Review.objects.create( name="hi", content="look at this", diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 61464bc7f..f15e99a76 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -8,7 +8,7 @@ from django.utils import timezone from bookwyrm import models, views -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class ReadingViews(TestCase): """viewing and creating statuses""" diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index f2d3baf2d..a7d958541 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -8,7 +8,7 @@ from bookwyrm.views import rss_feed @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") -@patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.activitystreams.add_status_task.delay") class RssFeedView(TestCase): """rss feed behaves as expected""" diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index ff429e20f..27d9de2df 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -59,7 +59,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: view(request, "comment") self.assertTrue(redis_mock.called) @@ -74,7 +74,7 @@ class StatusViews(TestCase): user = models.User.objects.create_user( "rat", "rat@rat.com", "password", local=True ) - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): parent = models.Status.objects.create( content="parent status", user=self.local_user ) @@ -89,7 +89,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = user - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: view(request, "reply") self.assertTrue(redis_mock.called) @@ -119,7 +119,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: view(request, "comment") self.assertTrue(redis_mock.called) @@ -147,7 +147,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: view(request, "comment") self.assertTrue(redis_mock.called) status = models.Status.objects.get() @@ -163,7 +163,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = user - with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock: + with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: view(request, "reply") self.assertTrue(redis_mock.called) @@ -179,7 +179,7 @@ class StatusViews(TestCase): view = views.DeleteAndRedraft.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Comment.objects.create( content="hi", book=self.book, user=self.local_user ) @@ -200,7 +200,7 @@ class StatusViews(TestCase): view = views.DeleteAndRedraft.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.ReviewRating.objects.create( book=self.book, rating=2.0, user=self.local_user ) @@ -220,7 +220,7 @@ class StatusViews(TestCase): view = views.DeleteAndRedraft.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.GeneratedNote.objects.create( content="hi", user=self.local_user ) @@ -344,7 +344,7 @@ class StatusViews(TestCase): def test_handle_delete_status(self, mock, *_): """marks a status as deleted""" view = views.DeleteStatus.as_view() - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") self.assertFalse(status.deleted) request = self.factory.post("") @@ -364,7 +364,7 @@ class StatusViews(TestCase): def test_handle_delete_status_permission_denied(self, *_): """marks a status as deleted""" view = views.DeleteStatus.as_view() - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") self.assertFalse(status.deleted) request = self.factory.post("") @@ -378,7 +378,7 @@ class StatusViews(TestCase): def test_handle_delete_status_moderator(self, mock, _): """marks a status as deleted""" view = views.DeleteStatus.as_view() - with patch("bookwyrm.activitystreams.ActivityStream.add_status"): + with patch("bookwyrm.activitystreams.add_status_task.delay"): status = models.Status.objects.create(user=self.local_user, content="hi") self.assertFalse(status.deleted) request = self.factory.post("") From bb94995389f9d2309ccbe903ba1415689f105c68 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 14:48:45 -0700 Subject: [PATCH 11/23] Where you need one mock, you probably need the other --- bookwyrm/tests/activitypub/test_base_activity.py | 4 +++- bookwyrm/tests/importers/test_goodreads_import.py | 4 +++- bookwyrm/tests/importers/test_librarything_import.py | 4 +++- bookwyrm/tests/management/test_populate_streams.py | 4 +++- bookwyrm/tests/models/test_activitypub_mixin.py | 4 +++- bookwyrm/tests/models/test_base_model.py | 4 +++- bookwyrm/tests/models/test_import_model.py | 4 +++- bookwyrm/tests/models/test_list.py | 4 +++- bookwyrm/tests/models/test_readthrough_model.py | 4 +++- bookwyrm/tests/models/test_relationship_models.py | 4 +++- bookwyrm/tests/models/test_shelf_model.py | 4 +++- bookwyrm/tests/models/test_status_model.py | 4 +++- bookwyrm/tests/models/test_user_model.py | 4 +++- bookwyrm/tests/test_activitystreams.py | 4 +++- bookwyrm/tests/test_emailing.py | 4 +++- bookwyrm/tests/test_preview_images.py | 4 +++- bookwyrm/tests/test_signing.py | 4 +++- bookwyrm/tests/test_suggested_users.py | 4 +++- bookwyrm/tests/test_templatetags.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_add.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_announce.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_block.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_create.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_delete.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_follow.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_like.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_remove.py | 4 +++- bookwyrm/tests/views/inbox/test_inbox_update.py | 4 +++- bookwyrm/tests/views/test_announcements.py | 4 +++- bookwyrm/tests/views/test_authentication.py | 4 +++- bookwyrm/tests/views/test_author.py | 4 +++- bookwyrm/tests/views/test_block.py | 4 +++- bookwyrm/tests/views/test_book.py | 4 +++- bookwyrm/tests/views/test_directory.py | 4 +++- bookwyrm/tests/views/test_discover.py | 4 +++- bookwyrm/tests/views/test_edit_user.py | 4 +++- bookwyrm/tests/views/test_editions.py | 4 +++- bookwyrm/tests/views/test_federation.py | 4 +++- bookwyrm/tests/views/test_feed.py | 4 +++- bookwyrm/tests/views/test_follow.py | 12 +++++++++--- bookwyrm/tests/views/test_get_started.py | 4 +++- bookwyrm/tests/views/test_goal.py | 4 +++- bookwyrm/tests/views/test_helpers.py | 4 +++- bookwyrm/tests/views/test_import.py | 4 +++- bookwyrm/tests/views/test_interaction.py | 4 +++- bookwyrm/tests/views/test_invite.py | 4 +++- bookwyrm/tests/views/test_isbn.py | 4 +++- bookwyrm/tests/views/test_landing.py | 4 +++- bookwyrm/tests/views/test_list.py | 4 +++- bookwyrm/tests/views/test_list_actions.py | 4 +++- bookwyrm/tests/views/test_notifications.py | 4 +++- bookwyrm/tests/views/test_outbox.py | 4 +++- bookwyrm/tests/views/test_password.py | 4 +++- bookwyrm/tests/views/test_reading.py | 4 +++- bookwyrm/tests/views/test_readthrough.py | 4 +++- bookwyrm/tests/views/test_reports.py | 4 +++- bookwyrm/tests/views/test_rss_feed.py | 4 +++- bookwyrm/tests/views/test_search.py | 4 +++- bookwyrm/tests/views/test_shelf.py | 4 +++- bookwyrm/tests/views/test_status.py | 4 +++- bookwyrm/tests/views/test_updates.py | 4 +++- bookwyrm/tests/views/test_user.py | 8 ++++++-- bookwyrm/tests/views/test_user_admin.py | 4 +++- bookwyrm/tests/views/test_wellknown.py | 4 +++- 65 files changed, 204 insertions(+), 68 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index 1b2dd7988..d0426a22c 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -28,7 +28,9 @@ class BaseActivity(TestCase): def setUp(self): """we're probably going to re-use this so why copy/paste""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index 2f1a8318b..a6639164b 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -30,7 +30,9 @@ class GoodreadsImport(TestCase): self.importer = GoodreadsImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") self.csv = open(datafile, "r", encoding=self.importer.encoding) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 3a9cf8c99..1abfdbb19 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -31,7 +31,9 @@ class LibrarythingImport(TestCase): # Librarything generates latin encoded exports... self.csv = open(datafile, "r", encoding=self.importer.encoding) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "mmai", "mmai@mmai.mmai", "password", local=True ) diff --git a/bookwyrm/tests/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index 5b1139f94..ca21b0ee8 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -12,7 +12,9 @@ class Activitystreams(TestCase): def setUp(self): """we need some stuff""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 30aa91173..911cca5cc 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -27,7 +27,9 @@ class ActivitypubMixins(TestCase): def setUp(self): """shared data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index 1aed644ee..285647405 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -13,7 +13,9 @@ class BaseModel(TestCase): def setUp(self): """shared data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index 15a75a96e..caf610349 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -59,7 +59,9 @@ class ImportJob(TestCase): unknown_read_data["Exclusive Shelf"] = "read" unknown_read_data["Date Read"] = "" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_list.py b/bookwyrm/tests/models/test_list.py index 6e1ff8094..0d749453e 100644 --- a/bookwyrm/tests/models/test_list.py +++ b/bookwyrm/tests/models/test_list.py @@ -11,7 +11,9 @@ class List(TestCase): def setUp(self): """look, a list""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_readthrough_model.py b/bookwyrm/tests/models/test_readthrough_model.py index 2b6e4fdd2..5d8450a1a 100644 --- a/bookwyrm/tests/models/test_readthrough_model.py +++ b/bookwyrm/tests/models/test_readthrough_model.py @@ -13,7 +13,9 @@ class ReadThrough(TestCase): def setUp(self): """look, a shelf""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_relationship_models.py b/bookwyrm/tests/models/test_relationship_models.py index f66cf1091..7383a489a 100644 --- a/bookwyrm/tests/models/test_relationship_models.py +++ b/bookwyrm/tests/models/test_relationship_models.py @@ -21,7 +21,9 @@ class Relationship(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index f6fd68509..cb7f78c38 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -13,7 +13,9 @@ class Shelf(TestCase): def setUp(self): """look, a shelf""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 91db382e2..9913911cd 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -22,7 +22,9 @@ class Status(TestCase): def setUp(self): """useful things for creating a status""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index 230c503b0..528d3fdc4 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -13,7 +13,9 @@ class User(TestCase): protocol = "https://" if USE_HTTPS else "http://" def setUp(self): - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "mouse@%s" % DOMAIN, "mouse@mouse.mouse", diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index a5b7e17fc..38f90af9e 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -14,7 +14,9 @@ class Activitystreams(TestCase): def setUp(self): """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/test_emailing.py b/bookwyrm/tests/test_emailing.py index 4c3d86a46..2f24122ee 100644 --- a/bookwyrm/tests/test_emailing.py +++ b/bookwyrm/tests/test_emailing.py @@ -14,7 +14,9 @@ class Emailing(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/test_preview_images.py b/bookwyrm/tests/test_preview_images.py index 37638c27c..760ff4c4a 100644 --- a/bookwyrm/tests/test_preview_images.py +++ b/bookwyrm/tests/test_preview_images.py @@ -29,7 +29,9 @@ class PreviewImages(TestCase): avatar_file = pathlib.Path(__file__).parent.joinpath( "../static/images/no_cover.jpg" ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "possum@local.com", "possum@possum.possum", diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index d9a87dd56..d33687a59 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -37,7 +37,9 @@ class Signature(TestCase): def setUp(self): """create users and test data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.mouse = models.User.objects.create_user( "mouse@%s" % DOMAIN, "mouse@example.com", diff --git a/bookwyrm/tests/test_suggested_users.py b/bookwyrm/tests/test_suggested_users.py index 6d45e9157..67b1940d0 100644 --- a/bookwyrm/tests/test_suggested_users.py +++ b/bookwyrm/tests/test_suggested_users.py @@ -19,7 +19,9 @@ class SuggestedUsers(TestCase): def setUp(self): """use a test csv""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" ) diff --git a/bookwyrm/tests/test_templatetags.py b/bookwyrm/tests/test_templatetags.py index f30ab6f7a..312d107b9 100644 --- a/bookwyrm/tests/test_templatetags.py +++ b/bookwyrm/tests/test_templatetags.py @@ -22,7 +22,9 @@ class TemplateTags(TestCase): def setUp(self): """create some filler objects""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py index 8e49d25a4..a84458ab2 100644 --- a/bookwyrm/tests/views/inbox/test_inbox.py +++ b/bookwyrm/tests/views/inbox/test_inbox.py @@ -19,7 +19,9 @@ class Inbox(TestCase): self.client = Client() self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_add.py b/bookwyrm/tests/views/inbox/test_inbox_add.py index 07525c34e..33e6c55b4 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_add.py +++ b/bookwyrm/tests/views/inbox/test_inbox_add.py @@ -13,7 +13,9 @@ class InboxAdd(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index ec827d753..fcf3e4105 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -13,7 +13,9 @@ class InboxActivities(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index ce650a007..dc29954d9 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -12,7 +12,9 @@ class InboxBlock(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index cb5cd2169..76afb5380 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -16,7 +16,9 @@ class InboxCreate(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index a58e0a4bc..23a956b2b 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -13,7 +13,9 @@ class InboxActivities(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index d1a4e0d00..62c84044a 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -13,7 +13,9 @@ class InboxRelationships(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index 2f6e39710..db8f1fca8 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -12,7 +12,9 @@ class InboxActivities(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_remove.py b/bookwyrm/tests/views/inbox/test_inbox_remove.py index 3d64fcb23..cb4e4a16f 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_remove.py +++ b/bookwyrm/tests/views/inbox/test_inbox_remove.py @@ -12,7 +12,9 @@ class InboxRemove(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index 4abb0fa0d..fc3b3a2a1 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -14,7 +14,9 @@ class InboxUpdate(TestCase): def setUp(self): """basic user and book data""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@example.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_announcements.py b/bookwyrm/tests/views/test_announcements.py index 16ef81e9c..44b5d5b67 100644 --- a/bookwyrm/tests/views/test_announcements.py +++ b/bookwyrm/tests/views/test_announcements.py @@ -13,7 +13,9 @@ class AnnouncementViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_authentication.py b/bookwyrm/tests/views/test_authentication.py index 22008e100..23091641d 100644 --- a/bookwyrm/tests/views/test_authentication.py +++ b/bookwyrm/tests/views/test_authentication.py @@ -20,7 +20,9 @@ class AuthenticationViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@your.domain.here", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index 6157b6516..7a0065c9e 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -17,7 +17,9 @@ class AuthorViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_block.py b/bookwyrm/tests/views/test_block.py index 11283869b..28f526393 100644 --- a/bookwyrm/tests/views/test_block.py +++ b/bookwyrm/tests/views/test_block.py @@ -14,7 +14,9 @@ class BlockViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_book.py b/bookwyrm/tests/views/test_book.py index 3b2ab6976..99022ec5e 100644 --- a/bookwyrm/tests/views/test_book.py +++ b/bookwyrm/tests/views/test_book.py @@ -24,7 +24,9 @@ class BookViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index bdda81013..93dc3528c 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -15,7 +15,9 @@ class DirectoryViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_discover.py b/bookwyrm/tests/views/test_discover.py index 7b08f260e..4b8927bca 100644 --- a/bookwyrm/tests/views/test_discover.py +++ b/bookwyrm/tests/views/test_discover.py @@ -14,7 +14,9 @@ class DiscoverViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_edit_user.py b/bookwyrm/tests/views/test_edit_user.py index df89d5b09..70e5eafd0 100644 --- a/bookwyrm/tests/views/test_edit_user.py +++ b/bookwyrm/tests/views/test_edit_user.py @@ -22,7 +22,9 @@ class EditUserViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_editions.py b/bookwyrm/tests/views/test_editions.py index 1bd23ae11..6ab81955c 100644 --- a/bookwyrm/tests/views/test_editions.py +++ b/bookwyrm/tests/views/test_editions.py @@ -15,7 +15,9 @@ class BookViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_federation.py b/bookwyrm/tests/views/test_federation.py index f43a9623e..ce5de7e33 100644 --- a/bookwyrm/tests/views/test_federation.py +++ b/bookwyrm/tests/views/test_federation.py @@ -15,7 +15,9 @@ class FederationViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index 805fa2c95..bcb9247ef 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -24,7 +24,9 @@ class FeedViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index 714284b01..a1dda42a7 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -16,7 +16,9 @@ class FollowViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", @@ -67,7 +69,9 @@ class FollowViews(TestCase): def test_handle_follow_local_manually_approves(self): """send a follow request""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): rat = models.User.objects.create_user( "rat@local.com", "rat@rat.com", @@ -91,7 +95,9 @@ class FollowViews(TestCase): def test_handle_follow_local(self): """send a follow request""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): rat = models.User.objects.create_user( "rat@local.com", "rat@rat.com", diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index eb9d67b5d..2f9e97724 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -13,7 +13,9 @@ class GetStartedViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index ea0cd1c9e..2ecce0ac6 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -16,7 +16,9 @@ class GoalViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index f3797cc5d..d8012d8e1 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -20,7 +20,9 @@ class ViewsHelpers(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): with patch("bookwyrm.suggested_users.rerank_user_task.delay"): self.local_user = models.User.objects.create_user( "mouse@local.com", diff --git a/bookwyrm/tests/views/test_import.py b/bookwyrm/tests/views/test_import.py index d9d67d568..2027d2845 100644 --- a/bookwyrm/tests/views/test_import.py +++ b/bookwyrm/tests/views/test_import.py @@ -15,7 +15,9 @@ class ImportViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 63b690072..aa3ea5115 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -15,7 +15,9 @@ class InteractionViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_invite.py b/bookwyrm/tests/views/test_invite.py index 6ad464208..c1e425c8c 100644 --- a/bookwyrm/tests/views/test_invite.py +++ b/bookwyrm/tests/views/test_invite.py @@ -16,7 +16,9 @@ class InviteViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index 7c413e8bf..a6a451748 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -16,7 +16,9 @@ class IsbnViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_landing.py b/bookwyrm/tests/views/test_landing.py index 476da74b1..f3a50fbc2 100644 --- a/bookwyrm/tests/views/test_landing.py +++ b/bookwyrm/tests/views/test_landing.py @@ -15,7 +15,9 @@ class LandingViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_list.py b/bookwyrm/tests/views/test_list.py index d5e917c38..35befec6b 100644 --- a/bookwyrm/tests/views/test_list.py +++ b/bookwyrm/tests/views/test_list.py @@ -17,7 +17,9 @@ class ListViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index 2339427c6..dadb9812f 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -15,7 +15,9 @@ class ListActionViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_notifications.py b/bookwyrm/tests/views/test_notifications.py index af6aac13e..d97616ce9 100644 --- a/bookwyrm/tests/views/test_notifications.py +++ b/bookwyrm/tests/views/test_notifications.py @@ -14,7 +14,9 @@ class NotificationViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_outbox.py b/bookwyrm/tests/views/test_outbox.py index eef9ed888..a1f62cc61 100644 --- a/bookwyrm/tests/views/test_outbox.py +++ b/bookwyrm/tests/views/test_outbox.py @@ -18,7 +18,9 @@ class OutboxView(TestCase): def setUp(self): """we'll need some data""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_password.py b/bookwyrm/tests/views/test_password.py index 5f59e9e32..b07d98a7d 100644 --- a/bookwyrm/tests/views/test_password.py +++ b/bookwyrm/tests/views/test_password.py @@ -15,7 +15,9 @@ class PasswordViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index f15e99a76..d5b5facab 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -16,7 +16,9 @@ class ReadingViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index 618d9cf87..d58e152e2 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -22,7 +22,9 @@ class ReadThrough(TestCase): title="Example Edition", parent_work=self.work ) - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.user = models.User.objects.create_user( "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" ) diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index 7d39a0076..c93594e28 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -13,7 +13,9 @@ class ReportViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index a7d958541..d4d112618 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -13,7 +13,9 @@ class RssFeedView(TestCase): """rss feed behaves as expected""" def setUp(self): - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "rss_user", "rss@test.rss", "password", local=True ) diff --git a/bookwyrm/tests/views/test_search.py b/bookwyrm/tests/views/test_search.py index 3da6f866b..dacbcbded 100644 --- a/bookwyrm/tests/views/test_search.py +++ b/bookwyrm/tests/views/test_search.py @@ -19,7 +19,9 @@ class Views(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_shelf.py b/bookwyrm/tests/views/test_shelf.py index 44c4b9cb5..19f86dafe 100644 --- a/bookwyrm/tests/views/test_shelf.py +++ b/bookwyrm/tests/views/test_shelf.py @@ -17,7 +17,9 @@ class ShelfViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 27d9de2df..1ff12e24e 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -17,7 +17,9 @@ class StatusViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.com", diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index 627b756e7..27181fc95 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -15,7 +15,9 @@ class UpdateViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 740f0d299..4702725e6 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -17,7 +17,9 @@ class UserViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", @@ -32,7 +34,9 @@ class UserViews(TestCase): title="test", parent_work=models.Work.objects.create(title="test work") ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): models.ShelfBook.objects.create( book=self.book, user=self.local_user, diff --git a/bookwyrm/tests/views/test_user_admin.py b/bookwyrm/tests/views/test_user_admin.py index 86309045d..f8e85119b 100644 --- a/bookwyrm/tests/views/test_user_admin.py +++ b/bookwyrm/tests/views/test_user_admin.py @@ -14,7 +14,9 @@ class UserAdminViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", diff --git a/bookwyrm/tests/views/test_wellknown.py b/bookwyrm/tests/views/test_wellknown.py index fcbcc12b7..7aca02369 100644 --- a/bookwyrm/tests/views/test_wellknown.py +++ b/bookwyrm/tests/views/test_wellknown.py @@ -16,7 +16,9 @@ class UserViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( + "bookwyrm.activitystreams.populate_stream_task.delay" + ): self.local_user = models.User.objects.create_user( "mouse@local.com", "mouse@mouse.mouse", From 72d5238590de71c13bcdf46c409bbee4c2c57a97 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 14:50:33 -0700 Subject: [PATCH 12/23] More mocks --- bookwyrm/tests/activitypub/test_base_activity.py | 1 + bookwyrm/tests/importers/test_goodreads_import.py | 1 + bookwyrm/tests/importers/test_librarything_import.py | 1 + bookwyrm/tests/models/test_fields.py | 1 + bookwyrm/tests/models/test_shelf_model.py | 1 + bookwyrm/tests/test_activitystreams.py | 1 + bookwyrm/tests/test_suggested_users.py | 1 + bookwyrm/tests/views/test_authentication.py | 1 + bookwyrm/tests/views/test_directory.py | 1 + bookwyrm/tests/views/test_editions.py | 1 + bookwyrm/tests/views/test_feed.py | 1 + bookwyrm/tests/views/test_get_started.py | 2 ++ bookwyrm/tests/views/test_helpers.py | 1 + bookwyrm/tests/views/test_reading.py | 1 + bookwyrm/tests/views/test_readthrough.py | 1 + bookwyrm/tests/views/test_reports.py | 1 + bookwyrm/tests/views/test_shelf.py | 1 + bookwyrm/tests/views/test_status.py | 1 + bookwyrm/tests/views/test_user.py | 1 + bookwyrm/tests/views/test_user_admin.py | 1 + 20 files changed, 21 insertions(+) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index d0426a22c..7117eb52a 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -23,6 +23,7 @@ from bookwyrm import models @patch("bookwyrm.suggested_users.rerank_user_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class BaseActivity(TestCase): """the super class for model-linked activitypub dataclasses""" diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index a6639164b..64a97b39a 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -22,6 +22,7 @@ def make_date(*args): # pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class GoodreadsImport(TestCase): """importing from goodreads csv""" diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 1abfdbb19..4d91a9c59 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -21,6 +21,7 @@ def make_date(*args): # pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class LibrarythingImport(TestCase): """importing from librarything tsv""" diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index 88b07a296..af0a12aaf 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -25,6 +25,7 @@ from bookwyrm.models.activitypub_mixin import ActivitypubMixin # pylint: disable=too-many-public-methods @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class ModelFields(TestCase): """overwrites standard model feilds to work with activitypub""" diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index cb7f78c38..3179b1387 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -8,6 +8,7 @@ from bookwyrm import models, settings # pylint: disable=unused-argument @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class Shelf(TestCase): """some activitypub oddness ahead""" diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index 38f90af9e..aecc448c4 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -8,6 +8,7 @@ from bookwyrm import activitystreams, models @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.activitystreams.BooksStream.add_book_statuses") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") # pylint: disable=too-many-public-methods class Activitystreams(TestCase): """using redis to build activity streams""" diff --git a/bookwyrm/tests/test_suggested_users.py b/bookwyrm/tests/test_suggested_users.py index 67b1940d0..39758252a 100644 --- a/bookwyrm/tests/test_suggested_users.py +++ b/bookwyrm/tests/test_suggested_users.py @@ -12,6 +12,7 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") class SuggestedUsers(TestCase): diff --git a/bookwyrm/tests/views/test_authentication.py b/bookwyrm/tests/views/test_authentication.py index 23091641d..f0fd5392f 100644 --- a/bookwyrm/tests/views/test_authentication.py +++ b/bookwyrm/tests/views/test_authentication.py @@ -14,6 +14,7 @@ from bookwyrm.settings import DOMAIN # pylint: disable=too-many-public-methods @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class AuthenticationViews(TestCase): """login and password management""" diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index 93dc3528c..52f9c0851 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -32,6 +32,7 @@ class DirectoryViews(TestCase): self.anonymous_user.is_authenticated = False @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") def test_directory_page(self, *_): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/test_editions.py b/bookwyrm/tests/views/test_editions.py index 6ab81955c..1cd256b1d 100644 --- a/bookwyrm/tests/views/test_editions.py +++ b/bookwyrm/tests/views/test_editions.py @@ -103,6 +103,7 @@ class BookViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") def test_switch_edition(self, _): """updates user's relationships to a book""" work = models.Work.objects.create(title="test work") diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index bcb9247ef..843a9fd7d 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -17,6 +17,7 @@ from bookwyrm.activitypub import ActivitypubResponse @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") class FeedViews(TestCase): """activity feed, statuses, dms""" diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 2f9e97724..98962bc4e 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -46,6 +46,7 @@ class GetStartedViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") def test_profile_view_post(self, *_): """save basic user details""" @@ -90,6 +91,7 @@ class GetStartedViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") def test_books_view_post(self, _): """shelve some books""" view = views.GetStartedBooks.as_view() diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index d8012d8e1..8f7b45a35 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -13,6 +13,7 @@ from bookwyrm.settings import USER_AGENT @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") class ViewsHelpers(TestCase): """viewing and creating statuses""" diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index d5b5facab..acd14775f 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -10,6 +10,7 @@ from bookwyrm import models, views @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class ReadingViews(TestCase): """viewing and creating statuses""" diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index d58e152e2..c246a263f 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -8,6 +8,7 @@ from bookwyrm import models @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") class ReadThrough(TestCase): """readthrough tests""" diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index c93594e28..2f9ee27b8 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -119,6 +119,7 @@ class ReportViews(TestCase): self.assertFalse(report.resolved) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") def test_suspend_user(self, *_): """toggle whether a user is able to log in""" diff --git a/bookwyrm/tests/views/test_shelf.py b/bookwyrm/tests/views/test_shelf.py index 19f86dafe..d7d334650 100644 --- a/bookwyrm/tests/views/test_shelf.py +++ b/bookwyrm/tests/views/test_shelf.py @@ -11,6 +11,7 @@ from bookwyrm.activitypub import ActivitypubResponse @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class ShelfViews(TestCase): """tag views""" diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 1ff12e24e..a3c812b41 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -10,6 +10,7 @@ from bookwyrm.settings import DOMAIN # pylint: disable=invalid-name @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") class StatusViews(TestCase): """viewing and creating statuses""" diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 4702725e6..d14c62432 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -103,6 +103,7 @@ class UserViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") def test_followers_page_blocked(self, _): """there are so many views, this just makes sure it LOADS""" view = views.Followers.as_view() diff --git a/bookwyrm/tests/views/test_user_admin.py b/bookwyrm/tests/views/test_user_admin.py index f8e85119b..eab8ab686 100644 --- a/bookwyrm/tests/views/test_user_admin.py +++ b/bookwyrm/tests/views/test_user_admin.py @@ -51,6 +51,7 @@ class UserAdminViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") def test_user_admin_page_post(self, *_): """set the user's group""" From 227b72eaf999c02ecbfabbb73b30a34b790cf5c4 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 15:09:04 -0700 Subject: [PATCH 13/23] Fixes mocks syntax --- .../tests/importers/test_goodreads_import.py | 16 +++---- .../importers/test_librarything_import.py | 14 +++---- bookwyrm/tests/models/test_fields.py | 42 +++++++++---------- bookwyrm/tests/models/test_shelf_model.py | 8 ++-- bookwyrm/tests/views/test_authentication.py | 28 ++++++------- bookwyrm/tests/views/test_get_started.py | 3 +- bookwyrm/tests/views/test_status.py | 2 +- bookwyrm/tests/views/test_user.py | 4 +- 8 files changed, 58 insertions(+), 59 deletions(-) diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index 64a97b39a..47fd6a33e 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -56,7 +56,7 @@ class GoodreadsImport(TestCase): parent_work=work, ) - def test_create_job(self, _): + def test_create_job(self, *_): """creates the import job entry and checks csv""" import_job = self.importer.create_job(self.user, self.csv, False, "public") self.assertEqual(import_job.user, self.user) @@ -72,7 +72,7 @@ class GoodreadsImport(TestCase): self.assertEqual(import_items[2].index, 2) self.assertEqual(import_items[2].data["Book Id"], "28694510") - def test_create_retry_job(self, _): + def test_create_retry_job(self, *_): """trying again with items that didn't import""" import_job = self.importer.create_job(self.user, self.csv, False, "unlisted") import_items = models.ImportItem.objects.filter(job=import_job).all()[:2] @@ -90,7 +90,7 @@ class GoodreadsImport(TestCase): self.assertEqual(retry_items[1].index, 1) self.assertEqual(retry_items[1].data["Book Id"], "52691223") - def test_start_import(self, _): + def test_start_import(self, *_): """begin loading books""" import_job = self.importer.create_job(self.user, self.csv, False, "unlisted") MockTask = namedtuple("Task", ("id")) @@ -102,7 +102,7 @@ class GoodreadsImport(TestCase): self.assertEqual(import_job.task_id, "7") @responses.activate - def test_import_data(self, _): + def test_import_data(self, *_): """resolve entry""" import_job = self.importer.create_job(self.user, self.csv, False, "unlisted") book = models.Edition.objects.create(title="Test Book") @@ -117,7 +117,7 @@ class GoodreadsImport(TestCase): import_item = models.ImportItem.objects.get(job=import_job, index=0) self.assertEqual(import_item.book.id, book.id) - def test_handle_imported_book(self, _): + def test_handle_imported_book(self, *_): """goodreads import added a book, this adds related connections""" shelf = self.user.shelf_set.filter(identifier="read").first() self.assertIsNone(shelf.books.first()) @@ -148,7 +148,7 @@ class GoodreadsImport(TestCase): self.assertEqual(readthrough.start_date, make_date(2020, 10, 21)) self.assertEqual(readthrough.finish_date, make_date(2020, 10, 25)) - def test_handle_imported_book_already_shelved(self, _): + def test_handle_imported_book_already_shelved(self, *_): """goodreads import added a book, this adds related connections""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): shelf = self.user.shelf_set.filter(identifier="to-read").first() @@ -186,7 +186,7 @@ class GoodreadsImport(TestCase): self.assertEqual(readthrough.start_date, make_date(2020, 10, 21)) self.assertEqual(readthrough.finish_date, make_date(2020, 10, 25)) - def test_handle_import_twice(self, _): + def test_handle_import_twice(self, *_): """re-importing books""" shelf = self.user.shelf_set.filter(identifier="read").first() import_job = models.ImportJob.objects.create(user=self.user) @@ -264,7 +264,7 @@ class GoodreadsImport(TestCase): self.assertEqual(review.published_date, make_date(2019, 7, 8)) self.assertEqual(review.privacy, "unlisted") - def test_handle_imported_book_reviews_disabled(self, _): + def test_handle_imported_book_reviews_disabled(self, *_): """goodreads review import""" import_job = models.ImportJob.objects.create(user=self.user) datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 4d91a9c59..c7ddbed69 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -57,7 +57,7 @@ class LibrarythingImport(TestCase): parent_work=work, ) - def test_create_job(self, _): + def test_create_job(self, *_): """creates the import job entry and checks csv""" import_job = self.importer.create_job(self.user, self.csv, False, "public") self.assertEqual(import_job.user, self.user) @@ -73,7 +73,7 @@ class LibrarythingImport(TestCase): self.assertEqual(import_items[2].index, 2) self.assertEqual(import_items[2].data["Book Id"], "5015399") - def test_create_retry_job(self, _): + def test_create_retry_job(self, *_): """trying again with items that didn't import""" import_job = self.importer.create_job(self.user, self.csv, False, "unlisted") import_items = models.ImportItem.objects.filter(job=import_job).all()[:2] @@ -92,7 +92,7 @@ class LibrarythingImport(TestCase): self.assertEqual(retry_items[1].data["Book Id"], "5015319") @responses.activate - def test_import_data(self, _): + def test_import_data(self, *_): """resolve entry""" import_job = self.importer.create_job(self.user, self.csv, False, "unlisted") book = models.Edition.objects.create(title="Test Book") @@ -107,7 +107,7 @@ class LibrarythingImport(TestCase): import_item = models.ImportItem.objects.get(job=import_job, index=0) self.assertEqual(import_item.book.id, book.id) - def test_handle_imported_book(self, _): + def test_handle_imported_book(self, *_): """librarything import added a book, this adds related connections""" shelf = self.user.shelf_set.filter(identifier="read").first() self.assertIsNone(shelf.books.first()) @@ -137,7 +137,7 @@ class LibrarythingImport(TestCase): self.assertEqual(readthrough.start_date, make_date(2007, 4, 16)) self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8)) - 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""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): shelf = self.user.shelf_set.filter(identifier="to-read").first() @@ -169,7 +169,7 @@ class LibrarythingImport(TestCase): self.assertEqual(readthrough.start_date, make_date(2007, 4, 16)) self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8)) - def test_handle_import_twice(self, _): + def test_handle_import_twice(self, *_): """re-importing books""" shelf = self.user.shelf_set.filter(identifier="read").first() import_job = models.ImportJob.objects.create(user=self.user) @@ -222,7 +222,7 @@ class LibrarythingImport(TestCase): self.assertEqual(review.published_date, make_date(2007, 5, 8)) self.assertEqual(review.privacy, "unlisted") - def test_handle_imported_book_reviews_disabled(self, _): + def test_handle_imported_book_reviews_disabled(self, *_): """librarything review import""" import_job = models.ImportJob.objects.create(user=self.user) datafile = pathlib.Path(__file__).parent.joinpath("../data/librarything.tsv") diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index af0a12aaf..1796b84bd 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -29,7 +29,7 @@ from bookwyrm.models.activitypub_mixin import ActivitypubMixin class ModelFields(TestCase): """overwrites standard model feilds to work with activitypub""" - def test_validate_remote_id(self, _): + def test_validate_remote_id(self, *_): """should look like a url""" self.assertIsNone(fields.validate_remote_id("http://www.example.com")) self.assertIsNone(fields.validate_remote_id("https://www.example.com")) @@ -46,7 +46,7 @@ class ModelFields(TestCase): "http://www.example.com/dlfjg 23/x", ) - def test_activitypub_field_mixin(self, _): + def test_activitypub_field_mixin(self, *_): """generic mixin with super basic to and from functionality""" instance = fields.ActivitypubFieldMixin() self.assertEqual(instance.field_to_activity("fish"), "fish") @@ -64,7 +64,7 @@ class ModelFields(TestCase): instance.name = "snake_case_name" self.assertEqual(instance.get_activitypub_field(), "snakeCaseName") - def test_set_field_from_activity(self, _): + def test_set_field_from_activity(self, *_): """setter from entire json blob""" @dataclass @@ -83,7 +83,7 @@ class ModelFields(TestCase): instance.set_field_from_activity(mock_model, data) self.assertEqual(mock_model.field_name, "hi") - def test_set_activity_from_field(self, _): + def test_set_activity_from_field(self, *_): """set json field given entire model""" @dataclass @@ -101,7 +101,7 @@ class ModelFields(TestCase): instance.set_activity_from_field(data, mock_model) self.assertEqual(data["fieldName"], "bip") - def test_remote_id_field(self, _): + def test_remote_id_field(self, *_): """just sets some defaults on charfield""" instance = fields.RemoteIdField() self.assertEqual(instance.max_length, 255) @@ -110,7 +110,7 @@ class ModelFields(TestCase): with self.assertRaises(ValidationError): instance.run_validators("http://www.example.com/dlfjg 23/x") - def test_username_field(self, _): + def test_username_field(self, *_): """again, just setting defaults on username field""" instance = fields.UsernameField() self.assertEqual(instance.activitypub_field, "preferredUsername") @@ -131,7 +131,7 @@ class ModelFields(TestCase): self.assertEqual(instance.field_to_activity("test@example.com"), "test") - def test_privacy_field_defaults(self, _): + def test_privacy_field_defaults(self, *_): """post privacy field's many default values""" instance = fields.PrivacyField() self.assertEqual(instance.max_length, 255) @@ -144,7 +144,7 @@ class ModelFields(TestCase): instance.public, "https://www.w3.org/ns/activitystreams#Public" ) - def test_privacy_field_set_field_from_activity(self, _): + def test_privacy_field_set_field_from_activity(self, *_): """translate between to/cc fields and privacy""" with patch("bookwyrm.models.user.set_remote_server.delay"): @@ -252,7 +252,7 @@ class ModelFields(TestCase): self.assertEqual(activity["to"], [user.remote_id]) self.assertEqual(activity["cc"], []) - def test_foreign_key(self, _): + def test_foreign_key(self, *_): """should be able to format a related model""" instance = fields.ForeignKey("User", on_delete=models.CASCADE) Serializable = namedtuple("Serializable", ("to_activity", "remote_id")) @@ -261,7 +261,7 @@ class ModelFields(TestCase): self.assertEqual(instance.field_to_activity(item), "https://e.b/c") @responses.activate - def test_foreign_key_from_activity_str(self, _): + def test_foreign_key_from_activity_str(self, *_): """create a new object from a foreign key""" instance = fields.ForeignKey(User, on_delete=models.CASCADE) datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") @@ -308,7 +308,7 @@ class ModelFields(TestCase): self.assertEqual(value.name, "MOUSE?? MOUSE!!") # et cetera but we're not testing serializing user json - def test_foreign_key_from_activity_dict_existing(self, _): + def test_foreign_key_from_activity_dict_existing(self, *_): """test receiving a dict of an existing object in the db""" instance = fields.ForeignKey(User, on_delete=models.CASCADE) datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") @@ -327,7 +327,7 @@ class ModelFields(TestCase): value = instance.field_from_activity(activitypub.Person(**userdata)) self.assertEqual(value, user) - def test_foreign_key_from_activity_str_existing(self, _): + def test_foreign_key_from_activity_str_existing(self, *_): """test receiving a remote id of an existing object in the db""" instance = fields.ForeignKey(User, on_delete=models.CASCADE) user = User.objects.create_user( @@ -340,14 +340,14 @@ class ModelFields(TestCase): value = instance.field_from_activity(user.remote_id) self.assertEqual(value, user) - def test_one_to_one_field(self, _): + def test_one_to_one_field(self, *_): """a gussied up foreign key""" instance = fields.OneToOneField("User", on_delete=models.CASCADE) Serializable = namedtuple("Serializable", ("to_activity", "remote_id")) item = Serializable(lambda: {"a": "b"}, "https://e.b/c") self.assertEqual(instance.field_to_activity(item), {"a": "b"}) - def test_many_to_many_field(self, _): + def test_many_to_many_field(self, *_): """lists!""" instance = fields.ManyToManyField("User") @@ -365,7 +365,7 @@ class ModelFields(TestCase): self.assertEqual(instance.field_to_activity(items), "example.com/snake_case") @responses.activate - def test_many_to_many_field_from_activity(self, _): + def test_many_to_many_field_from_activity(self, *_): """resolve related fields for a list, takes a list of remote ids""" instance = fields.ManyToManyField(User) datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") @@ -385,7 +385,7 @@ class ModelFields(TestCase): self.assertEqual(len(value), 1) self.assertIsInstance(value[0], User) - def test_tag_field(self, _): + def test_tag_field(self, *_): """a special type of many to many field""" instance = fields.TagField("User") @@ -404,7 +404,7 @@ class ModelFields(TestCase): self.assertEqual(result[0].name, "Name") self.assertEqual(result[0].type, "Serializable") - def test_tag_field_from_activity(self, _): + def test_tag_field_from_activity(self, *_): """loadin' a list of items from Links""" # TODO @@ -449,7 +449,7 @@ class ModelFields(TestCase): self.assertIsInstance(loaded_image, list) self.assertIsInstance(loaded_image[1], ContentFile) - def test_image_serialize(self, _): + def test_image_serialize(self, *_): """make sure we're creating sensible image paths""" ValueMock = namedtuple("ValueMock", ("url")) value_mock = ValueMock("/images/fish.jpg") @@ -458,7 +458,7 @@ class ModelFields(TestCase): self.assertEqual(result.url, "https://your.domain.here/images/fish.jpg") self.assertEqual(result.name, "hello") - def test_datetime_field(self, _): + def test_datetime_field(self, *_): """this one is pretty simple, it just has to use isoformat""" instance = fields.DateTimeField() now = timezone.now() @@ -466,12 +466,12 @@ class ModelFields(TestCase): self.assertEqual(instance.field_from_activity(now.isoformat()), now) self.assertEqual(instance.field_from_activity("bip"), None) - def test_array_field(self, _): + def test_array_field(self, *_): """idk why it makes them strings but probably for a good reason""" instance = fields.ArrayField(fields.IntegerField) self.assertEqual(instance.field_to_activity([0, 1]), ["0", "1"]) - def test_html_field(self, _): + def test_html_field(self, *_): """sanitizes html, the sanitizer has its own tests""" instance = fields.HtmlField() self.assertEqual( diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 3179b1387..54d811621 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -23,7 +23,7 @@ class Shelf(TestCase): work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create(title="test book", parent_work=work) - def test_remote_id(self, _): + def test_remote_id(self, *_): """shelves use custom remote ids""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): shelf = models.Shelf.objects.create( @@ -32,7 +32,7 @@ class Shelf(TestCase): expected_id = "https://%s/user/mouse/books/test-shelf" % settings.DOMAIN self.assertEqual(shelf.get_remote_id(), expected_id) - def test_to_activity(self, _): + def test_to_activity(self, *_): """jsonify it""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): shelf = models.Shelf.objects.create( @@ -46,7 +46,7 @@ class Shelf(TestCase): self.assertEqual(activity_json["name"], "Test Shelf") self.assertEqual(activity_json["owner"], self.local_user.remote_id) - def test_create_update_shelf(self, _): + def test_create_update_shelf(self, *_): """create and broadcast shelf creation""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: @@ -67,7 +67,7 @@ class Shelf(TestCase): self.assertEqual(activity["object"]["name"], "arthur russel") self.assertEqual(shelf.name, "arthur russel") - def test_shelve(self, _): + def test_shelve(self, *_): """create and broadcast shelf creation""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): shelf = models.Shelf.objects.create( diff --git a/bookwyrm/tests/views/test_authentication.py b/bookwyrm/tests/views/test_authentication.py index f0fd5392f..95a4d9a0b 100644 --- a/bookwyrm/tests/views/test_authentication.py +++ b/bookwyrm/tests/views/test_authentication.py @@ -38,7 +38,7 @@ class AuthenticationViews(TestCase): id=1, require_confirm_email=False ) - def test_login_get(self, _): + def test_login_get(self, *_): """there are so many views, this just makes sure it LOADS""" login = views.Login.as_view() request = self.factory.get("") @@ -54,7 +54,7 @@ class AuthenticationViews(TestCase): self.assertEqual(result.url, "/") self.assertEqual(result.status_code, 302) - def test_login_post_localname(self, _): + def test_login_post_localname(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Login.as_view() form = forms.LoginForm() @@ -68,7 +68,7 @@ class AuthenticationViews(TestCase): self.assertEqual(result.url, "/") self.assertEqual(result.status_code, 302) - def test_login_post_username(self, _): + def test_login_post_username(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Login.as_view() form = forms.LoginForm() @@ -82,7 +82,7 @@ class AuthenticationViews(TestCase): self.assertEqual(result.url, "/") self.assertEqual(result.status_code, 302) - def test_login_post_email(self, _): + def test_login_post_email(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Login.as_view() form = forms.LoginForm() @@ -96,7 +96,7 @@ class AuthenticationViews(TestCase): self.assertEqual(result.url, "/") self.assertEqual(result.status_code, 302) - def test_login_post_invalid_credentials(self, _): + def test_login_post_invalid_credentials(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Login.as_view() form = forms.LoginForm() @@ -114,7 +114,7 @@ class AuthenticationViews(TestCase): "Username or password are incorrect", ) - def test_register(self, _): + def test_register(self, *_): """create a user""" view = views.Register.as_view() self.assertEqual(models.User.objects.count(), 1) @@ -162,7 +162,7 @@ class AuthenticationViews(TestCase): self.assertEqual(nutria.deactivation_reason, "pending") self.assertIsNotNone(nutria.confirmation_code) - def test_register_trailing_space(self, _): + def test_register_trailing_space(self, *_): """django handles this so weirdly""" view = views.Register.as_view() request = self.factory.post( @@ -178,7 +178,7 @@ class AuthenticationViews(TestCase): self.assertEqual(nutria.localname, "nutria") self.assertEqual(nutria.local, True) - def test_register_invalid_email(self, _): + def test_register_invalid_email(self, *_): """gotta have an email""" view = views.Register.as_view() self.assertEqual(models.User.objects.count(), 1) @@ -189,7 +189,7 @@ class AuthenticationViews(TestCase): self.assertEqual(models.User.objects.count(), 1) response.render() - def test_register_invalid_username(self, _): + def test_register_invalid_username(self, *_): """gotta have an email""" view = views.Register.as_view() self.assertEqual(models.User.objects.count(), 1) @@ -217,7 +217,7 @@ class AuthenticationViews(TestCase): self.assertEqual(models.User.objects.count(), 1) response.render() - def test_register_closed_instance(self, _): + def test_register_closed_instance(self, *_): """you can't just register""" view = views.Register.as_view() self.settings.allow_registration = False @@ -229,7 +229,7 @@ class AuthenticationViews(TestCase): with self.assertRaises(PermissionDenied): view(request) - def test_register_invite(self, _): + def test_register_invite(self, *_): """you can't just register""" view = views.Register.as_view() self.settings.allow_registration = False @@ -282,7 +282,7 @@ class AuthenticationViews(TestCase): response = view(request) self.assertEqual(models.User.objects.count(), 2) - def test_confirm_email_code_get(self, _): + def test_confirm_email_code_get(self, *_): """there are so many views, this just makes sure it LOADS""" self.settings.require_confirm_email = True self.settings.save() @@ -311,7 +311,7 @@ class AuthenticationViews(TestCase): self.assertEqual(result.url, "/") self.assertEqual(result.status_code, 302) - def test_confirm_email_code_get_invalid_code(self, _): + def test_confirm_email_code_get_invalid_code(self, *_): """there are so many views, this just makes sure it LOADS""" self.settings.require_confirm_email = True self.settings.save() @@ -334,7 +334,7 @@ class AuthenticationViews(TestCase): self.assertFalse(self.local_user.is_active) self.assertEqual(self.local_user.deactivation_reason, "pending") - def test_confirm_email_get(self, _): + def test_confirm_email_get(self, *_): """there are so many views, this just makes sure it LOADS""" self.settings.require_confirm_email = True self.settings.save() diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 98962bc4e..d4baa72f0 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -7,6 +7,7 @@ from django.test.client import RequestFactory from bookwyrm import forms, models, views +@patch("bookwyrm.activitystreams.populate_stream_task.delay") class GetStartedViews(TestCase): """helping new users get oriented""" @@ -46,7 +47,6 @@ class GetStartedViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") def test_profile_view_post(self, *_): """save basic user details""" @@ -91,7 +91,6 @@ class GetStartedViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") def test_books_view_post(self, _): """shelve some books""" view = views.GetStartedBooks.as_view() diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index a3c812b41..ef460282e 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -378,7 +378,7 @@ class StatusViews(TestCase): status.refresh_from_db() self.assertFalse(status.deleted) - def test_handle_delete_status_moderator(self, mock, _): + def test_handle_delete_status_moderator(self, mock, *_): """marks a status as deleted""" view = views.DeleteStatus.as_view() with patch("bookwyrm.activitystreams.add_status_task.delay"): diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index d14c62432..7209c8ed5 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -103,8 +103,8 @@ class UserViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") - def test_followers_page_blocked(self, _): + @patch("bookwyrm.activitystreams.populate_stream_task.delay") + def test_followers_page_blocked(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Followers.as_view() request = self.factory.get("") From 38dc640dd50a0c2c5efdcb0e68b1110704c2741f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 15:10:52 -0700 Subject: [PATCH 14/23] Mock for goodreads import test` --- bookwyrm/tests/importers/test_goodreads_import.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index 47fd6a33e..dd33a140e 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -23,6 +23,7 @@ def make_date(*args): # pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay.delay") class GoodreadsImport(TestCase): """importing from goodreads csv""" From 4db255758184bf7f7af3658375d88c366e9063ae Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 15:39:32 -0700 Subject: [PATCH 15/23] Fixes handling boosts --- bookwyrm/activitystreams.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index cb59f1a7f..51bb74931 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -272,16 +272,8 @@ def add_status_on_create_command(sender, instance, created): """runs this code only after the database commit completes""" add_status_task.delay(instance.id, increment_unread_unread=created) - if sender != models.Boost: - return - # remove the original post and other, earlier boosts - boosted = instance.boost.boosted_status - old_versions = models.Boost.objects.filter( - boosted_status__id=boosted.id, - created_date__lt=instance.created_date, - ).values_list("id", flat=True) - remove_status_task.delay(boosted.id) - remove_status_task.delay(old_versions) + if sender == models.Boost: + handle_boost_task.delay(instance.id) @receiver(signals.post_delete, sender=models.Boost) @@ -466,3 +458,21 @@ def add_user_statuses_task(viewer_id, user_id, stream_list=None): user = models.User.objects.get(id=user_id) for stream in stream_list: stream.add_user_statuses(viewer, user) + + +@app.task +def handle_boost_task(boost_id): + """remove the original post and other, earlier boosts""" + instance = models.Status.objects.get(id=boost_id) + boosted = instance.boost.boosted_status.id + + old_versions = models.Boost.objects.filter( + boosted_status__id=boosted.id, + created_date__lt=instance.created_date, + ).values_list("id", flat=True) + + for stream in streams.values(): + audience = stream.get_stores_for_object(instance) + stream.remove_object_from_related_stores(boosted, stores=audience) + for status in old_versions: + stream.remove_object_from_related_stores(status, stores=audience) From e35c8059606197fdf53f4b7f4ea228ccf5dad971 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 15:48:02 -0700 Subject: [PATCH 16/23] Fixes typo in function call --- bookwyrm/activitystreams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 51bb74931..4389fab41 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -270,7 +270,7 @@ def add_status_on_create(sender, instance, created, *args, **kwargs): def add_status_on_create_command(sender, instance, created): """runs this code only after the database commit completes""" - add_status_task.delay(instance.id, increment_unread_unread=created) + add_status_task.delay(instance.id, increment_unread=created) if sender == models.Boost: handle_boost_task.delay(instance.id) From 4ea9637a2ddab89f102239d7adf15116929ade8e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 16:16:45 -0700 Subject: [PATCH 17/23] Updates activitystreams tests --- bookwyrm/activitystreams.py | 2 +- bookwyrm/tests/test_activitystreams.py | 21 ++++++++------------- bookwyrm/tests/views/test_directory.py | 2 +- bookwyrm/tests/views/test_editions.py | 2 +- bookwyrm/tests/views/test_reports.py | 2 +- bookwyrm/tests/views/test_user_admin.py | 2 +- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 4389fab41..6dedd7176 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -464,7 +464,7 @@ def add_user_statuses_task(viewer_id, user_id, stream_list=None): def handle_boost_task(boost_id): """remove the original post and other, earlier boosts""" instance = models.Status.objects.get(id=boost_id) - boosted = instance.boost.boosted_status.id + boosted = instance.boost.boosted_status old_versions = models.Boost.objects.filter( boosted_status__id=boosted.id, diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index aecc448c4..add5875f7 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -6,7 +6,7 @@ from bookwyrm import activitystreams, models @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.activitystreams.add_status_task.delay") -@patch("bookwyrm.activitystreams.BooksStream.add_book_statuses") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") # pylint: disable=too-many-public-methods @@ -296,9 +296,7 @@ class Activitystreams(TestCase): def test_boost_to_another_timeline(self, *_): """add a boost and deduplicate the boosted status on the timeline""" status = models.Status.objects.create(user=self.local_user, content="hi") - with patch( - "bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores" - ): + with patch("bookwyrm.activitystreams.handle_boost_task.delay"): boost = models.Boost.objects.create( boosted_status=status, user=self.another_user, @@ -306,7 +304,8 @@ class Activitystreams(TestCase): with patch( "bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores" ) as mock: - activitystreams.add_status_on_create(models.Boost, boost, True) + activitystreams.handle_boost_task(boost.id) + self.assertTrue(mock.called) call_args = mock.call_args self.assertEqual(call_args[0][0], status) @@ -320,9 +319,7 @@ class Activitystreams(TestCase): """add a boost and deduplicate the boosted status on the timeline""" self.local_user.following.add(self.another_user) status = models.Status.objects.create(user=self.local_user, content="hi") - with patch( - "bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores" - ): + with patch("bookwyrm.activitystreams.handle_boost_task.delay"): boost = models.Boost.objects.create( boosted_status=status, user=self.another_user, @@ -330,7 +327,7 @@ class Activitystreams(TestCase): with patch( "bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores" ) as mock: - activitystreams.add_status_on_create(models.Boost, boost, True) + activitystreams.handle_boost_task(boost.id) self.assertTrue(mock.called) call_args = mock.call_args self.assertEqual(call_args[0][0], status) @@ -346,9 +343,7 @@ class Activitystreams(TestCase): def test_boost_to_same_timeline(self, *_): """add a boost and deduplicate the boosted status on the timeline""" status = models.Status.objects.create(user=self.local_user, content="hi") - with patch( - "bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores" - ): + with patch("bookwyrm.activitystreams.handle_boost_task.delay"): boost = models.Boost.objects.create( boosted_status=status, user=self.local_user, @@ -356,7 +351,7 @@ class Activitystreams(TestCase): with patch( "bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores" ) as mock: - activitystreams.add_status_on_create(models.Boost, boost, True) + activitystreams.handle_boost_task(boost.id) self.assertTrue(mock.called) call_args = mock.call_args self.assertEqual(call_args[0][0], status) diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index 52f9c0851..90638b0a6 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -32,7 +32,7 @@ class DirectoryViews(TestCase): self.anonymous_user.is_authenticated = False @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") + @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") def test_directory_page(self, *_): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/test_editions.py b/bookwyrm/tests/views/test_editions.py index 1cd256b1d..d1eb34c4a 100644 --- a/bookwyrm/tests/views/test_editions.py +++ b/bookwyrm/tests/views/test_editions.py @@ -103,7 +103,7 @@ class BookViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") + @patch("bookwyrm.activitystreams.populate_stream_task.delay") def test_switch_edition(self, _): """updates user's relationships to a book""" work = models.Work.objects.create(title="test work") diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index 2f9ee27b8..1b0b6008a 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -119,7 +119,7 @@ class ReportViews(TestCase): self.assertFalse(report.resolved) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") + @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") def test_suspend_user(self, *_): """toggle whether a user is able to log in""" diff --git a/bookwyrm/tests/views/test_user_admin.py b/bookwyrm/tests/views/test_user_admin.py index eab8ab686..3917a6fd9 100644 --- a/bookwyrm/tests/views/test_user_admin.py +++ b/bookwyrm/tests/views/test_user_admin.py @@ -51,7 +51,7 @@ class UserAdminViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") -@patch("bookwyrm.activitystreams.populate_stream_task.delay") + @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") def test_user_admin_page_post(self, *_): """set the user's group""" From db34918347ea62e18219e7dcb5ce521e474e6f47 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 16:33:21 -0700 Subject: [PATCH 18/23] Updates user view test --- bookwyrm/tests/views/test_user.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 7209c8ed5..614f772d7 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -33,15 +33,14 @@ class UserViews(TestCase): self.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ): - models.ShelfBook.objects.create( - book=self.book, - user=self.local_user, - shelf=self.local_user.shelf_set.first(), - ) + with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"), patch( + "bookwyrm.suggested_users.rerank_suggestions_task.delay" + ), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"): + models.ShelfBook.objects.create( + book=self.book, + user=self.local_user, + shelf=self.local_user.shelf_set.first(), + ) models.SiteSettings.objects.create() self.anonymous_user = AnonymousUser From 59400511c94dee5abe5f821e4cff8b409d68fdd3 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 16:59:58 -0700 Subject: [PATCH 19/23] mocks mocks more mocks --- .../tests/importers/test_goodreads_import.py | 2 +- .../importers/test_librarything_import.py | 1 + .../tests/models/test_relationship_models.py | 11 +++-- bookwyrm/tests/models/test_shelf_model.py | 1 + bookwyrm/tests/models/test_status_model.py | 17 +++---- bookwyrm/tests/test_suggested_users.py | 1 + bookwyrm/tests/test_templatetags.py | 17 +++---- .../tests/views/inbox/test_inbox_create.py | 47 +++++++------------ bookwyrm/tests/views/test_block.py | 4 +- bookwyrm/tests/views/test_edit_user.py | 4 +- bookwyrm/tests/views/test_feed.py | 13 ++--- bookwyrm/tests/views/test_follow.py | 14 +++--- bookwyrm/tests/views/test_get_started.py | 13 ++--- bookwyrm/tests/views/test_interaction.py | 15 ++---- bookwyrm/tests/views/test_status.py | 1 + 15 files changed, 75 insertions(+), 86 deletions(-) diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index dd33a140e..387d9f4f2 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -23,7 +23,7 @@ def make_date(*args): # pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") -@patch("bookwyrm.activitystreams.add_book_statuses_task.delay.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") class GoodreadsImport(TestCase): """importing from goodreads csv""" diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index c7ddbed69..dfdd515e1 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -22,6 +22,7 @@ def make_date(*args): # pylint: disable=consider-using-with @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") class LibrarythingImport(TestCase): """importing from librarything tsv""" diff --git a/bookwyrm/tests/models/test_relationship_models.py b/bookwyrm/tests/models/test_relationship_models.py index 7383a489a..04dbe1a33 100644 --- a/bookwyrm/tests/models/test_relationship_models.py +++ b/bookwyrm/tests/models/test_relationship_models.py @@ -6,6 +6,7 @@ from django.test import TestCase from bookwyrm import models +@patch("bookwyrm.activitystreams.add_user_statuses_task.delay") class Relationship(TestCase): """following, blocking, stuff like that""" @@ -30,7 +31,7 @@ class Relationship(TestCase): self.local_user.remote_id = "http://local.com/user/mouse" self.local_user.save(broadcast=False, update_fields=["remote_id"]) - def test_user_follows_from_request(self): + def test_user_follows_from_request(self, _): """convert a follow request into a follow""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: request = models.UserFollowRequest.objects.create( @@ -51,7 +52,7 @@ class Relationship(TestCase): self.assertEqual(rel.user_subject, self.local_user) self.assertEqual(rel.user_object, self.remote_user) - 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""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): request = models.UserFollowRequest.objects.create( @@ -69,7 +70,7 @@ class Relationship(TestCase): self.assertEqual(rel.user_object, self.remote_user) @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") - def test_follow_request_activity(self, broadcast_mock): + def test_follow_request_activity(self, broadcast_mock, _): """accept a request and make it a relationship""" models.UserFollowRequest.objects.create( user_subject=self.local_user, @@ -81,7 +82,7 @@ class Relationship(TestCase): self.assertEqual(activity["type"], "Follow") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") - def test_follow_request_accept(self, broadcast_mock): + def test_follow_request_accept(self, broadcast_mock, _): """accept a request and make it a relationship""" self.local_user.manually_approves_followers = True self.local_user.save( @@ -107,7 +108,7 @@ class Relationship(TestCase): self.assertEqual(rel.user_object, self.local_user) @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") - def test_follow_request_reject(self, broadcast_mock): + def test_follow_request_reject(self, broadcast_mock, _): """accept a request and make it a relationship""" self.local_user.manually_approves_followers = True self.local_user.save( diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 54d811621..26bf8d8a4 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -9,6 +9,7 @@ from bookwyrm import models, settings # pylint: disable=unused-argument @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") class Shelf(TestCase): """some activitypub oddness ahead""" diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 9913911cd..6bdfa336a 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -16,7 +16,7 @@ from bookwyrm import activitypub, models, settings # pylint: disable=too-many-public-methods @patch("bookwyrm.models.Status.broadcast") @patch("bookwyrm.activitystreams.add_status_task.delay") -@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") +@patch("bookwyrm.activitystreams.remove_status_task.delay") class Status(TestCase): """lotta types of statuses""" @@ -120,15 +120,12 @@ class Status(TestCase): def test_status_to_activity_tombstone(self, *_): """subclass of the base model version with a "pure" serializer""" - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ): - status = models.Status.objects.create( - content="test content", - user=self.local_user, - deleted=True, - deleted_date=timezone.now(), - ) + status = models.Status.objects.create( + content="test content", + user=self.local_user, + deleted=True, + deleted_date=timezone.now(), + ) activity = status.to_activity() self.assertEqual(activity["id"], status.remote_id) self.assertEqual(activity["type"], "Tombstone") diff --git a/bookwyrm/tests/test_suggested_users.py b/bookwyrm/tests/test_suggested_users.py index 39758252a..6b794b5dc 100644 --- a/bookwyrm/tests/test_suggested_users.py +++ b/bookwyrm/tests/test_suggested_users.py @@ -13,6 +13,7 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") @patch("bookwyrm.suggested_users.rerank_user_task.delay") @patch("bookwyrm.suggested_users.remove_user_task.delay") class SuggestedUsers(TestCase): diff --git a/bookwyrm/tests/test_templatetags.py b/bookwyrm/tests/test_templatetags.py index 312d107b9..e13b50dcf 100644 --- a/bookwyrm/tests/test_templatetags.py +++ b/bookwyrm/tests/test_templatetags.py @@ -16,7 +16,7 @@ from bookwyrm.templatetags import ( @patch("bookwyrm.activitystreams.add_status_task.delay") -@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") +@patch("bookwyrm.activitystreams.remove_status_task.delay") class TemplateTags(TestCase): """lotta different things here""" @@ -75,15 +75,12 @@ class TemplateTags(TestCase): second_child = models.Status.objects.create( reply_parent=parent, user=self.user, content="hi" ) - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ): - third_child = models.Status.objects.create( - reply_parent=parent, - user=self.user, - deleted=True, - deleted_date=timezone.now(), - ) + third_child = models.Status.objects.create( + reply_parent=parent, + user=self.user, + deleted=True, + deleted_date=timezone.now(), + ) replies = status_display.get_replies(parent) self.assertEqual(len(replies), 2) diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index 76afb5380..3e1a22ae7 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -11,6 +11,7 @@ from bookwyrm.activitypub import ActivitySerializerError # pylint: disable=too-many-public-methods @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") class InboxCreate(TestCase): """readthrough tests""" @@ -49,7 +50,6 @@ class InboxCreate(TestCase): } models.SiteSettings.objects.create() - @patch("bookwyrm.activitystreams.add_status_task.delay") def test_create_status(self, *_): """the "it justs works" mode""" datafile = pathlib.Path(__file__).parent.joinpath( @@ -63,9 +63,7 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - views.inbox.activity_task(activity) - self.assertTrue(redis_mock.called) + views.inbox.activity_task(activity) status = models.Quotation.objects.get() self.assertEqual( @@ -79,7 +77,6 @@ class InboxCreate(TestCase): views.inbox.activity_task(activity) self.assertEqual(models.Status.objects.count(), 1) - @patch("bookwyrm.activitystreams.add_status_task.delay") def test_create_comment_with_reading_status(self, *_): """the "it justs works" mode""" datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_comment.json") @@ -92,9 +89,7 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - views.inbox.activity_task(activity) - self.assertTrue(redis_mock.called) + views.inbox.activity_task(activity) status = models.Comment.objects.get() self.assertEqual(status.remote_id, "https://example.com/user/mouse/comment/6") @@ -106,7 +101,7 @@ class InboxCreate(TestCase): views.inbox.activity_task(activity) self.assertEqual(models.Status.objects.count(), 1) - def test_create_status_remote_note_with_mention(self, _): + def test_create_status_remote_note_with_mention(self, *_): """should only create it under the right circumstances""" self.assertFalse( models.Notification.objects.filter(user=self.local_user).exists() @@ -117,9 +112,8 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - views.inbox.activity_task(activity) - self.assertTrue(redis_mock.called) + views.inbox.activity_task(activity) + status = models.Status.objects.last() self.assertEqual(status.content, "test content in note") self.assertEqual(status.mention_users.first(), self.local_user) @@ -128,14 +122,13 @@ class InboxCreate(TestCase): ) self.assertEqual(models.Notification.objects.get().notification_type, "MENTION") - def test_create_status_remote_note_with_reply(self, _): + def test_create_status_remote_note_with_reply(self, *_): """should only create it under the right circumstances""" - with patch("bookwyrm.activitystreams.add_status_task.delay"): - parent_status = models.Status.objects.create( - user=self.local_user, - content="Test status", - remote_id="https://example.com/status/1", - ) + parent_status = models.Status.objects.create( + user=self.local_user, + content="Test status", + remote_id="https://example.com/status/1", + ) self.assertEqual(models.Status.objects.count(), 1) self.assertFalse(models.Notification.objects.filter(user=self.local_user)) @@ -147,16 +140,14 @@ class InboxCreate(TestCase): activity = self.create_json activity["object"] = status_data - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - views.inbox.activity_task(activity) - self.assertTrue(redis_mock.called) + views.inbox.activity_task(activity) status = models.Status.objects.last() self.assertEqual(status.content, "test content in note") self.assertEqual(status.reply_parent, parent_status) self.assertTrue(models.Notification.objects.filter(user=self.local_user)) self.assertEqual(models.Notification.objects.get().notification_type, "REPLY") - def test_create_rating(self, _): + def test_create_rating(self, *_): """a remote rating activity""" book = models.Edition.objects.create( title="Test Book", remote_id="https://example.com/book/1" @@ -186,14 +177,12 @@ class InboxCreate(TestCase): "rating": 3, "@context": "https://www.w3.org/ns/activitystreams", } - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - views.inbox.activity_task(activity) - self.assertTrue(redis_mock.called) + views.inbox.activity_task(activity) rating = models.ReviewRating.objects.first() self.assertEqual(rating.book, book) self.assertEqual(rating.rating, 3.0) - def test_create_list(self, _): + def test_create_list(self, *_): """a new list""" activity = self.create_json activity["object"] = { @@ -217,7 +206,7 @@ class InboxCreate(TestCase): self.assertEqual(book_list.description, "summary text") self.assertEqual(book_list.remote_id, "https://example.com/list/22") - def test_create_unsupported_type(self, _): + def test_create_unsupported_type(self, *_): """ignore activities we know we can't handle""" activity = self.create_json activity["object"] = { @@ -227,7 +216,7 @@ class InboxCreate(TestCase): # just observer how it doesn't throw an error views.inbox.activity_task(activity) - def test_create_unknown_type(self, _): + def test_create_unknown_type(self, *_): """ignore activities we know we've never heard of""" activity = self.create_json activity["object"] = { diff --git a/bookwyrm/tests/views/test_block.py b/bookwyrm/tests/views/test_block.py index 28f526393..f1ec42f03 100644 --- a/bookwyrm/tests/views/test_block.py +++ b/bookwyrm/tests/views/test_block.py @@ -59,7 +59,7 @@ class BlockViews(TestCase): request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.remove_user_statuses"): + with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"): view(request, self.remote_user.id) block = models.UserBlocks.objects.get() self.assertEqual(block.user_subject, self.local_user) @@ -74,7 +74,7 @@ class BlockViews(TestCase): request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.add_user_statuses"): + with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"): views.block.unblock(request, self.remote_user.id) self.assertFalse(models.UserBlocks.objects.exists()) diff --git a/bookwyrm/tests/views/test_edit_user.py b/bookwyrm/tests/views/test_edit_user.py index 70e5eafd0..07e54e4e4 100644 --- a/bookwyrm/tests/views/test_edit_user.py +++ b/bookwyrm/tests/views/test_edit_user.py @@ -39,7 +39,9 @@ class EditUserViews(TestCase): self.book = models.Edition.objects.create( title="test", parent_work=models.Work.objects.create(title="test work") ) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"), patch( + "bookwyrm.activitystreams.add_book_statuses_task.delay" + ): models.ShelfBook.objects.create( book=self.book, user=self.local_user, diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index 843a9fd7d..526cb0f99 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -172,14 +172,15 @@ class FeedViews(TestCase): result.render() self.assertEqual(result.status_code, 200) + @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") + @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") def test_get_suggested_book(self, *_): """gets books the ~*~ algorithm ~*~ thinks you want to post about""" - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - models.ShelfBook.objects.create( - book=self.book, - user=self.local_user, - shelf=self.local_user.shelf_set.get(identifier="reading"), - ) + models.ShelfBook.objects.create( + book=self.book, + user=self.local_user, + shelf=self.local_user.shelf_set.get(identifier="reading"), + ) suggestions = views.feed.get_suggested_books(self.local_user) self.assertEqual(suggestions[0]["name"], "Currently Reading") self.assertEqual(suggestions[0]["books"][0], self.book) diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index a1dda42a7..947c55cf0 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -10,6 +10,7 @@ from django.test.client import RequestFactory from bookwyrm import models, views +@patch("bookwyrm.activitystreams.add_user_statuses_task.delay") class FollowViews(TestCase): """follows""" @@ -52,7 +53,7 @@ class FollowViews(TestCase): parent_work=self.work, ) - def test_handle_follow_remote(self): + def test_handle_follow_remote(self, _): """send a follow request""" request = self.factory.post("", {"user": self.remote_user.username}) request.user = self.local_user @@ -67,7 +68,7 @@ class FollowViews(TestCase): self.assertEqual(rel.user_object, self.remote_user) self.assertEqual(rel.status, "follow_request") - def test_handle_follow_local_manually_approves(self): + def test_handle_follow_local_manually_approves(self, _): """send a follow request""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -93,7 +94,7 @@ class FollowViews(TestCase): self.assertEqual(rel.user_object, rat) self.assertEqual(rel.status, "follow_request") - def test_handle_follow_local(self): + def test_handle_follow_local(self, _): """send a follow request""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -119,7 +120,8 @@ class FollowViews(TestCase): self.assertEqual(rel.user_object, rat) self.assertEqual(rel.status, "follows") - def test_handle_unfollow(self): + @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") + def test_handle_unfollow(self, *_): """send an unfollow""" request = self.factory.post("", {"user": self.remote_user.username}) request.user = self.local_user @@ -133,7 +135,7 @@ class FollowViews(TestCase): self.assertEqual(self.remote_user.followers.count(), 0) - def test_handle_accept(self): + def test_handle_accept(self, _): """accept a follow request""" self.local_user.manually_approves_followers = True self.local_user.save( @@ -152,7 +154,7 @@ class FollowViews(TestCase): # follow relationship should exist self.assertEqual(self.local_user.followers.first(), self.remote_user) - def test_handle_reject(self): + def test_handle_reject(self, _): """reject a follow request""" self.local_user.manually_approves_followers = True self.local_user.save( diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index d4baa72f0..135896dc2 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -34,7 +34,7 @@ class GetStartedViews(TestCase): ) models.SiteSettings.objects.create() - def test_profile_view(self): + def test_profile_view(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedProfile.as_view() request = self.factory.get("") @@ -66,7 +66,7 @@ class GetStartedViews(TestCase): self.assertEqual(self.local_user.name, "New Name") self.assertTrue(self.local_user.discoverable) - def test_books_view(self): + def test_books_view(self, _): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedBooks.as_view() request = self.factory.get("") @@ -78,7 +78,7 @@ class GetStartedViews(TestCase): result.render() self.assertEqual(result.status_code, 200) - def test_books_view_with_query(self): + def test_books_view_with_query(self, _): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedBooks.as_view() request = self.factory.get("?query=Example") @@ -91,7 +91,8 @@ class GetStartedViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") - def test_books_view_post(self, _): + @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") + def test_books_view_post(self, *_): """shelve some books""" view = views.GetStartedBooks.as_view() data = {self.book.id: self.local_user.shelf_set.first().id} @@ -110,7 +111,7 @@ class GetStartedViews(TestCase): self.assertEqual(shelfbook.user, self.local_user) @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") - def test_users_view(self, _): + def test_users_view(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedUsers.as_view() request = self.factory.get("") @@ -123,7 +124,7 @@ class GetStartedViews(TestCase): self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") - def test_users_view_with_query(self, _): + def test_users_view_with_query(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedUsers.as_view() request = self.factory.get("?query=rat") diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index aa3ea5115..e8b9353ed 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -8,7 +8,7 @@ from bookwyrm import models, views @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") -@patch("bookwyrm.activitystreams.remove_object_from_related_stores") +@patch("bookwyrm.activitystreams.remove_status_task.delay") class InteractionViews(TestCase): """viewing and creating statuses""" @@ -173,17 +173,12 @@ class InteractionViews(TestCase): request.user = self.remote_user status = models.Status.objects.create(user=self.local_user, content="hi") - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ): - views.Boost.as_view()(request, status.id) + views.Boost.as_view()(request, status.id) self.assertEqual(models.Boost.objects.count(), 1) self.assertEqual(models.Notification.objects.count(), 1) - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as redis_mock: - view(request, status.id) - self.assertTrue(redis_mock.called) + + view(request, status.id) + self.assertEqual(models.Boost.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0) diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index ef460282e..c197a0bc5 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -11,6 +11,7 @@ from bookwyrm.settings import DOMAIN # pylint: disable=invalid-name @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.remove_status_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") class StatusViews(TestCase): """viewing and creating statuses""" From 2653458e569953d6642651b4fa25d27944989810 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 18:39:14 -0700 Subject: [PATCH 20/23] another round of mocks --- bookwyrm/tests/models/test_shelf_model.py | 1 + .../tests/views/inbox/test_inbox_announce.py | 17 +++--- .../tests/views/inbox/test_inbox_block.py | 4 +- .../tests/views/inbox/test_inbox_delete.py | 10 ++-- .../tests/views/inbox/test_inbox_follow.py | 3 +- .../tests/views/inbox/test_inbox_update.py | 3 +- bookwyrm/tests/views/test_editions.py | 2 +- bookwyrm/tests/views/test_reading.py | 1 + bookwyrm/tests/views/test_readthrough.py | 2 + bookwyrm/tests/views/test_shelf.py | 2 + bookwyrm/tests/views/test_status.py | 54 ++++++------------- 11 files changed, 38 insertions(+), 61 deletions(-) diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 26bf8d8a4..fe179e883 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -10,6 +10,7 @@ from bookwyrm import models, settings @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") +@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay") class Shelf(TestCase): """some activitypub oddness ahead""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index fcf3e4105..3a108878c 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -55,9 +55,8 @@ class InboxActivities(TestCase): models.SiteSettings.objects.create() - @patch("bookwyrm.activitystreams.add_status_task.delay") - @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") - def test_boost(self, redis_mock, _): + @patch("bookwyrm.activitystreams.handle_boost_task.delay") + def test_boost(self, _): """boost a status""" self.assertEqual(models.Notification.objects.count(), 0) activity = { @@ -73,9 +72,6 @@ class InboxActivities(TestCase): discarder.return_value = False views.inbox.activity_task(activity) - # boost added to redis activitystreams - self.assertTrue(redis_mock.called) - # boost created of correct status boost = models.Boost.objects.get() self.assertEqual(boost.boosted_status, self.status) @@ -86,9 +82,8 @@ class InboxActivities(TestCase): self.assertEqual(notification.related_status, self.status) @responses.activate - @patch("bookwyrm.activitystreams.add_status_task.delay") - @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") - def test_boost_remote_status(self, redis_mock, _): + @patch("bookwyrm.activitystreams.handle_boost_task.delay") + def test_boost_remote_status(self, _): """boost a status from a remote server""" work = models.Work.objects.create(title="work title") book = models.Edition.objects.create( @@ -129,7 +124,6 @@ class InboxActivities(TestCase): with patch("bookwyrm.models.status.Status.ignore_activity") as discarder: discarder.return_value = False views.inbox.activity_task(activity) - self.assertTrue(redis_mock.called) boost = models.Boost.objects.get() self.assertEqual(boost.boosted_status.remote_id, "https://remote.com/status/1") @@ -161,7 +155,8 @@ class InboxActivities(TestCase): self.assertEqual(models.Boost.objects.count(), 0) @patch("bookwyrm.activitystreams.add_status_task.delay") - @patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores") + @patch("bookwyrm.activitystreams.handle_boost_task.delay") + @patch("bookwyrm.activitystreams.remove_status_task.delay") def test_unboost(self, *_): """undo a boost""" boost = models.Boost.objects.create( diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index dc29954d9..154391ed3 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -56,7 +56,7 @@ class InboxBlock(TestCase): } with patch( - "bookwyrm.activitystreams.ActivityStream.remove_user_statuses" + "bookwyrm.activitystreams.remove_user_statuses_task.delay" ) as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) @@ -94,7 +94,7 @@ class InboxBlock(TestCase): }, } with patch( - "bookwyrm.activitystreams.ActivityStream.add_user_statuses" + "bookwyrm.activitystreams.add_user_statuses_task.delay" ) as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 23a956b2b..3bda8ace3 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -1,4 +1,4 @@ -""" tests incoming activities""" +"""tests incoming activities""" from datetime import datetime from unittest.mock import patch @@ -63,9 +63,7 @@ class InboxActivities(TestCase): "actor": self.remote_user.remote_id, "object": {"id": self.status.remote_id, "type": "Tombstone"}, } - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as redis_mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) # deletion doens't remove the status, it turns it into a tombstone @@ -94,9 +92,7 @@ class InboxActivities(TestCase): "actor": self.remote_user.remote_id, "object": {"id": self.status.remote_id, "type": "Tombstone"}, } - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as redis_mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock: views.inbox.activity_task(activity) self.assertTrue(redis_mock.called) # deletion doens't remove the status, it turns it into a tombstone diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index 62c84044a..6b629c2f0 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -183,7 +183,8 @@ class InboxRelationships(TestCase): views.inbox.activity_task(activity) self.assertIsNone(self.local_user.followers.first()) - def test_follow_accept(self): + @patch("bookwyrm.activitystreams.add_user_statuses_task.delay") + def test_follow_accept(self, _): """a remote user approved a follow request from local""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): rel = models.UserFollowRequest.objects.create( diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index fc3b3a2a1..ec10f2f81 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -83,7 +83,8 @@ class InboxUpdate(TestCase): self.assertEqual(book_list.remote_id, "https://example.com/list/22") @patch("bookwyrm.suggested_users.rerank_user_task.delay") - def test_update_user(self, _): + @patch("bookwyrm.activitystreams.add_user_statuses_task.delay") + def test_update_user(self, *_): """update an existing user""" models.UserFollows.objects.create( user_subject=self.local_user, diff --git a/bookwyrm/tests/views/test_editions.py b/bookwyrm/tests/views/test_editions.py index d1eb34c4a..4a4dc3cb6 100644 --- a/bookwyrm/tests/views/test_editions.py +++ b/bookwyrm/tests/views/test_editions.py @@ -104,7 +104,7 @@ class BookViews(TestCase): @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") - def test_switch_edition(self, _): + def test_switch_edition(self, *_): """updates user's relationships to a book""" work = models.Work.objects.create(title="test work") edition1 = models.Edition.objects.create(title="first ed", parent_work=work) diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index acd14775f..df1e83c6e 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -11,6 +11,7 @@ from bookwyrm import models, views @patch("bookwyrm.activitystreams.add_status_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") class ReadingViews(TestCase): """viewing and creating statuses""" diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index c246a263f..b3656f4c0 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -10,6 +10,8 @@ from bookwyrm import models @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") +@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay") class ReadThrough(TestCase): """readthrough tests""" diff --git a/bookwyrm/tests/views/test_shelf.py b/bookwyrm/tests/views/test_shelf.py index d7d334650..d873edc6a 100644 --- a/bookwyrm/tests/views/test_shelf.py +++ b/bookwyrm/tests/views/test_shelf.py @@ -12,6 +12,8 @@ from bookwyrm.activitypub import ActivitypubResponse @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") +@patch("bookwyrm.activitystreams.add_book_statuses_task.delay") +@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay") class ShelfViews(TestCase): """tag views""" diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index c197a0bc5..aad040cba 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -63,9 +63,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = self.local_user - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - view(request, "comment") - self.assertTrue(redis_mock.called) + view(request, "comment") status = models.Comment.objects.get() self.assertEqual(status.content, "

hi

") @@ -78,10 +76,9 @@ class StatusViews(TestCase): user = models.User.objects.create_user( "rat", "rat@rat.com", "password", local=True ) - with patch("bookwyrm.activitystreams.add_status_task.delay"): - parent = models.Status.objects.create( - content="parent status", user=self.local_user - ) + parent = models.Status.objects.create( + content="parent status", user=self.local_user + ) form = forms.ReplyForm( { "content": "hi", @@ -93,9 +90,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = user - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - view(request, "reply") - self.assertTrue(redis_mock.called) + view(request, "reply") status = models.Status.objects.get(user=user) self.assertEqual(status.content, "

hi

") @@ -123,9 +118,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = self.local_user - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - view(request, "comment") - self.assertTrue(redis_mock.called) + view(request, "comment") status = models.Status.objects.get() self.assertEqual(list(status.mention_users.all()), [user]) @@ -151,9 +144,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = self.local_user - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - view(request, "comment") - self.assertTrue(redis_mock.called) + view(request, "comment") status = models.Status.objects.get() form = forms.ReplyForm( @@ -167,9 +158,7 @@ class StatusViews(TestCase): request = self.factory.post("", form.data) request.user = user - with patch("bookwyrm.activitystreams.add_status_task.delay") as redis_mock: - view(request, "reply") - self.assertTrue(redis_mock.called) + view(request, "reply") reply = models.Status.replies(status).first() self.assertEqual(reply.content, "

right

") @@ -183,14 +172,11 @@ class StatusViews(TestCase): view = views.DeleteAndRedraft.as_view() request = self.factory.post("") request.user = self.local_user - with patch("bookwyrm.activitystreams.add_status_task.delay"): - status = models.Comment.objects.create( - content="hi", book=self.book, user=self.local_user - ) + status = models.Comment.objects.create( + content="hi", book=self.book, user=self.local_user + ) - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock: result = view(request, status.id) self.assertTrue(mock.called) result.render() @@ -209,9 +195,7 @@ class StatusViews(TestCase): book=self.book, rating=2.0, user=self.local_user ) - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock: result = view(request, status.id) self.assertFalse(mock.called) self.assertEqual(result.status_code, 400) @@ -229,9 +213,7 @@ class StatusViews(TestCase): content="hi", user=self.local_user ) - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock: result = view(request, status.id) self.assertFalse(mock.called) self.assertEqual(result.status_code, 400) @@ -354,9 +336,7 @@ class StatusViews(TestCase): request = self.factory.post("") request.user = self.local_user - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as redis_mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock: view(request, status.id) self.assertTrue(redis_mock.called) activity = json.loads(mock.call_args_list[1][0][1]) @@ -389,9 +369,7 @@ class StatusViews(TestCase): request.user = self.remote_user request.user.is_superuser = True - with patch( - "bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores" - ) as redis_mock: + with patch("bookwyrm.activitystreams.remove_status_task.delay") as redis_mock: view(request, status.id) self.assertTrue(redis_mock.called) activity = json.loads(mock.call_args_list[1][0][1]) From c56a9021b6b4f26b11a2a19c01fba8126f05ea8f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 18:55:48 -0700 Subject: [PATCH 21/23] A few more failing tests --- bookwyrm/tests/views/inbox/test_inbox_block.py | 1 + bookwyrm/tests/views/test_editions.py | 1 + bookwyrm/tests/views/test_reading.py | 3 ++- bookwyrm/tests/views/test_readthrough.py | 6 ++++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index 154391ed3..d8685a12d 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -69,6 +69,7 @@ class InboxBlock(TestCase): self.assertFalse(models.UserFollows.objects.exists()) self.assertFalse(models.UserFollowRequest.objects.exists()) + @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") def test_handle_unblock(self): """unblock a user""" self.remote_user.blocks.add(self.local_user) diff --git a/bookwyrm/tests/views/test_editions.py b/bookwyrm/tests/views/test_editions.py index 4a4dc3cb6..a138f3451 100644 --- a/bookwyrm/tests/views/test_editions.py +++ b/bookwyrm/tests/views/test_editions.py @@ -104,6 +104,7 @@ class BookViews(TestCase): @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @patch("bookwyrm.activitystreams.populate_stream_task.delay") + @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") def test_switch_edition(self, *_): """updates user's relationships to a book""" work = models.Work.objects.create(title="test work") diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index df1e83c6e..1df7d147e 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -77,7 +77,8 @@ class ReadingViews(TestCase): self.assertEqual(readthrough.user, self.local_user) self.assertEqual(readthrough.book, self.book) - def test_start_reading_reshelf(self, *_): + @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") + def test_start_reading_reshelve(self, *_): """begin a book""" to_read_shelf = self.local_user.shelf_set.get(identifier=models.Shelf.TO_READ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index b3656f4c0..07997ed2b 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -35,7 +35,8 @@ class ReadThrough(TestCase): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): self.client.force_login(self.user) - def test_create_basic_readthrough(self, delay_mock, _): + @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") + def test_create_basic_readthrough(self, delay_mock, *_): """A basic readthrough doesn't create a progress update""" self.assertEqual(self.edition.readthrough_set.count(), 0) @@ -56,7 +57,8 @@ class ReadThrough(TestCase): self.assertEqual(readthroughs[0].finish_date, None) self.assertEqual(delay_mock.call_count, 1) - def test_create_progress_readthrough(self, delay_mock, _): + @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") + def test_create_progress_readthrough(self, delay_mock, *_): """a readthrough with progress""" self.assertEqual(self.edition.readthrough_set.count(), 0) From 9988a3e82bb9f9c5e562a86eb3bf63208dd72ea6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 18:58:45 -0700 Subject: [PATCH 22/23] More test fixes --- bookwyrm/tests/views/test_readthrough.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index 07997ed2b..ef149ce30 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -36,7 +36,7 @@ class ReadThrough(TestCase): self.client.force_login(self.user) @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") - def test_create_basic_readthrough(self, delay_mock, *_): + def test_create_basic_readthrough(self, *_): """A basic readthrough doesn't create a progress update""" self.assertEqual(self.edition.readthrough_set.count(), 0) @@ -55,10 +55,9 @@ class ReadThrough(TestCase): ) self.assertEqual(readthroughs[0].progress, None) self.assertEqual(readthroughs[0].finish_date, None) - self.assertEqual(delay_mock.call_count, 1) @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") - def test_create_progress_readthrough(self, delay_mock, *_): + def test_create_progress_readthrough(self, *_): """a readthrough with progress""" self.assertEqual(self.edition.readthrough_set.count(), 0) @@ -93,8 +92,6 @@ class ReadThrough(TestCase): self.assertEqual(progress_updates[0].progress, 100) # Edit doesn't publish anything - self.assertEqual(delay_mock.call_count, 1) - self.client.post( "/delete-readthrough", { From 0a9d515d4559e80e2a6c953865a7396a279e0a8a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 20:37:09 -0700 Subject: [PATCH 23/23] two more mocks --- bookwyrm/tests/views/inbox/test_inbox_block.py | 2 +- bookwyrm/tests/views/test_reading.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index d8685a12d..ffd74dbde 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -70,7 +70,7 @@ class InboxBlock(TestCase): self.assertFalse(models.UserFollowRequest.objects.exists()) @patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") - def test_handle_unblock(self): + def test_handle_unblock(self, _): """unblock a user""" self.remote_user.blocks.add(self.local_user) diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 1df7d147e..3f5846d07 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -78,6 +78,7 @@ class ReadingViews(TestCase): self.assertEqual(readthrough.book, self.book) @patch("bookwyrm.activitystreams.add_book_statuses_task.delay") + @patch("bookwyrm.activitystreams.remove_book_statuses_task.delay") def test_start_reading_reshelve(self, *_): """begin a book""" to_read_shelf = self.local_user.shelf_set.get(identifier=models.Shelf.TO_READ)