From be044bce0de604052c832e9f4be84b785bd84283 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 3 Aug 2021 10:25:53 -0700 Subject: [PATCH] Updates mocks --- bookwyrm/suggested_users.py | 4 +- .../importers/test_librarything_import.py | 9 +-- .../tests/management/test_populate_streams.py | 21 +++---- .../tests/models/test_activitypub_mixin.py | 7 ++- bookwyrm/tests/models/test_base_model.py | 7 ++- bookwyrm/tests/models/test_import_model.py | 7 ++- bookwyrm/tests/models/test_list.py | 7 ++- .../tests/models/test_readthrough_model.py | 8 ++- bookwyrm/tests/models/test_shelf_model.py | 16 +++--- bookwyrm/tests/models/test_status_model.py | 7 ++- bookwyrm/tests/models/test_user_model.py | 19 ++++--- bookwyrm/tests/views/test_announcements.py | 15 ++--- bookwyrm/tests/views/test_authentication.py | 30 +++++----- bookwyrm/tests/views/test_author.py | 17 +++--- bookwyrm/tests/views/test_block.py | 15 ++--- bookwyrm/tests/views/test_book.py | 17 +++--- bookwyrm/tests/views/test_directory.py | 50 ++++++++++++---- bookwyrm/tests/views/test_edit_user.py | 21 +++---- bookwyrm/tests/views/test_federation.py | 15 ++--- bookwyrm/tests/views/test_feed.py | 15 ++--- bookwyrm/tests/views/test_follow.py | 57 ++++++++++--------- bookwyrm/tests/views/test_get_started.py | 15 ++--- bookwyrm/tests/views/test_goal.py | 33 +++++------ bookwyrm/tests/views/test_helpers.py | 48 ++++++++-------- bookwyrm/tests/views/test_import.py | 15 ++--- bookwyrm/tests/views/test_interaction.py | 17 +++--- bookwyrm/tests/views/test_invite.py | 15 ++--- bookwyrm/tests/views/test_isbn.py | 17 +++--- bookwyrm/tests/views/test_landing.py | 15 ++--- bookwyrm/tests/views/test_list.py | 33 +++++------ bookwyrm/tests/views/test_list_actions.py | 33 +++++------ bookwyrm/tests/views/test_notifications.py | 16 +++--- bookwyrm/tests/views/test_outbox.py | 17 +++--- bookwyrm/tests/views/test_password.py | 15 ++--- bookwyrm/tests/views/test_reading.py | 17 +++--- bookwyrm/tests/views/test_readthrough.py | 7 ++- bookwyrm/tests/views/test_reports.py | 30 +++++----- bookwyrm/tests/views/test_rss_feed.py | 7 ++- bookwyrm/tests/views/test_search.py | 17 +++--- bookwyrm/tests/views/test_shelf.py | 17 +++--- bookwyrm/tests/views/test_status.py | 46 ++++++++------- bookwyrm/tests/views/test_updates.py | 15 ++--- bookwyrm/tests/views/test_user.py | 21 +++---- bookwyrm/tests/views/test_user_admin.py | 15 ++--- bookwyrm/tests/views/test_wellknown.py | 21 +++---- 45 files changed, 473 insertions(+), 393 deletions(-) diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py index b48b4e74a..d8a8f8657 100644 --- a/bookwyrm/suggested_users.py +++ b/bookwyrm/suggested_users.py @@ -148,9 +148,9 @@ def update_suggestions_on_follow(sender, instance, created, *args, **kwargs): # pylint: disable=unused-argument def update_suggestions_on_block(sender, instance, *args, **kwargs): """remove blocked users from recs""" - if instance.user_subject.local: + if instance.user_subject.local and instance.user_object.discoverable: remove_suggestion_task.delay(instance.user_subject.id, instance.user_object.id) - if instance.user_object.local: + if instance.user_object.local and instance.user_subject.discoverable: remove_suggestion_task.delay(instance.user_object.id, instance.user_subject.id) diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index c6f2176b3..504951c2f 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -31,9 +31,10 @@ class LibrarythingImport(TestCase): # Librarything generates latin encoded exports... self.csv = open(datafile, "r", encoding=self.importer.encoding) - self.user = models.User.objects.create_user( - "mmai", "mmai@mmai.mmai", "password", local=True - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.user = models.User.objects.create_user( + "mmai", "mmai@mmai.mmai", "password", local=True + ) models.Connector.objects.create( identifier=DOMAIN, @@ -197,7 +198,7 @@ class LibrarythingImport(TestCase): self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8)) @patch("bookwyrm.activitystreams.ActivityStream.add_status") - def test_handle_imported_book_review(self, _): + def test_handle_imported_book_review(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/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index ddbce7d35..ee7a96d7c 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -12,16 +12,17 @@ class Activitystreams(TestCase): def setUp(self): """we need some stuff""" - self.local_user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" - ) - self.another_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.nutria", - "password", - local=True, - localname="nutria", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" + ) + self.another_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.nutria", + "password", + local=True, + localname="nutria", + ) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 6d8fe270a..aea87e8d1 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -27,9 +27,10 @@ class ActivitypubMixins(TestCase): def setUp(self): """shared data""" - self.local_user = models.User.objects.create_user( - "mouse", "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", "mouse@mouse.com", "mouseword", local=True, localname="mouse" + ) self.local_user.remote_id = "http://example.com/a/b" self.local_user.save(broadcast=False) with patch("bookwyrm.models.user.set_remote_server.delay"): diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index e140887af..43cd5d3f4 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -13,9 +13,10 @@ class BaseModel(TestCase): def setUp(self): """shared data""" - self.local_user = models.User.objects.create_user( - "mouse", "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", "mouse@mouse.com", "mouseword", local=True, localname="mouse" + ) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index 76a914d1b..15a75a96e 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -59,9 +59,10 @@ class ImportJob(TestCase): unknown_read_data["Exclusive Shelf"] = "read" unknown_read_data["Date Read"] = "" - user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" + ) job = models.ImportJob.objects.create(user=user) self.item_1 = models.ImportItem.objects.create( job=job, index=1, data=currently_reading_data diff --git a/bookwyrm/tests/models/test_list.py b/bookwyrm/tests/models/test_list.py index 8f5bd4976..6e1ff8094 100644 --- a/bookwyrm/tests/models/test_list.py +++ b/bookwyrm/tests/models/test_list.py @@ -11,9 +11,10 @@ class List(TestCase): def setUp(self): """look, a list""" - self.local_user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" + ) work = models.Work.objects.create(title="hello") self.book = models.Edition.objects.create(title="hi", parent_work=work) diff --git a/bookwyrm/tests/models/test_readthrough_model.py b/bookwyrm/tests/models/test_readthrough_model.py index a8d74e54c..596753f79 100644 --- a/bookwyrm/tests/models/test_readthrough_model.py +++ b/bookwyrm/tests/models/test_readthrough_model.py @@ -1,4 +1,5 @@ """ testing models """ +from unittest.mock import patch from django.test import TestCase from django.core.exceptions import ValidationError @@ -10,9 +11,10 @@ class ReadThrough(TestCase): def setUp(self): """look, a shelf""" - self.user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" + ) self.work = models.Work.objects.create(title="Example Work") self.edition = models.Edition.objects.create( diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 911df059d..f6fd68509 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -7,18 +7,20 @@ from bookwyrm import models, settings # pylint: disable=unused-argument +@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class Shelf(TestCase): """some activitypub oddness ahead""" def setUp(self): """look, a shelf""" - self.local_user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" + ) 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( @@ -27,7 +29,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( @@ -41,7 +43,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: @@ -62,7 +64,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/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index 355caab9b..f8113549d 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -22,9 +22,10 @@ class Status(TestCase): def setUp(self): """useful things for creating a status""" - self.local_user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" + ) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index b2791379d..0868bc4bf 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -11,15 +11,16 @@ from bookwyrm.settings import DOMAIN # pylint: disable=missing-function-docstring class User(TestCase): def setUp(self): - self.user = models.User.objects.create_user( - "mouse@%s" % DOMAIN, - "mouse@mouse.mouse", - "mouseword", - local=True, - localname="mouse", - name="hi", - bookwyrm_user=False, - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.user = models.User.objects.create_user( + "mouse@%s" % DOMAIN, + "mouse@mouse.mouse", + "mouseword", + local=True, + localname="mouse", + name="hi", + bookwyrm_user=False, + ) def test_computed_fields(self): """username instead of id here""" diff --git a/bookwyrm/tests/views/test_announcements.py b/bookwyrm/tests/views/test_announcements.py index 8df6302cb..bd1371dee 100644 --- a/bookwyrm/tests/views/test_announcements.py +++ b/bookwyrm/tests/views/test_announcements.py @@ -12,13 +12,14 @@ class AnnouncementViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_authentication.py b/bookwyrm/tests/views/test_authentication.py index 22f3c20f4..10531f517 100644 --- a/bookwyrm/tests/views/test_authentication.py +++ b/bookwyrm/tests/views/test_authentication.py @@ -13,25 +13,27 @@ from bookwyrm.settings import DOMAIN # pylint: disable=too-many-public-methods +@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class AuthenticationViews(TestCase): """login and password management""" def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "password", + local=True, + localname="mouse", + ) self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False self.settings = models.SiteSettings.objects.create(id=1) - 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("") @@ -47,7 +49,7 @@ class AuthenticationViews(TestCase): self.assertEqual(result.url, "/") self.assertEqual(result.status_code, 302) - def test_register(self): + def test_register(self, _): """create a user""" view = views.Register.as_view() self.assertEqual(models.User.objects.count(), 1) @@ -68,7 +70,7 @@ class AuthenticationViews(TestCase): self.assertEqual(nutria.localname, "nutria-user.user_nutria") self.assertEqual(nutria.local, True) - 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( @@ -84,7 +86,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) @@ -95,7 +97,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) @@ -123,7 +125,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 @@ -135,7 +137,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 diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index 0169bbe8b..6157b6516 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -17,14 +17,15 @@ class AuthorViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) self.group = Group.objects.create(name="editor") self.group.permissions.add( Permission.objects.create( diff --git a/bookwyrm/tests/views/test_block.py b/bookwyrm/tests/views/test_block.py index c6fc9eb86..11283869b 100644 --- a/bookwyrm/tests/views/test_block.py +++ b/bookwyrm/tests/views/test_block.py @@ -14,13 +14,14 @@ class BlockViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) 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_book.py b/bookwyrm/tests/views/test_book.py index 73f2cad11..47e322297 100644 --- a/bookwyrm/tests/views/test_book.py +++ b/bookwyrm/tests/views/test_book.py @@ -23,14 +23,15 @@ class BookViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) self.group = Group.objects.create(name="editor") self.group.permissions.add( Permission.objects.create( diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index c2026cca3..bdda81013 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -1,4 +1,7 @@ """ 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 @@ -12,15 +15,25 @@ class DirectoryViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) - self.rat = models.User.objects.create_user( + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) + + models.SiteSettings.objects.create() + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + + @patch("bookwyrm.suggested_users.rerank_suggestions_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""" + models.User.objects.create_user( "rat@local.com", "rat@rat.com", "ratword", @@ -29,10 +42,16 @@ class DirectoryViews(TestCase): remote_id="https://example.com/users/rat", discoverable=True, ) + view = views.Directory.as_view() + request = self.factory.get("") + request.user = self.local_user - models.SiteSettings.objects.create() + result = view(request) + self.assertIsInstance(result, TemplateResponse) + result.render() + self.assertEqual(result.status_code, 200) - def test_directory_page(self): + def test_directory_page_empty(self): """there are so many views, this just makes sure it LOADS""" view = views.Directory.as_view() request = self.factory.get("") @@ -42,3 +61,12 @@ class DirectoryViews(TestCase): self.assertIsInstance(result, TemplateResponse) result.render() self.assertEqual(result.status_code, 200) + + def test_directory_page_logged_out(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Directory.as_view() + request = self.factory.get("") + request.user = self.anonymous_user + + result = view(request) + self.assertEqual(result.status_code, 302) diff --git a/bookwyrm/tests/views/test_edit_user.py b/bookwyrm/tests/views/test_edit_user.py index 7c0825b19..e9f90ad6b 100644 --- a/bookwyrm/tests/views/test_edit_user.py +++ b/bookwyrm/tests/views/test_edit_user.py @@ -21,16 +21,17 @@ class EditUserViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) - self.rat = models.User.objects.create_user( - "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) + 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") with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): diff --git a/bookwyrm/tests/views/test_federation.py b/bookwyrm/tests/views/test_federation.py index 6db65b785..2ada24c6c 100644 --- a/bookwyrm/tests/views/test_federation.py +++ b/bookwyrm/tests/views/test_federation.py @@ -15,13 +15,14 @@ class FederationViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) 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_feed.py b/bookwyrm/tests/views/test_feed.py index a6a3d9677..aad72b0c7 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -22,13 +22,14 @@ class FeedViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) self.book = models.Edition.objects.create( parent_work=models.Work.objects.create(title="hi"), title="Example Edition", diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index 45e60d3cb..122cf3c6a 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -10,20 +10,21 @@ from django.test.client import RequestFactory from bookwyrm import models, views -class BookViews(TestCase): - """books books books""" +class FollowViews(TestCase): + """follows""" def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) with patch("bookwyrm.models.user.set_remote_server"): self.remote_user = models.User.objects.create_user( "rat", @@ -66,15 +67,16 @@ class BookViews(TestCase): def test_handle_follow_local_manually_approves(self): """send a follow request""" - rat = models.User.objects.create_user( - "rat@local.com", - "rat@rat.com", - "ratword", - local=True, - localname="rat", - remote_id="https://example.com/users/rat", - manually_approves_followers=True, - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + rat = models.User.objects.create_user( + "rat@local.com", + "rat@rat.com", + "ratword", + local=True, + localname="rat", + remote_id="https://example.com/users/rat", + manually_approves_followers=True, + ) request = self.factory.post("", {"user": rat}) request.user = self.local_user self.assertEqual(models.UserFollowRequest.objects.count(), 0) @@ -89,14 +91,15 @@ class BookViews(TestCase): def test_handle_follow_local(self): """send a follow request""" - rat = models.User.objects.create_user( - "rat@local.com", - "rat@rat.com", - "ratword", - local=True, - localname="rat", - remote_id="https://example.com/users/rat", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + rat = models.User.objects.create_user( + "rat@local.com", + "rat@rat.com", + "ratword", + local=True, + localname="rat", + remote_id="https://example.com/users/rat", + ) request = self.factory.post("", {"user": rat}) request.user = self.local_user self.assertEqual(models.UserFollowRequest.objects.count(), 0) diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 1c55da086..c741415c8 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -13,13 +13,14 @@ class GetStartedViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) self.book = models.Edition.objects.create( parent_work=models.Work.objects.create(title="hi"), title="Example Edition", diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index 4e8f6ee23..ad615ba6e 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -16,22 +16,23 @@ class GoalViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) - self.rat = models.User.objects.create_user( - "rat@local.com", - "rat@rat.com", - "ratword", - local=True, - localname="rat", - remote_id="https://example.com/users/rat", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) + self.rat = models.User.objects.create_user( + "rat@local.com", + "rat@rat.com", + "ratword", + local=True, + localname="rat", + remote_id="https://example.com/users/rat", + ) self.book = models.Edition.objects.create( title="Example Edition", remote_id="https://example.com/book/1", diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index 874b913ec..bfa9d82ed 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -13,21 +13,23 @@ from bookwyrm.settings import USER_AGENT @patch("bookwyrm.activitystreams.ActivityStream.add_status") +@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class ViewsHelpers(TestCase): """viewing and creating statuses""" def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - discoverable=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + discoverable=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", @@ -53,12 +55,12 @@ class ViewsHelpers(TestCase): name="Test Shelf", identifier="test-shelf", user=self.local_user ) - def test_get_edition(self, _): + def test_get_edition(self, *_): """given an edition or a work, returns an edition""" self.assertEqual(views.helpers.get_edition(self.book.id), self.book) self.assertEqual(views.helpers.get_edition(self.work.id), self.book) - def test_get_user_from_username(self, _): + def test_get_user_from_username(self, *_): """works for either localname or username""" self.assertEqual( views.helpers.get_user_from_username(self.local_user, "mouse"), @@ -71,7 +73,7 @@ class ViewsHelpers(TestCase): with self.assertRaises(Http404): views.helpers.get_user_from_username(self.local_user, "mojfse@example.com") - def test_is_api_request(self, _): + def test_is_api_request(self, *_): """should it return html or json""" request = self.factory.get("/path") request.headers = {"Accept": "application/json"} @@ -85,12 +87,12 @@ class ViewsHelpers(TestCase): request.headers = {"Accept": "Praise"} self.assertFalse(views.helpers.is_api_request(request)) - def test_is_api_request_no_headers(self, _): + def test_is_api_request_no_headers(self, *_): """should it return html or json""" request = self.factory.get("/path") self.assertFalse(views.helpers.is_api_request(request)) - def test_is_bookwyrm_request(self, _): + def test_is_bookwyrm_request(self, *_): """checks if a request came from a bookwyrm instance""" request = self.factory.get("", {"q": "Test Book"}) self.assertFalse(views.helpers.is_bookwyrm_request(request)) @@ -105,7 +107,7 @@ class ViewsHelpers(TestCase): request = self.factory.get("", {"q": "Test Book"}, HTTP_USER_AGENT=USER_AGENT) self.assertTrue(views.helpers.is_bookwyrm_request(request)) - def test_existing_user(self, _): + def test_existing_user(self, *_): """simple database lookup by username""" result = views.helpers.handle_remote_webfinger("@mouse@local.com") self.assertEqual(result, self.local_user) @@ -117,7 +119,7 @@ class ViewsHelpers(TestCase): self.assertEqual(result, self.local_user) @responses.activate - def test_load_user(self, _): + def test_load_user(self, *_): """find a remote user using webfinger""" username = "mouse@example.com" wellknown = { @@ -147,7 +149,7 @@ class ViewsHelpers(TestCase): self.assertIsInstance(result, models.User) self.assertEqual(result.username, "mouse@example.com") - def test_user_on_blocked_server(self, _): + def test_user_on_blocked_server(self, *_): """find a remote user using webfinger""" models.FederatedServer.objects.create( server_name="example.com", status="blocked" @@ -156,7 +158,7 @@ class ViewsHelpers(TestCase): result = views.helpers.handle_remote_webfinger("@mouse@example.com") self.assertIsNone(result) - def test_handle_reading_status_to_read(self, _): + def test_handle_reading_status_to_read(self, *_): """posts shelve activities""" shelf = self.local_user.shelf_set.get(identifier="to-read") with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): @@ -168,7 +170,7 @@ class ViewsHelpers(TestCase): self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.content, "wants to read") - def test_handle_reading_status_reading(self, _): + def test_handle_reading_status_reading(self, *_): """posts shelve activities""" shelf = self.local_user.shelf_set.get(identifier="reading") with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): @@ -180,7 +182,7 @@ class ViewsHelpers(TestCase): self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.content, "started reading") - def test_handle_reading_status_read(self, _): + def test_handle_reading_status_read(self, *_): """posts shelve activities""" shelf = self.local_user.shelf_set.get(identifier="read") with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): @@ -192,7 +194,7 @@ class ViewsHelpers(TestCase): self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.content, "finished reading") - def test_handle_reading_status_other(self, _): + def test_handle_reading_status_other(self, *_): """posts shelve activities""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): views.helpers.handle_reading_status( @@ -200,7 +202,7 @@ class ViewsHelpers(TestCase): ) self.assertFalse(models.GeneratedNote.objects.exists()) - def test_get_annotated_users(self, _): + def test_get_annotated_users(self, *_): """list of people you might know""" user_1 = models.User.objects.create_user( "nutria@local.com", @@ -247,7 +249,7 @@ class ViewsHelpers(TestCase): self.assertEqual(remote_user_annotated.mutuals, 0) self.assertEqual(remote_user_annotated.shared_books, 0) - def test_get_annotated_users_counts(self, _): + def test_get_annotated_users_counts(self, *_): """correct counting for multiple shared attributed""" user_1 = models.User.objects.create_user( "nutria@local.com", diff --git a/bookwyrm/tests/views/test_import.py b/bookwyrm/tests/views/test_import.py index 22694623a..13c0ef5d2 100644 --- a/bookwyrm/tests/views/test_import.py +++ b/bookwyrm/tests/views/test_import.py @@ -14,13 +14,14 @@ class ImportViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) models.SiteSettings.objects.create() def test_import_page(self): diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 3867f57d5..d83fc1190 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -15,14 +15,15 @@ class InteractionViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) with patch("bookwyrm.models.user.set_remote_server"): self.remote_user = models.User.objects.create_user( "rat", diff --git a/bookwyrm/tests/views/test_invite.py b/bookwyrm/tests/views/test_invite.py index 7b5071b36..1eaf57c03 100644 --- a/bookwyrm/tests/views/test_invite.py +++ b/bookwyrm/tests/views/test_invite.py @@ -16,13 +16,14 @@ class InviteViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) models.SiteSettings.objects.create() def test_invite_page(self): diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index 2aedd3cea..7c413e8bf 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -16,14 +16,15 @@ class IsbnViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Test Book", diff --git a/bookwyrm/tests/views/test_landing.py b/bookwyrm/tests/views/test_landing.py index 864e48f7f..4690ed1b7 100644 --- a/bookwyrm/tests/views/test_landing.py +++ b/bookwyrm/tests/views/test_landing.py @@ -15,13 +15,14 @@ class LandingViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() diff --git a/bookwyrm/tests/views/test_list.py b/bookwyrm/tests/views/test_list.py index 399892e3c..988d8d4ad 100644 --- a/bookwyrm/tests/views/test_list.py +++ b/bookwyrm/tests/views/test_list.py @@ -17,22 +17,23 @@ class ListViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) - self.rat = models.User.objects.create_user( - "rat@local.com", - "rat@rat.com", - "ratword", - local=True, - localname="rat", - remote_id="https://example.com/users/rat", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) + self.rat = models.User.objects.create_user( + "rat@local.com", + "rat@rat.com", + "ratword", + local=True, + localname="rat", + remote_id="https://example.com/users/rat", + ) work = models.Work.objects.create(title="Work") self.book = models.Edition.objects.create( title="Example Edition", diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index a59867822..2339427c6 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -15,22 +15,23 @@ class ListActionViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) - self.rat = models.User.objects.create_user( - "rat@local.com", - "rat@rat.com", - "ratword", - local=True, - localname="rat", - remote_id="https://example.com/users/rat", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) + self.rat = models.User.objects.create_user( + "rat@local.com", + "rat@rat.com", + "ratword", + local=True, + localname="rat", + remote_id="https://example.com/users/rat", + ) work = models.Work.objects.create(title="Work") self.book = models.Edition.objects.create( diff --git a/bookwyrm/tests/views/test_notifications.py b/bookwyrm/tests/views/test_notifications.py index 182753f91..af6aac13e 100644 --- a/bookwyrm/tests/views/test_notifications.py +++ b/bookwyrm/tests/views/test_notifications.py @@ -1,4 +1,5 @@ """ test for app action functionality """ +from unittest.mock import patch from django.template.response import TemplateResponse from django.test import TestCase from django.test.client import RequestFactory @@ -13,13 +14,14 @@ class NotificationViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) models.SiteSettings.objects.create() def test_notifications_page(self): diff --git a/bookwyrm/tests/views/test_outbox.py b/bookwyrm/tests/views/test_outbox.py index f89258e5f..fe493bb87 100644 --- a/bookwyrm/tests/views/test_outbox.py +++ b/bookwyrm/tests/views/test_outbox.py @@ -18,14 +18,15 @@ class OutboxView(TestCase): def setUp(self): """we'll need some data""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Example Edition", diff --git a/bookwyrm/tests/views/test_password.py b/bookwyrm/tests/views/test_password.py index ec686db74..5f59e9e32 100644 --- a/bookwyrm/tests/views/test_password.py +++ b/bookwyrm/tests/views/test_password.py @@ -15,13 +15,14 @@ class PasswordViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "password", + local=True, + localname="mouse", + ) self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create(id=1) diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 00bd62c73..ab1fc70a5 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -15,14 +15,15 @@ class ReadingViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) 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_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index 764490d89..ae87ebdc7 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -21,9 +21,10 @@ class ReadThrough(TestCase): title="Example Edition", parent_work=self.work ) - self.user = models.User.objects.create_user( - "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.user = models.User.objects.create_user( + "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" + ) with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): self.client.force_login(self.user) diff --git a/bookwyrm/tests/views/test_reports.py b/bookwyrm/tests/views/test_reports.py index 84539489d..bb32bcb1e 100644 --- a/bookwyrm/tests/views/test_reports.py +++ b/bookwyrm/tests/views/test_reports.py @@ -1,4 +1,5 @@ """ test for app action functionality """ +from unittest.mock import patch from django.template.response import TemplateResponse from django.test import TestCase from django.test.client import RequestFactory @@ -12,20 +13,21 @@ class ReportViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) - self.rat = models.User.objects.create_user( - "rat@local.com", - "rat@mouse.mouse", - "password", - local=True, - localname="rat", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) + self.rat = models.User.objects.create_user( + "rat@local.com", + "rat@mouse.mouse", + "password", + local=True, + localname="rat", + ) models.SiteSettings.objects.create() def test_reports_page(self): diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index eacb3c936..3608b043a 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -14,9 +14,10 @@ class RssFeedView(TestCase): """test data""" self.site = models.SiteSettings.objects.create() - self.user = models.User.objects.create_user( - "rss_user", "rss@test.rss", "password", local=True - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.user = models.User.objects.create_user( + "rss_user", "rss@test.rss", "password", local=True + ) work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( diff --git a/bookwyrm/tests/views/test_search.py b/bookwyrm/tests/views/test_search.py index ab2c910d4..3da6f866b 100644 --- a/bookwyrm/tests/views/test_search.py +++ b/bookwyrm/tests/views/test_search.py @@ -19,14 +19,15 @@ class Views(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Test Book", diff --git a/bookwyrm/tests/views/test_shelf.py b/bookwyrm/tests/views/test_shelf.py index 239b3318f..ccba4c73f 100644 --- a/bookwyrm/tests/views/test_shelf.py +++ b/bookwyrm/tests/views/test_shelf.py @@ -16,14 +16,15 @@ class ShelfViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) self.work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Example Edition", diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index a20e98b92..2049963cb 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -10,20 +10,22 @@ from bookwyrm.settings import DOMAIN # pylint: disable=invalid-name @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") +@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") class StatusViews(TestCase): """viewing and creating statuses""" def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.com", - "mouseword", - local=True, - localname="mouse", - remote_id="https://example.com/users/mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.com", + "mouseword", + local=True, + localname="mouse", + remote_id="https://example.com/users/mouse", + ) with patch("bookwyrm.models.user.set_remote_server"): self.remote_user = models.User.objects.create_user( "rat", @@ -43,7 +45,7 @@ class StatusViews(TestCase): ) models.SiteSettings.objects.create() - def test_handle_status(self, _): + def test_handle_status(self, *_): """create a status""" view = views.CreateStatus.as_view() form = forms.CommentForm( @@ -66,7 +68,7 @@ class StatusViews(TestCase): self.assertEqual(status.user, self.local_user) self.assertEqual(status.book, self.book) - def test_handle_status_reply(self, _): + def test_handle_status_reply(self, *_): """create a status in reply to an existing status""" view = views.CreateStatus.as_view() user = models.User.objects.create_user( @@ -96,7 +98,7 @@ class StatusViews(TestCase): self.assertEqual(status.user, user) self.assertEqual(models.Notification.objects.get().user, self.local_user) - def test_handle_status_mentions(self, _): + def test_handle_status_mentions(self, *_): """@mention a user in a post""" view = views.CreateStatus.as_view() user = models.User.objects.create_user( @@ -128,7 +130,7 @@ class StatusViews(TestCase): status.content, '

hi @rat

' % user.remote_id ) - def test_handle_status_reply_with_mentions(self, _): + def test_handle_status_reply_with_mentions(self, *_): """reply to a post with an @mention'ed user""" view = views.CreateStatus.as_view() user = models.User.objects.create_user( @@ -172,7 +174,7 @@ class StatusViews(TestCase): self.assertFalse(self.remote_user in reply.mention_users.all()) self.assertTrue(self.local_user in reply.mention_users.all()) - def test_delete_and_redraft(self, _): + def test_delete_and_redraft(self, *_): """delete and re-draft a status""" view = views.DeleteAndRedraft.as_view() request = self.factory.post("") @@ -193,7 +195,7 @@ class StatusViews(TestCase): status.refresh_from_db() self.assertTrue(status.deleted) - def test_delete_and_redraft_invalid_status_type_rating(self, _): + def test_delete_and_redraft_invalid_status_type_rating(self, *_): """you can't redraft generated statuses""" view = views.DeleteAndRedraft.as_view() request = self.factory.post("") @@ -213,7 +215,7 @@ class StatusViews(TestCase): status.refresh_from_db() self.assertFalse(status.deleted) - def test_delete_and_redraft_invalid_status_type_generated_note(self, _): + def test_delete_and_redraft_invalid_status_type_generated_note(self, *_): """you can't redraft generated statuses""" view = views.DeleteAndRedraft.as_view() request = self.factory.post("") @@ -233,7 +235,7 @@ class StatusViews(TestCase): status.refresh_from_db() self.assertFalse(status.deleted) - def test_find_mentions(self, _): + def test_find_mentions(self, *_): """detect and look up @ mentions of users""" user = models.User.objects.create_user( "nutria@%s" % DOMAIN, @@ -279,7 +281,7 @@ class StatusViews(TestCase): ("@nutria@%s" % DOMAIN, user), ) - def test_format_links(self, _): + def test_format_links(self, *_): """find and format urls into a tags""" url = "http://www.fish.com/" self.assertEqual( @@ -302,7 +304,7 @@ class StatusViews(TestCase): "?q=arkady+strugatsky&mode=everything" % url, ) - def test_to_markdown(self, _): + def test_to_markdown(self, *_): """this is mostly handled in other places, but nonetheless""" text = "_hi_ and http://fish.com is rad" result = views.status.to_markdown(text) @@ -311,7 +313,7 @@ class StatusViews(TestCase): '

hi and fish.com ' "is rad

", ) - def test_to_markdown_detect_url(self, _): + def test_to_markdown_detect_url(self, *_): """this is mostly handled in other places, but nonetheless""" text = "http://fish.com/@hello#okay" result = views.status.to_markdown(text) @@ -320,7 +322,7 @@ class StatusViews(TestCase): '

fish.com/@hello#okay

', ) - def test_to_markdown_link(self, _): + def test_to_markdown_link(self, *_): """this is mostly handled in other places, but nonetheless""" text = "[hi](http://fish.com) is rad" result = views.status.to_markdown(text) @@ -346,7 +348,7 @@ class StatusViews(TestCase): status.refresh_from_db() self.assertTrue(status.deleted) - def test_handle_delete_status_permission_denied(self, _): + 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"): @@ -360,7 +362,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.ActivityStream.add_status"): diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index fb003f8de..627b756e7 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -15,13 +15,14 @@ class UpdateViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) models.SiteSettings.objects.create() def test_get_notification_count(self): diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 478d2e8f4..5e3680d2a 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -17,16 +17,17 @@ class UserViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) - self.rat = models.User.objects.create_user( - "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) + 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") with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): models.ShelfBook.objects.create( diff --git a/bookwyrm/tests/views/test_user_admin.py b/bookwyrm/tests/views/test_user_admin.py index a044a22c5..42f2d7e82 100644 --- a/bookwyrm/tests/views/test_user_admin.py +++ b/bookwyrm/tests/views/test_user_admin.py @@ -14,13 +14,14 @@ class UserAdminViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) models.SiteSettings.objects.create() def test_user_admin_list_page(self): diff --git a/bookwyrm/tests/views/test_wellknown.py b/bookwyrm/tests/views/test_wellknown.py index 244921d47..4a3eb579f 100644 --- a/bookwyrm/tests/views/test_wellknown.py +++ b/bookwyrm/tests/views/test_wellknown.py @@ -16,16 +16,17 @@ class UserViews(TestCase): def setUp(self): """we need basic test data and mocks""" self.factory = RequestFactory() - self.local_user = models.User.objects.create_user( - "mouse@local.com", - "mouse@mouse.mouse", - "password", - local=True, - localname="mouse", - ) - models.User.objects.create_user( - "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse@local.com", + "mouse@mouse.mouse", + "password", + local=True, + localname="mouse", + ) + models.User.objects.create_user( + "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" + ) with patch("bookwyrm.models.user.set_remote_server.delay"): models.User.objects.create_user( "rat",