diff --git a/bookwyrm/tests/test_suggested_users.py b/bookwyrm/tests/test_suggested_users.py index d950858d..13dfda39 100644 --- a/bookwyrm/tests/test_suggested_users.py +++ b/bookwyrm/tests/test_suggested_users.py @@ -2,6 +2,7 @@ from collections import namedtuple from unittest.mock import patch +from django.db.models import Q from django.test import TestCase from bookwyrm import models @@ -10,6 +11,8 @@ 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.suggested_users.rerank_suggestions_task.delay") +@patch("bookwyrm.suggested_users.rerank_user_task.delay") class SuggestedUsers(TestCase): """using redis to build activity streams""" @@ -41,8 +44,6 @@ class SuggestedUsers(TestCase): self.assertEqual(counts["mutuals"], 3) self.assertEqual(counts["shared_books"], 27) - @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") - @patch("bookwyrm.suggested_users.rerank_user_task.delay") def test_get_objects_for_store(self, *_): """list of people to follow for a given user""" @@ -96,6 +97,7 @@ class SuggestedUsers(TestCase): "fishword", local=True, localname="fish", + discoverable=True, ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): # 1 shared follow @@ -112,8 +114,8 @@ class SuggestedUsers(TestCase): user=user_1, book=self.book, shelf=user_1.shelf_set.first() ) - result = views.helpers.get_annotated_users(self.local_user) - self.assertEqual(result.count(), 3) + result = get_annotated_users(self.local_user) + self.assertEqual(result.count(), 2) self.assertTrue(user_1 in result) self.assertFalse(user_2 in result) self.assertTrue(self.local_user in result) diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py index 43032c62..9ca500c4 100644 --- a/bookwyrm/tests/views/inbox/test_inbox.py +++ b/bookwyrm/tests/views/inbox/test_inbox.py @@ -19,13 +19,14 @@ class Inbox(TestCase): self.client = Client() self.factory = RequestFactory() - local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) local_user.remote_id = "https://example.com/user/mouse" local_user.save(broadcast=False) with patch("bookwyrm.models.user.set_remote_server.delay"): diff --git a/bookwyrm/tests/views/inbox/test_inbox_add.py b/bookwyrm/tests/views/inbox/test_inbox_add.py index 64be49b8..4280196b 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_add.py +++ b/bookwyrm/tests/views/inbox/test_inbox_add.py @@ -13,13 +13,14 @@ class InboxAdd(TestCase): def setUp(self): """basic user and book data""" - local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) local_user.remote_id = "https://example.com/user/mouse" local_user.save(broadcast=False) with patch("bookwyrm.models.user.set_remote_server.delay"): diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index 5866ed1f..8bc6cd1d 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -13,15 +13,16 @@ class InboxActivities(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index 956cf538..ce650a00 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -12,15 +12,16 @@ class InboxBlock(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index d2fdb8b6..f93354bf 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -16,15 +16,16 @@ class InboxCreate(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 617dcf6f..cc3299aa 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -13,15 +13,16 @@ class InboxActivities(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index f5332b7a..9adce7ab 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -13,15 +13,16 @@ class InboxRelationships(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", @@ -102,7 +103,7 @@ class InboxRelationships(TestCase): } self.local_user.manually_approves_followers = True - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["manually_approves_followers"]) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): views.inbox.activity_task(activity) @@ -124,7 +125,7 @@ class InboxRelationships(TestCase): def test_undo_follow_request(self): """the requester cancels a follow request""" self.local_user.manually_approves_followers = True - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["manually_approves_followers"]) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): request = models.UserFollowRequest.objects.create( user_subject=self.remote_user, user_object=self.local_user diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index 433d5ba4..56f21e89 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -12,15 +12,16 @@ class InboxActivities(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/inbox/test_inbox_remove.py b/bookwyrm/tests/views/inbox/test_inbox_remove.py index 4e78480a..3d64fcb2 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_remove.py +++ b/bookwyrm/tests/views/inbox/test_inbox_remove.py @@ -12,15 +12,16 @@ class InboxRemove(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index 242cfe91..77c7ab76 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -14,15 +14,16 @@ class InboxUpdate(TestCase): def setUp(self): """basic user and book data""" - self.local_user = models.User.objects.create_user( - "mouse@example.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@example.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + ) self.local_user.remote_id = "https://example.com/user/mouse" - self.local_user.save(broadcast=False) + self.local_user.save(broadcast=False, update_fields=["remote_id"]) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index 2cfb0da9..b9a82e68 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -2,7 +2,6 @@ import json from unittest.mock import patch import pathlib -from django.db.models import Q from django.http import Http404 from django.test import TestCase from django.test.client import RequestFactory diff --git a/bookwyrm/tests/views/test_landing.py b/bookwyrm/tests/views/test_landing.py index 4690ed1b..4d1531e4 100644 --- a/bookwyrm/tests/views/test_landing.py +++ b/bookwyrm/tests/views/test_landing.py @@ -27,7 +27,8 @@ class LandingViews(TestCase): self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() - def test_home_page(self): + @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") + def test_home_page(self, _): """there are so many views, this just makes sure it LOADS""" view = views.Home.as_view() request = self.factory.get("") diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index bb32bcb1..d6034a94 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -116,6 +116,7 @@ class ReportViews(TestCase): report.refresh_from_db() self.assertFalse(report.resolved) + @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") def test_suspend_user(self): """toggle whether a user is able to log in""" self.assertTrue(self.rat.is_active) diff --git a/bookwyrm/tests/views/test_shelf.py b/bookwyrm/tests/views/test_shelf.py index ccba4c73..44c4b9cb 100644 --- a/bookwyrm/tests/views/test_shelf.py +++ b/bookwyrm/tests/views/test_shelf.py @@ -10,6 +10,7 @@ from bookwyrm.activitypub import ActivitypubResponse @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") +@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class ShelfViews(TestCase): """tag views""" @@ -37,7 +38,7 @@ class ShelfViews(TestCase): ) models.SiteSettings.objects.create() - def test_shelf_page(self, _): + def test_shelf_page(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.Shelf.as_view() shelf = self.local_user.shelf_set.first() @@ -64,7 +65,7 @@ class ShelfViews(TestCase): self.assertIsInstance(result, ActivitypubResponse) self.assertEqual(result.status_code, 200) - def test_edit_shelf_privacy(self, _): + def test_edit_shelf_privacy(self, *_): """set name or privacy on shelf""" view = views.Shelf.as_view() shelf = self.local_user.shelf_set.get(identifier="to-read") @@ -84,7 +85,7 @@ class ShelfViews(TestCase): self.assertEqual(shelf.privacy, "unlisted") - def test_edit_shelf_name(self, _): + def test_edit_shelf_name(self, *_): """change the name of an editable shelf""" view = views.Shelf.as_view() shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user) @@ -101,7 +102,7 @@ class ShelfViews(TestCase): self.assertEqual(shelf.name, "cool name") self.assertEqual(shelf.identifier, "testshelf-%d" % shelf.id) - def test_edit_shelf_name_not_editable(self, _): + def test_edit_shelf_name_not_editable(self, *_): """can't change the name of an non-editable shelf""" view = views.Shelf.as_view() shelf = self.local_user.shelf_set.get(identifier="to-read") @@ -116,7 +117,7 @@ class ShelfViews(TestCase): self.assertEqual(shelf.name, "To Read") - def test_handle_shelve(self, _): + def test_handle_shelve(self, *_): """shelve a book""" request = self.factory.post( "", {"book": self.book.id, "shelf": self.shelf.identifier} @@ -134,7 +135,7 @@ class ShelfViews(TestCase): # make sure the book is on the shelf self.assertEqual(self.shelf.books.get(), self.book) - def test_handle_shelve_to_read(self, _): + def test_handle_shelve_to_read(self, *_): """special behavior for the to-read shelf""" shelf = models.Shelf.objects.get(identifier="to-read") request = self.factory.post( @@ -147,7 +148,7 @@ class ShelfViews(TestCase): # make sure the book is on the shelf self.assertEqual(shelf.books.get(), self.book) - def test_handle_shelve_reading(self, _): + def test_handle_shelve_reading(self, *_): """special behavior for the reading shelf""" shelf = models.Shelf.objects.get(identifier="reading") request = self.factory.post( @@ -160,7 +161,7 @@ class ShelfViews(TestCase): # make sure the book is on the shelf self.assertEqual(shelf.books.get(), self.book) - def test_handle_shelve_read(self, _): + def test_handle_shelve_read(self, *_): """special behavior for the read shelf""" shelf = models.Shelf.objects.get(identifier="read") request = self.factory.post( @@ -173,7 +174,7 @@ class ShelfViews(TestCase): # make sure the book is on the shelf self.assertEqual(shelf.books.get(), self.book) - def test_handle_unshelve(self, _): + def test_handle_unshelve(self, *_): """remove a book from a shelf""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): models.ShelfBook.objects.create(