From df43a8e2c52e16ba4dd63c74bd447a36f2ad5cf6 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 30 Oct 2023 19:43:39 +1100 Subject: [PATCH 01/17] Use django-file-resubmit plugin - save cover images to cache when checking author and work for existing records - fixes #2760 --- bookwyrm/forms/books.py | 5 ++--- bookwyrm/settings.py | 7 ++++++- requirements.txt | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index 4885dc063..e28c19d79 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -3,6 +3,7 @@ from django import forms from bookwyrm import models from bookwyrm.models.fields import ClearableFileInputWithWarning +from file_resubmit.admin import AdminResubmitImageWidget from .custom_form import CustomForm from .widgets import ArrayWidget, SelectDateWidget, Select @@ -70,9 +71,7 @@ class EditionForm(CustomForm): "published_date": SelectDateWidget( attrs={"aria-describedby": "desc_published_date"} ), - "cover": ClearableFileInputWithWarning( - attrs={"aria-describedby": "desc_cover"} - ), + "cover": AdminResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}), "physical_format": Select( attrs={"aria-describedby": "desc_physical_format"} ), diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 16241f9df..8c1841e2e 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -99,6 +99,7 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "django.contrib.humanize", + "file_resubmit", "sass_processor", "bookwyrm", "celery", @@ -252,7 +253,11 @@ else: "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", }, - } + }, + "file_resubmit": { + "BACKEND": "django.core.cache.backends.filebased.FileBasedCache", + "LOCATION": "/tmp/file_resubmit/", + }, } SESSION_ENGINE = "django.contrib.sessions.backends.cache" diff --git a/requirements.txt b/requirements.txt index 0602f8da4..f63989e1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ celery==5.2.7 colorthief==0.2.1 Django==3.2.20 django-celery-beat==2.4.0 +django-file-resubmit==0.5.2 django-compressor==4.3.1 django-imagekit==4.1.0 django-model-utils==4.3.1 From c486b9c37e5fefd61272c1039b28e2cdae4191e2 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 30 Oct 2023 21:47:19 +1100 Subject: [PATCH 02/17] pylint fixes --- bookwyrm/forms/books.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index e28c19d79..c65a6aaf7 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -1,9 +1,9 @@ """ using django model forms """ from django import forms -from bookwyrm import models -from bookwyrm.models.fields import ClearableFileInputWithWarning from file_resubmit.admin import AdminResubmitImageWidget + +from bookwyrm import models from .custom_form import CustomForm from .widgets import ArrayWidget, SelectDateWidget, Select From d682e55812e04b475271e8036a588cb8df4b9d25 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 5 Nov 2023 16:34:24 +1100 Subject: [PATCH 03/17] swap out django-file-resubmit - we decided to fork it, so this now uses the inaugural RC release of bw-file-resubmit (will need to be adjusted once we're confident it's ok to push a full release) - I was accidentally using the wrong widget lol --- bookwyrm/forms/books.py | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index c65a6aaf7..f73ce3f5a 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -1,7 +1,7 @@ """ using django model forms """ from django import forms -from file_resubmit.admin import AdminResubmitImageWidget +from file_resubmit.widgets import ResubmitImageWidget from bookwyrm import models from .custom_form import CustomForm @@ -71,7 +71,7 @@ class EditionForm(CustomForm): "published_date": SelectDateWidget( attrs={"aria-describedby": "desc_published_date"} ), - "cover": AdminResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}), + "cover": ResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}), "physical_format": Select( attrs={"aria-describedby": "desc_physical_format"} ), diff --git a/requirements.txt b/requirements.txt index f63989e1f..cda7b1967 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ celery==5.2.7 colorthief==0.2.1 Django==3.2.20 django-celery-beat==2.4.0 -django-file-resubmit==0.5.2 +bw-file-resubmit==0.6.0rc2 django-compressor==4.3.1 django-imagekit==4.1.0 django-model-utils==4.3.1 From f3fc5f6179bb81496f9c23e5a3bb9ddf11642720 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 11 Nov 2023 12:45:04 +1100 Subject: [PATCH 04/17] add file_resubmit to DUMMY caches settings --- bookwyrm/settings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 8c1841e2e..cb5a576a2 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -243,7 +243,11 @@ if env.bool("USE_DUMMY_CACHE", False): CACHES = { "default": { "BACKEND": "django.core.cache.backends.dummy.DummyCache", - } + }, + "file_resubmit": { + "BACKEND": "django.core.cache.backends.dummy.DummyCache", + "LOCATION": "/tmp/file_resubmit_tests/", + }, } else: CACHES = { From a7fcd898c218442820566cf916876a1eeda654a3 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 18 Nov 2023 22:10:36 +1100 Subject: [PATCH 05/17] middleware for displaying 413 page When a RequestDataTooBig exception is thrown, users are largely in the dark about what happened and how it can be fixed. This commit resolves this by inserting middleware to redirect the request to a custom 413 error page. This exception is thrown when DATA_UPLOAD_MAX_MEMORY_SIZE is exceeded. The default value is 2.5MB. Fixes #2340 Fixes #2633 --- bookwyrm/middleware/__init__.py | 1 + bookwyrm/middleware/file_too_big.py | 30 +++++++++++++++++++++++++++++ bookwyrm/settings.py | 1 + bookwyrm/templates/413.html | 16 +++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 bookwyrm/middleware/file_too_big.py create mode 100644 bookwyrm/templates/413.html diff --git a/bookwyrm/middleware/__init__.py b/bookwyrm/middleware/__init__.py index 03843c5a3..85c3a56fe 100644 --- a/bookwyrm/middleware/__init__.py +++ b/bookwyrm/middleware/__init__.py @@ -1,3 +1,4 @@ """ look at all this nice middleware! """ from .timezone_middleware import TimezoneMiddleware from .ip_middleware import IPBlocklistMiddleware +from .file_too_big import FileTooBig diff --git a/bookwyrm/middleware/file_too_big.py b/bookwyrm/middleware/file_too_big.py new file mode 100644 index 000000000..de1349d96 --- /dev/null +++ b/bookwyrm/middleware/file_too_big.py @@ -0,0 +1,30 @@ +"""Middleware to display a custom 413 error page""" + +from django.http import HttpResponse +from django.shortcuts import render +from django.core.exceptions import RequestDataTooBig + + +class FileTooBig: + """Middleware to display a custom page when a + RequestDataTooBig exception is thrown""" + + def __init__(self, get_response): + """boilerplate __init__ from Django docs""" + + self.get_response = get_response + + def __call__(self, request): + """If RequestDataTooBig is thrown, render the 413 error page""" + + try: + body = request.body # pylint: disable=unused-variable + + except RequestDataTooBig: + + rendered = render(request, "413.html") + response = HttpResponse(rendered) + return response + + response = self.get_response(request) + return response diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 4cecc4df6..e3730acf8 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -119,6 +119,7 @@ MIDDLEWARE = [ "bookwyrm.middleware.IPBlocklistMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "bookwyrm.middleware.FileTooBig", ] ROOT_URLCONF = "bookwyrm.urls" diff --git a/bookwyrm/templates/413.html b/bookwyrm/templates/413.html new file mode 100644 index 000000000..337436aae --- /dev/null +++ b/bookwyrm/templates/413.html @@ -0,0 +1,16 @@ +{% extends 'layout.html' %} +{% load i18n %} + +{% block title %}{% trans "File too large" %}{% endblock %} + +{% block content %} +
+

{% trans "File too large" %}

+

{% trans "The file you are uploading is too large." %}

+

+ {% blocktrans %} + You you can try using a smaller file, or ask your BookWyrm server administrator to increase the DATA_UPLOAD_MAX_MEMORY_SIZE setting. + {% endblocktrans %} +

+
+{% endblock %} From 2ba0e3d7ff786fac6d52005a7c725bae33093dd7 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 19 Nov 2023 20:03:48 +1100 Subject: [PATCH 06/17] Allow removing followers and fix follow rejections * adds the ability to remove a user from your followers list * fixes verbs.Reject to process reject activities for previously accepted follows in both directions fixes #2635 --- bookwyrm/activitypub/verbs.py | 32 +++++++++++++++++-- bookwyrm/models/relationship.py | 28 ++++++++++++---- bookwyrm/static/js/bookwyrm.js | 32 +++++++++++++------ .../templates/snippets/follow_button.html | 12 ++++++- .../user/relationships/followers.html | 5 +++ .../templates/user/relationships/layout.html | 2 +- bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 1 + bookwyrm/views/follow.py | 28 ++++++++++++++++ 9 files changed, 120 insertions(+), 21 deletions(-) diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index 00c9524fe..2753104b2 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -171,8 +171,36 @@ class Reject(Verb): type: str = "Reject" def action(self, allow_external_connections=True): - """reject a follow request""" - obj = self.object.to_model(save=False, allow_create=False) + """reject a follow or follow request""" + + if self.object.type == "Follow": + model = apps.get_model("bookwyrm.UserFollowRequest") + obj = self.object.to_model( + model=model, + save=False, + allow_create=False, + allow_external_connections=allow_external_connections, + ) + if not obj: + # This is a deletion (soft-block) of an accepted follow + model = apps.get_model("bookwyrm.UserFollows") + obj = self.object.to_model( + model=model, + save=False, + allow_create=False, + allow_external_connections=allow_external_connections, + ) + else: + # it's something else + obj = self.object.to_model( + model=model, + save=False, + allow_create=False, + allow_external_connections=allow_external_connections, + ) + if not obj: + # if we don't have the object, we can't reject it. + return obj.reject() diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index 7af6ad5ab..3386a02dc 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -65,6 +65,13 @@ class UserRelationship(BookWyrmModel): base_path = self.user_subject.remote_id return f"{base_path}#follows/{self.id}" + def get_accept_reject_id(self, status): + """get id for sending an accept or reject of a local user""" + + base_path = self.user_object.remote_id + status_id = self.id or 0 + return f"{base_path}#{status}/{status_id}" + class UserFollows(ActivityMixin, UserRelationship): """Following a user""" @@ -105,6 +112,20 @@ class UserFollows(ActivityMixin, UserRelationship): ) return obj + def reject(self): + """generate a Reject for this follow. This would normally happen + when a user deletes a follow they previously accepted""" + + if self.user_object.local: + activity = activitypub.Reject( + id=self.get_accept_reject_id(status="rejects"), + actor=self.user_object.remote_id, + object=self.to_activity(), + ).serialize() + self.broadcast(activity, self.user_object) + + self.delete() + class UserFollowRequest(ActivitypubMixin, UserRelationship): """following a user requires manual or automatic confirmation""" @@ -148,13 +169,6 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship): if not manually_approves: self.accept() - def get_accept_reject_id(self, status): - """get id for sending an accept or reject of a local user""" - - base_path = self.user_object.remote_id - status_id = self.id or 0 - return f"{base_path}#{status}/{status_id}" - def accept(self, broadcast_only=False): """turn this request into the real deal""" user = self.user_object diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index a2351a98c..7093219e5 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -330,18 +330,30 @@ let BookWyrm = new (class { const bookwyrm = this; const form = event.currentTarget; + const formAction = event.submitter.getAttribute("formaction") || form.action; const relatedforms = document.querySelectorAll(`.${form.dataset.id}`); // Toggle class on all related forms. - relatedforms.forEach((relatedForm) => - bookwyrm.addRemoveClass( - relatedForm, - "is-hidden", - relatedForm.className.indexOf("is-hidden") == -1 - ) - ); + if (formAction == "/remove-follow") { + // Remove ALL follow/unfollow/remote buttons + relatedforms.forEach((relatedForm) => relatedForm.classList.add("is-hidden")); - this.ajaxPost(form).catch((error) => { + // Remove orphaned user-options dropdown + const parent = form.parentElement; + const next = parent.nextElementSibling; + + next.classList.add("is-hidden"); + } else { + relatedforms.forEach((relatedForm) => + bookwyrm.addRemoveClass( + relatedForm, + "is-hidden", + relatedForm.className.indexOf("is-hidden") == -1 + ) + ); + } + + this.ajaxPost(formAction, form).catch((error) => { // @todo Display a notification in the UI instead. console.warn("Request failed:", error); }); @@ -353,8 +365,8 @@ let BookWyrm = new (class { * @param {object} form - Form to be submitted * @return {Promise} */ - ajaxPost(form) { - return fetch(form.action, { + ajaxPost(target, form) { + return fetch(target, { method: "POST", body: new FormData(form), headers: { diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index 2bde47f58..5c0839065 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -12,6 +12,7 @@
+ {% if not followers_page %} -
{% endfor %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 8541f4fb6..ab1dca378 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -763,6 +763,7 @@ urlpatterns = [ # following re_path(r"^follow/?$", views.follow, name="follow"), re_path(r"^unfollow/?$", views.unfollow, name="unfollow"), + re_path(r"^remove-follow/?$", views.remove_follow, name="remove-follow"), re_path(r"^accept-follow-request/?$", views.accept_follow_request), re_path(r"^delete-follow-request/?$", views.delete_follow_request), re_path(r"^ostatus_follow/?$", views.remote_follow, name="remote-follow"), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 2d2e97f52..0d7af9d68 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -113,6 +113,7 @@ from .feed import DirectMessage, Feed, Replies, Status from .follow import ( follow, unfollow, + remove_follow, ostatus_follow_request, ostatus_follow_success, remote_follow, diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 0090cbe32..f9a09e2c9 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -69,6 +69,34 @@ def unfollow(request): return redirect("/") +@login_required +@require_POST +def remove_follow(request): + """remove a previously approved follower without blocking them""" + + username = request.POST["user"] + to_remove = get_user_from_username(request.user, username) + + try: + models.UserFollows.objects.get( + user_subject=to_remove, user_object=request.user + ).reject() + except models.UserFollows.DoesNotExist: + clear_cache(to_remove, request.user) + + try: + models.UserFollowRequest.objects.get( + user_subject=to_remove, user_object=request.user + ).reject() + except models.UserFollowRequest.DoesNotExist: + clear_cache(to_remove, request.user) + + if is_api_request(request): + return HttpResponse() + # this is handled with ajax so it shouldn't really matter + return redirect("/") + + @login_required @require_POST def accept_follow_request(request): From 2c9ebba5d72adf4fef99291fc07ebe13cb1b36f4 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 21 Nov 2023 20:13:56 +1100 Subject: [PATCH 07/17] fix reject PR - rationalise activitypub.Reject and fix model being undefined - fix not being able to follow users from followers page: 'delete' option now in user_options dropdown - revert bookwyrm.js - fix delete_follow_request deleting instead of rejecting - add user id to 'remove-follow' path --- bookwyrm/activitypub/verbs.py | 32 ++++-------------- bookwyrm/static/js/bookwyrm.js | 33 ++++++------------- .../templates/snippets/follow_button.html | 14 ++------ .../snippets/remove_follower_button.html | 5 +++ bookwyrm/templates/snippets/user_options.html | 5 +++ bookwyrm/tests/views/test_follow.py | 12 +++++++ bookwyrm/urls.py | 4 ++- bookwyrm/views/follow.py | 11 +++---- 8 files changed, 49 insertions(+), 67 deletions(-) create mode 100644 bookwyrm/templates/snippets/remove_follower_button.html diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index 2753104b2..a365f4cc0 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -173,35 +173,17 @@ class Reject(Verb): def action(self, allow_external_connections=True): """reject a follow or follow request""" - if self.object.type == "Follow": - model = apps.get_model("bookwyrm.UserFollowRequest") - obj = self.object.to_model( + for model_name in ["UserFollowRequest", "UserFollows", None]: + model = apps.get_model(f"bookwyrm.{model_name}") if model_name else None + if obj := self.object.to_model( model=model, save=False, allow_create=False, allow_external_connections=allow_external_connections, - ) - if not obj: - # This is a deletion (soft-block) of an accepted follow - model = apps.get_model("bookwyrm.UserFollows") - obj = self.object.to_model( - model=model, - save=False, - allow_create=False, - allow_external_connections=allow_external_connections, - ) - else: - # it's something else - obj = self.object.to_model( - model=model, - save=False, - allow_create=False, - allow_external_connections=allow_external_connections, - ) - if not obj: - # if we don't have the object, we can't reject it. - return - obj.reject() + ): + # Reject the first model that can be built. + obj.reject() + break @dataclass(init=False) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 7093219e5..dcde9cc72 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -330,30 +330,17 @@ let BookWyrm = new (class { const bookwyrm = this; const form = event.currentTarget; - const formAction = event.submitter.getAttribute("formaction") || form.action; const relatedforms = document.querySelectorAll(`.${form.dataset.id}`); - // Toggle class on all related forms. - if (formAction == "/remove-follow") { - // Remove ALL follow/unfollow/remote buttons - relatedforms.forEach((relatedForm) => relatedForm.classList.add("is-hidden")); + relatedforms.forEach((relatedForm) => + bookwyrm.addRemoveClass( + relatedForm, + "is-hidden", + relatedForm.className.indexOf("is-hidden") == -1 + ) + ); - // Remove orphaned user-options dropdown - const parent = form.parentElement; - const next = parent.nextElementSibling; - - next.classList.add("is-hidden"); - } else { - relatedforms.forEach((relatedForm) => - bookwyrm.addRemoveClass( - relatedForm, - "is-hidden", - relatedForm.className.indexOf("is-hidden") == -1 - ) - ); - } - - this.ajaxPost(formAction, form).catch((error) => { + this.ajaxPost(form).catch((error) => { // @todo Display a notification in the UI instead. console.warn("Request failed:", error); }); @@ -365,8 +352,8 @@ let BookWyrm = new (class { * @param {object} form - Form to be submitted * @return {Promise} */ - ajaxPost(target, form) { - return fetch(target, { + ajaxPost(form) { + return fetch(form.action, { method: "POST", body: new FormData(form), headers: { diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index 5c0839065..28b979987 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -12,7 +12,6 @@
- {% if not followers_page %} {% csrf_token %} @@ -24,22 +23,13 @@ {% endif %} - {% endif %} -
{% if not minimal %}
- {% include 'snippets/user_options.html' with user=user class="is-small" %} + {% include 'snippets/user_options.html' with user=user followers_page=followers_page class="is-small" %}
{% endif %}
diff --git a/bookwyrm/templates/snippets/remove_follower_button.html b/bookwyrm/templates/snippets/remove_follower_button.html new file mode 100644 index 000000000..28bef6842 --- /dev/null +++ b/bookwyrm/templates/snippets/remove_follower_button.html @@ -0,0 +1,5 @@ +{% load i18n %} + + {% csrf_token %} + + diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html index 35abc98c2..ab028a494 100644 --- a/bookwyrm/templates/snippets/user_options.html +++ b/bookwyrm/templates/snippets/user_options.html @@ -20,4 +20,9 @@
  • {% include 'snippets/block_button.html' with user=user class="is-fullwidth" blocks=False %}
  • +{% if followers_page %} +
  • + {% include 'snippets/remove_follower_button.html' with user=user class="is-fullwidth" blocks=False %} +
  • +{% endif %} {% endblock %} diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index d18e24f89..8d73a666c 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -180,6 +180,18 @@ class FollowViews(TestCase): # follow relationship should not exist self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0) + def test_handle_reject_existing(self, *_): + """reject a follow previously approved""" + request = self.factory.post("", {"user": self.remote_user.username}) + request.user = self.local_user + rel = models.UserFollows.objects.create( + user_subject=self.remote_user, user_object=self.local_user + ) + with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): + views.remove_follow(request, self.remote_user.id) + # follow relationship should not exist + self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0) + def test_ostatus_follow_request(self, *_): """check ostatus subscribe template loads""" request = self.factory.get( diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index ab1dca378..41eff3b8c 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -763,7 +763,9 @@ urlpatterns = [ # following re_path(r"^follow/?$", views.follow, name="follow"), re_path(r"^unfollow/?$", views.unfollow, name="unfollow"), - re_path(r"^remove-follow/?$", views.remove_follow, name="remove-follow"), + re_path( + r"^remove-follow/(?P\d+)/?$", views.remove_follow, name="remove-follow" + ), re_path(r"^accept-follow-request/?$", views.accept_follow_request), re_path(r"^delete-follow-request/?$", views.delete_follow_request), re_path(r"^ostatus_follow/?$", views.remote_follow, name="remote-follow"), diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index f9a09e2c9..dcb1c695c 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -71,11 +71,10 @@ def unfollow(request): @login_required @require_POST -def remove_follow(request): +def remove_follow(request, user_id): """remove a previously approved follower without blocking them""" - username = request.POST["user"] - to_remove = get_user_from_username(request.user, username) + to_remove = get_object_or_404(models.User, id=user_id) try: models.UserFollows.objects.get( @@ -93,8 +92,8 @@ def remove_follow(request): if is_api_request(request): return HttpResponse() - # this is handled with ajax so it shouldn't really matter - return redirect("/") + + return redirect(f"{request.user.local_path}/followers") @login_required @@ -128,7 +127,7 @@ def delete_follow_request(request): ) follow_request.raise_not_deletable(request.user) - follow_request.delete() + follow_request.reject() return redirect(f"/user/{request.user.localname}") From 8ed4a997f8f81a4a5be020151fba7f741c8a0b3a Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 21 Nov 2023 20:20:11 +1100 Subject: [PATCH 08/17] add comment back to bookwyrm.js --- bookwyrm/static/js/bookwyrm.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index dcde9cc72..a2351a98c 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -332,6 +332,7 @@ let BookWyrm = new (class { const form = event.currentTarget; const relatedforms = document.querySelectorAll(`.${form.dataset.id}`); + // Toggle class on all related forms. relatedforms.forEach((relatedForm) => bookwyrm.addRemoveClass( relatedForm, From 6ba74181214e253924f022b2e537e7772eaadfe1 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 22 Nov 2023 20:04:17 +1100 Subject: [PATCH 09/17] improve tests and minor cleanup --- bookwyrm/templates/snippets/user_options.html | 2 +- bookwyrm/tests/views/test_follow.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html index ab028a494..0e15e413a 100644 --- a/bookwyrm/templates/snippets/user_options.html +++ b/bookwyrm/templates/snippets/user_options.html @@ -22,7 +22,7 @@ {% if followers_page %}
  • - {% include 'snippets/remove_follower_button.html' with user=user class="is-fullwidth" blocks=False %} + {% include 'snippets/remove_follower_button.html' with user=user class="is-fullwidth" %}
  • {% endif %} {% endblock %} diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index 8d73a666c..d88a42210 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -173,8 +173,15 @@ class FollowViews(TestCase): user_subject=self.remote_user, user_object=self.local_user ) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): + with patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ) as broadcast_mock: views.delete_follow_request(request) + # did we send the reject activity? + activity = json.loads(broadcast_mock.call_args[1]["args"][1]) + self.assertEqual(activity["actor"], self.local_user.remote_id) + self.assertEqual(activity["object"]["object"], rel.user_object.remote_id) + self.assertEqual(activity["type"], "Reject") # request should be deleted self.assertEqual(models.UserFollowRequest.objects.filter(id=rel.id).count(), 0) # follow relationship should not exist @@ -187,8 +194,15 @@ class FollowViews(TestCase): rel = models.UserFollows.objects.create( user_subject=self.remote_user, user_object=self.local_user ) - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): + with patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ) as broadcast_mock: views.remove_follow(request, self.remote_user.id) + # did we send the reject activity? + activity = json.loads(broadcast_mock.call_args[1]["args"][1]) + self.assertEqual(activity["actor"], self.local_user.remote_id) + self.assertEqual(activity["object"]["object"], rel.user_object.remote_id) + self.assertEqual(activity["type"], "Reject") # follow relationship should not exist self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0) From e322d3cae1720504814b2fa6afd39fdab0390d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Thu, 23 Nov 2023 17:05:18 -0300 Subject: [PATCH 10/17] Do not create a set for already-distinct query result --- bookwyrm/book_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/book_search.py b/bookwyrm/book_search.py index ceb228f40..3012482fd 100644 --- a/bookwyrm/book_search.py +++ b/bookwyrm/book_search.py @@ -137,7 +137,7 @@ def search_title_author( # filter out multiple editions of the same work list_results = [] - for work_id in set(editions_of_work[:30]): + for work_id in editions_of_work[:30]: result = ( results.filter(parent_work=work_id) .order_by("-rank", "-edition_rank") From c997d2d44aebd258ba4f45975f16b1940a799199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Fri, 24 Nov 2023 02:18:18 -0300 Subject: [PATCH 11/17] Add test to assert distinct() clause Also, tweak other `search_title_author()` tests to verify ordering by edition rank. --- bookwyrm/tests/test_book_search.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bookwyrm/tests/test_book_search.py b/bookwyrm/tests/test_book_search.py index db6ba8353..ad954f585 100644 --- a/bookwyrm/tests/test_book_search.py +++ b/bookwyrm/tests/test_book_search.py @@ -26,10 +26,10 @@ class BookSearch(TestCase): parent_work=self.work, isbn_10="1111111111", openlibrary_key="hello", + pages=150, ) - self.third_edition = models.Edition.objects.create( - title="Edition with annoying ISBN", + title="Another Edition with annoying ISBN", parent_work=self.work, isbn_10="022222222X", ) @@ -76,16 +76,21 @@ class BookSearch(TestCase): def test_search_title_author(self): """search by unique identifiers""" - results = book_search.search_title_author("Another", min_confidence=0) + results = book_search.search_title_author("annoying", min_confidence=0) self.assertEqual(len(results), 1) - self.assertEqual(results[0], self.second_edition) + self.assertEqual(results[0], self.third_edition) def test_search_title_author_return_first(self): - """search by unique identifiers""" - results = book_search.search_title_author( + """sorts by edition rank""" + result = book_search.search_title_author( "Another", min_confidence=0, return_first=True ) - self.assertEqual(results, self.second_edition) + self.assertEqual(result, self.second_edition) # highest edition rank + + def test_search_title_author_one_edition_per_work(self): + """at most one edition per work""" + results = book_search.search_title_author("Edition", 0) + self.assertEqual(results, [self.first_edition]) # highest edition rank def test_format_search_result(self): """format a search result""" From 58f149d8896494faaa4cfcdd92696036bc8f91c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 01:02:35 +0000 Subject: [PATCH 12/17] Bump aiohttp from 3.8.6 to 3.9.0 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.8.6 to 3.9.0. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.8.6...v3.9.0) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 36192f148..4ec939c0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohttp==3.8.6 +aiohttp==3.9.0 bleach==5.0.1 celery==5.2.7 colorthief==0.2.1 From 5384e4c47084a9b383875e98a99f30659e64c2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Thu, 30 Nov 2023 15:58:48 -0300 Subject: [PATCH 13/17] Use bulk_create to test ordered collections --- bookwyrm/tests/models/test_activitypub_mixin.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 645a6546b..8af41ffbd 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -391,11 +391,13 @@ class ActivitypubMixins(TestCase): def test_to_ordered_collection_page(self, *_): """make sure the paged results of an ordered collection work""" self.assertEqual(PAGE_LENGTH, 15) - for number in range(0, 2 * PAGE_LENGTH): - models.Status.objects.create( + models.Status.objects.bulk_create( + models.Status( user=self.local_user, content=f"test status {number}", ) + for number in range(2 * PAGE_LENGTH) + ) page_1 = to_ordered_collection_page( models.Status.objects.all(), "http://fish.com/", page=1 ) @@ -416,13 +418,13 @@ class ActivitypubMixins(TestCase): def test_to_ordered_collection(self, *_): """convert a queryset into an ordered collection object""" self.assertEqual(PAGE_LENGTH, 15) - - for number in range(0, 2 * PAGE_LENGTH): - models.Status.objects.create( + models.Status.objects.bulk_create( + models.Status( user=self.local_user, content=f"test status {number}", ) - + for number in range(2 * PAGE_LENGTH) + ) MockSelf = namedtuple("Self", ("remote_id")) mock_self = MockSelf("") From 8fd05004eac0296be4388ccb3bbd57f56f758515 Mon Sep 17 00:00:00 2001 From: Victor Villas Date: Sun, 3 Dec 2023 20:03:33 -0800 Subject: [PATCH 14/17] Update page formatter on ordered collection --- bookwyrm/models/activitypub_mixin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 36317ad4e..d0a941f43 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -602,7 +602,7 @@ def to_ordered_collection_page( if activity_page.has_next(): next_page = f"{remote_id}?page={activity_page.next_page_number()}" if activity_page.has_previous(): - prev_page = f"{remote_id}?page=%d{activity_page.previous_page_number()}" + prev_page = f"{remote_id}?page={activity_page.previous_page_number()}" return activitypub.OrderedCollectionPage( id=f"{remote_id}?page={page}", partOf=remote_id, From 9d502f5ee23d19a2afbabadbc5d16dd277a6ea45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Thu, 30 Nov 2023 02:56:16 -0300 Subject: [PATCH 15/17] Use setUpTestData() to speed up tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pylint's `bad-classmethod-argument` is disabled for each definition to avoid rewriting the method bodies just to rename `self` → `cls`. This can be done gradually, as the setUpTestData methods are modified along the way. --- bookwyrm/tests/activitypub/test_author.py | 3 ++- .../tests/activitypub/test_base_activity.py | 5 ++-- bookwyrm/tests/activitypub/test_note.py | 4 ++-- bookwyrm/tests/activitypub/test_quotation.py | 6 ++++- .../activitystreams/test_abstractstream.py | 6 ++++- .../tests/activitystreams/test_booksstream.py | 3 ++- .../tests/activitystreams/test_homestream.py | 3 ++- .../tests/activitystreams/test_localstream.py | 3 ++- .../tests/activitystreams/test_signals.py | 8 ++----- bookwyrm/tests/activitystreams/test_tasks.py | 4 ++-- .../connectors/test_abstract_connector.py | 23 +++++++++++-------- .../test_abstract_minimal_connector.py | 8 +++++-- .../connectors/test_bookwyrm_connector.py | 8 +++++-- .../connectors/test_connector_manager.py | 3 ++- .../connectors/test_inventaire_connector.py | 8 +++++-- .../connectors/test_openlibrary_connector.py | 8 +++++-- .../tests/importers/test_calibre_import.py | 5 +++- .../tests/importers/test_goodreads_import.py | 5 +++- bookwyrm/tests/importers/test_importer.py | 6 +++-- .../importers/test_librarything_import.py | 5 +++- .../importers/test_openlibrary_import.py | 5 +++- .../tests/importers/test_storygraph_import.py | 5 +++- bookwyrm/tests/lists_stream/test_signals.py | 5 ++-- bookwyrm/tests/lists_stream/test_stream.py | 5 ++-- bookwyrm/tests/lists_stream/test_tasks.py | 5 ++-- .../management/test_populate_lists_streams.py | 3 ++- .../tests/management/test_populate_streams.py | 3 ++- .../tests/models/test_activitypub_mixin.py | 5 +++- bookwyrm/tests/models/test_automod.py | 8 ++++--- bookwyrm/tests/models/test_base_model.py | 4 +++- bookwyrm/tests/models/test_book_model.py | 3 ++- bookwyrm/tests/models/test_group.py | 3 ++- bookwyrm/tests/models/test_import_model.py | 5 +++- bookwyrm/tests/models/test_link.py | 11 --------- bookwyrm/tests/models/test_list.py | 3 ++- bookwyrm/tests/models/test_notification.py | 6 +++-- .../tests/models/test_readthrough_model.py | 3 ++- .../tests/models/test_relationship_models.py | 3 ++- bookwyrm/tests/models/test_shelf_model.py | 3 ++- bookwyrm/tests/models/test_site.py | 3 ++- bookwyrm/tests/models/test_status_model.py | 11 +++++---- bookwyrm/tests/models/test_user_model.py | 4 ++-- .../templatetags/test_book_display_tags.py | 3 ++- .../tests/templatetags/test_feed_page_tags.py | 3 ++- .../tests/templatetags/test_interaction.py | 3 ++- .../test_notification_page_tags.py | 3 ++- .../tests/templatetags/test_rating_tags.py | 3 ++- .../tests/templatetags/test_shelf_tags.py | 8 +++++-- .../tests/templatetags/test_status_display.py | 3 ++- bookwyrm/tests/templatetags/test_utilities.py | 4 ++-- bookwyrm/tests/test_book_search.py | 3 ++- bookwyrm/tests/test_context_processors.py | 8 +++++-- bookwyrm/tests/test_emailing.py | 9 +++++--- bookwyrm/tests/test_signing.py | 10 ++++---- .../tests/views/admin/test_announcements.py | 8 +++++-- bookwyrm/tests/views/admin/test_automod.py | 9 +++++--- bookwyrm/tests/views/admin/test_celery.py | 9 +++++--- bookwyrm/tests/views/admin/test_dashboard.py | 8 +++++-- .../tests/views/admin/test_email_blocks.py | 8 +++++-- .../tests/views/admin/test_email_config.py | 9 +++++--- bookwyrm/tests/views/admin/test_federation.py | 9 +++++--- bookwyrm/tests/views/admin/test_imports.py | 9 +++++--- .../tests/views/admin/test_ip_blocklist.py | 8 +++++-- .../tests/views/admin/test_link_domains.py | 8 +++++-- bookwyrm/tests/views/admin/test_reports.py | 9 +++++--- bookwyrm/tests/views/admin/test_site.py | 9 +++++--- bookwyrm/tests/views/admin/test_themes.py | 9 +++++--- bookwyrm/tests/views/admin/test_user_admin.py | 8 +++++-- bookwyrm/tests/views/books/test_book.py | 8 +++++-- bookwyrm/tests/views/books/test_edit_book.py | 13 ++++++----- bookwyrm/tests/views/books/test_editions.py | 8 +++++-- bookwyrm/tests/views/books/test_links.py | 9 +++++--- bookwyrm/tests/views/imports/test_import.py | 9 +++++--- .../tests/views/imports/test_import_review.py | 9 +++++--- .../views/imports/test_import_troubleshoot.py | 9 +++++--- bookwyrm/tests/views/inbox/test_inbox.py | 22 ++++++++++-------- bookwyrm/tests/views/inbox/test_inbox_add.py | 3 ++- .../tests/views/inbox/test_inbox_announce.py | 9 +++++--- .../tests/views/inbox/test_inbox_block.py | 3 ++- .../tests/views/inbox/test_inbox_create.py | 10 +++++--- .../tests/views/inbox/test_inbox_delete.py | 4 ++-- .../tests/views/inbox/test_inbox_follow.py | 3 ++- bookwyrm/tests/views/inbox/test_inbox_like.py | 9 +++++--- .../tests/views/inbox/test_inbox_remove.py | 3 ++- .../tests/views/inbox/test_inbox_update.py | 9 +++++--- bookwyrm/tests/views/landing/test_invite.py | 9 +++++--- bookwyrm/tests/views/landing/test_landing.py | 10 +++++--- bookwyrm/tests/views/landing/test_login.py | 11 +++++---- bookwyrm/tests/views/landing/test_password.py | 10 +++++--- bookwyrm/tests/views/landing/test_register.py | 14 ++++++----- bookwyrm/tests/views/lists/test_curate.py | 12 ++++++---- bookwyrm/tests/views/lists/test_embed.py | 12 ++++++---- bookwyrm/tests/views/lists/test_list.py | 12 ++++++---- bookwyrm/tests/views/lists/test_list_item.py | 8 +++++-- bookwyrm/tests/views/lists/test_lists.py | 13 +++++++---- .../tests/views/preferences/test_block.py | 8 +++++-- .../views/preferences/test_change_password.py | 8 +++++-- .../views/preferences/test_delete_user.py | 11 +++++---- .../tests/views/preferences/test_edit_user.py | 8 +++++-- .../tests/views/preferences/test_export.py | 8 +++++-- .../views/preferences/test_two_factor_auth.py | 8 +++++-- bookwyrm/tests/views/shelf/test_shelf.py | 7 ++++-- .../tests/views/shelf/test_shelf_actions.py | 8 +++++-- bookwyrm/tests/views/test_annual_summary.py | 13 ++++++----- bookwyrm/tests/views/test_author.py | 9 +++++--- bookwyrm/tests/views/test_directory.py | 9 +++++--- bookwyrm/tests/views/test_discover.py | 11 +++++---- bookwyrm/tests/views/test_feed.py | 8 +++++-- bookwyrm/tests/views/test_follow.py | 8 +++++-- bookwyrm/tests/views/test_get_started.py | 8 +++++-- bookwyrm/tests/views/test_goal.py | 12 ++++++---- bookwyrm/tests/views/test_group.py | 11 +++++---- bookwyrm/tests/views/test_hashtag.py | 10 +++++--- bookwyrm/tests/views/test_helpers.py | 17 ++++++++------ bookwyrm/tests/views/test_interaction.py | 9 +++++--- bookwyrm/tests/views/test_isbn.py | 8 +++++-- bookwyrm/tests/views/test_notifications.py | 8 +++++-- bookwyrm/tests/views/test_outbox.py | 8 +++++-- bookwyrm/tests/views/test_reading.py | 8 +++++-- bookwyrm/tests/views/test_readthrough.py | 8 ++++--- bookwyrm/tests/views/test_report.py | 9 +++++--- bookwyrm/tests/views/test_rss_feed.py | 9 +++++--- bookwyrm/tests/views/test_search.py | 8 +++++-- bookwyrm/tests/views/test_setup.py | 8 +++++-- bookwyrm/tests/views/test_status.py | 19 ++++++++------- bookwyrm/tests/views/test_updates.py | 8 +++++-- bookwyrm/tests/views/test_user.py | 9 +++++--- bookwyrm/tests/views/test_wellknown.py | 8 +++++-- pytest.ini | 1 + 129 files changed, 644 insertions(+), 327 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_author.py b/bookwyrm/tests/activitypub/test_author.py index 51beac49a..7579909a8 100644 --- a/bookwyrm/tests/activitypub/test_author.py +++ b/bookwyrm/tests/activitypub/test_author.py @@ -6,7 +6,8 @@ from bookwyrm import models class Author(TestCase): """serialize author tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """initial data""" self.book = models.Edition.objects.create( title="Example Edition", diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index c9022d35c..a0d10019f 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -28,8 +28,8 @@ from bookwyrm import models class BaseActivity(TestCase): """the super class for model-linked activitypub dataclasses""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we're probably going to re-use this so why copy/paste""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -40,6 +40,7 @@ class BaseActivity(TestCase): self.user.remote_id = "http://example.com/a/b" self.user.save(broadcast=False, update_fields=["remote_id"]) + def setUp(self): datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") self.userdata = json.loads(datafile.read_bytes()) # don't try to load the user icon diff --git a/bookwyrm/tests/activitypub/test_note.py b/bookwyrm/tests/activitypub/test_note.py index c4db2d9b1..fd5467f01 100644 --- a/bookwyrm/tests/activitypub/test_note.py +++ b/bookwyrm/tests/activitypub/test_note.py @@ -10,8 +10,8 @@ from bookwyrm import models class Note(TestCase): """the model-linked ActivityPub dataclass for Note-based types""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create a shared user""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/activitypub/test_quotation.py b/bookwyrm/tests/activitypub/test_quotation.py index 678ee7aa3..9a0867c52 100644 --- a/bookwyrm/tests/activitypub/test_quotation.py +++ b/bookwyrm/tests/activitypub/test_quotation.py @@ -10,7 +10,8 @@ from bookwyrm import activitypub, models class Quotation(TestCase): """we have hecka ways to create statuses""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """model objects we'll need""" with patch("bookwyrm.models.user.set_remote_server.delay"): self.user = models.User.objects.create_user( @@ -26,6 +27,9 @@ class Quotation(TestCase): title="Example Edition", remote_id="https://example.com/book/1", ) + + def setUp(self): + """other test data""" datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_quotation.json") self.status_data = json.loads(datafile.read_bytes()) diff --git a/bookwyrm/tests/activitystreams/test_abstractstream.py b/bookwyrm/tests/activitystreams/test_abstractstream.py index a9f2cfdd3..83985efdc 100644 --- a/bookwyrm/tests/activitystreams/test_abstractstream.py +++ b/bookwyrm/tests/activitystreams/test_abstractstream.py @@ -15,7 +15,8 @@ from bookwyrm import activitystreams, models class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -43,6 +44,9 @@ class Activitystreams(TestCase): work = models.Work.objects.create(title="test work") self.book = models.Edition.objects.create(title="test book", parent_work=work) + def setUp(self): + """per-test setUp""" + class TestStream(activitystreams.ActivityStream): """test stream, don't have to do anything here""" diff --git a/bookwyrm/tests/activitystreams/test_booksstream.py b/bookwyrm/tests/activitystreams/test_booksstream.py index 1cd335b30..71d7ce531 100644 --- a/bookwyrm/tests/activitystreams/test_booksstream.py +++ b/bookwyrm/tests/activitystreams/test_booksstream.py @@ -14,7 +14,8 @@ from bookwyrm import activitystreams, models class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/activitystreams/test_homestream.py b/bookwyrm/tests/activitystreams/test_homestream.py index 2dc975523..3312f20ee 100644 --- a/bookwyrm/tests/activitystreams/test_homestream.py +++ b/bookwyrm/tests/activitystreams/test_homestream.py @@ -12,7 +12,8 @@ from bookwyrm import activitystreams, models class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/activitystreams/test_localstream.py b/bookwyrm/tests/activitystreams/test_localstream.py index 14c5798dc..f4ca13395 100644 --- a/bookwyrm/tests/activitystreams/test_localstream.py +++ b/bookwyrm/tests/activitystreams/test_localstream.py @@ -12,7 +12,8 @@ from bookwyrm import activitystreams, models class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/activitystreams/test_signals.py b/bookwyrm/tests/activitystreams/test_signals.py index 210d4d5df..db16a0081 100644 --- a/bookwyrm/tests/activitystreams/test_signals.py +++ b/bookwyrm/tests/activitystreams/test_signals.py @@ -14,7 +14,8 @@ from bookwyrm import activitystreams, models class ActivitystreamsSignals(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -22,9 +23,6 @@ class ActivitystreamsSignals(TestCase): 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( - "fish", "fish@fish.fish", "password", local=True, localname="fish" - ) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat", @@ -35,8 +33,6 @@ class ActivitystreamsSignals(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - work = models.Work.objects.create(title="test work") - self.book = models.Edition.objects.create(title="test book", parent_work=work) def test_add_status_on_create_ignore(self, *_): """a new statuses has entered""" diff --git a/bookwyrm/tests/activitystreams/test_tasks.py b/bookwyrm/tests/activitystreams/test_tasks.py index 82b8c2e5a..39a240e92 100644 --- a/bookwyrm/tests/activitystreams/test_tasks.py +++ b/bookwyrm/tests/activitystreams/test_tasks.py @@ -7,8 +7,8 @@ from bookwyrm import activitystreams, models class Activitystreams(TestCase): """using redis to build activity streams""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """use a test csv""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/connectors/test_abstract_connector.py b/bookwyrm/tests/connectors/test_abstract_connector.py index 02ac5c66a..b43966d6a 100644 --- a/bookwyrm/tests/connectors/test_abstract_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_connector.py @@ -12,9 +12,10 @@ from bookwyrm.settings import DOMAIN class AbstractConnector(TestCase): """generic code for connecting to outside data sources""" - def setUp(self): - """we need an example connector""" - self.connector_info = models.Connector.objects.create( + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """we need an example connector in the database""" + models.Connector.objects.create( identifier="example.com", connector_file="openlibrary", base_url="https://example.com", @@ -22,19 +23,27 @@ class AbstractConnector(TestCase): covers_url="https://example.com/covers", search_url="https://example.com/search?q=", ) + self.book = models.Edition.objects.create( + title="Test Book", + remote_id="https://example.com/book/1234", + openlibrary_key="OL1234M", + ) + + def setUp(self): + """test data""" work_data = { "id": "abc1", "title": "Test work", "type": "work", "openlibraryKey": "OL1234W", } - self.work_data = work_data edition_data = { "id": "abc2", "title": "Test edition", "type": "edition", "openlibraryKey": "OL1234M", } + self.work_data = work_data self.edition_data = edition_data class TestConnector(abstract_connector.AbstractConnector): @@ -70,12 +79,6 @@ class AbstractConnector(TestCase): Mapping("openlibraryKey"), ] - self.book = models.Edition.objects.create( - title="Test Book", - remote_id="https://example.com/book/1234", - openlibrary_key="OL1234M", - ) - def test_abstract_connector_init(self): """barebones connector for search with defaults""" self.assertIsInstance(self.connector.book_mappings, list) diff --git a/bookwyrm/tests/connectors/test_abstract_minimal_connector.py b/bookwyrm/tests/connectors/test_abstract_minimal_connector.py index 119ca3581..73399649e 100644 --- a/bookwyrm/tests/connectors/test_abstract_minimal_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_minimal_connector.py @@ -9,8 +9,9 @@ from bookwyrm.connectors.abstract_connector import Mapping class AbstractConnector(TestCase): """generic code for connecting to outside data sources""" - def setUp(self): - """we need an example connector""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """we need an example connector in the database""" self.connector_info = models.Connector.objects.create( identifier="example.com", connector_file="openlibrary", @@ -21,6 +22,9 @@ class AbstractConnector(TestCase): isbn_search_url="https://example.com/isbn?q=", ) + def setUp(self): + """instantiate example connector""" + class TestConnector(abstract_connector.AbstractMinimalConnector): """nothing added here""" diff --git a/bookwyrm/tests/connectors/test_bookwyrm_connector.py b/bookwyrm/tests/connectors/test_bookwyrm_connector.py index 1e369ca01..553901655 100644 --- a/bookwyrm/tests/connectors/test_bookwyrm_connector.py +++ b/bookwyrm/tests/connectors/test_bookwyrm_connector.py @@ -11,8 +11,9 @@ from bookwyrm.connectors.bookwyrm_connector import Connector class BookWyrmConnector(TestCase): """this connector doesn't do much, just search""" - def setUp(self): - """create the connector""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """create bookwrym_connector in the database""" models.Connector.objects.create( identifier="example.com", connector_file="bookwyrm_connector", @@ -21,6 +22,9 @@ class BookWyrmConnector(TestCase): covers_url="https://example.com/images/covers", search_url="https://example.com/search?q=", ) + + def setUp(self): + """test data""" self.connector = Connector("example.com") def test_get_or_create_book_existing(self): diff --git a/bookwyrm/tests/connectors/test_connector_manager.py b/bookwyrm/tests/connectors/test_connector_manager.py index c0c09147e..cc01f1116 100644 --- a/bookwyrm/tests/connectors/test_connector_manager.py +++ b/bookwyrm/tests/connectors/test_connector_manager.py @@ -10,7 +10,8 @@ from bookwyrm.connectors.bookwyrm_connector import Connector as BookWyrmConnecto class ConnectorManager(TestCase): """interface between the app and various connectors""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we'll need some books and a connector info entry""" self.work = models.Work.objects.create(title="Example Work") diff --git a/bookwyrm/tests/connectors/test_inventaire_connector.py b/bookwyrm/tests/connectors/test_inventaire_connector.py index 3bba9ece3..c4ea1a595 100644 --- a/bookwyrm/tests/connectors/test_inventaire_connector.py +++ b/bookwyrm/tests/connectors/test_inventaire_connector.py @@ -14,8 +14,9 @@ from bookwyrm.connectors.connector_manager import ConnectorException class Inventaire(TestCase): """test loading data from inventaire.io""" - def setUp(self): - """creates the connector we'll use""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """creates the connector in the database""" models.Connector.objects.create( identifier="inventaire.io", name="Inventaire", @@ -26,6 +27,9 @@ class Inventaire(TestCase): search_url="https://inventaire.io/search?q=", isbn_search_url="https://inventaire.io/isbn", ) + + def setUp(self): + """connector instance""" self.connector = Connector("inventaire.io") @responses.activate diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index 70db03483..487356400 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -18,8 +18,9 @@ from bookwyrm.connectors.connector_manager import ConnectorException class Openlibrary(TestCase): """test loading data from openlibrary.org""" - def setUp(self): - """creates the connector we'll use""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """creates the connector in the database""" models.Connector.objects.create( identifier="openlibrary.org", name="OpenLibrary", @@ -30,6 +31,9 @@ class Openlibrary(TestCase): search_url="https://openlibrary.org/search?q=", isbn_search_url="https://openlibrary.org/isbn", ) + + def setUp(self): + """connector instance and other test data""" self.connector = Connector("openlibrary.org") work_file = pathlib.Path(__file__).parent.joinpath("../data/ol_work.json") diff --git a/bookwyrm/tests/importers/test_calibre_import.py b/bookwyrm/tests/importers/test_calibre_import.py index 37b206458..d549a75ed 100644 --- a/bookwyrm/tests/importers/test_calibre_import.py +++ b/bookwyrm/tests/importers/test_calibre_import.py @@ -16,12 +16,15 @@ from bookwyrm.models.import_job import handle_imported_book class CalibreImport(TestCase): """importing from Calibre csv""" - # pylint: disable=invalid-name def setUp(self): """use a test csv""" self.importer = CalibreImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/calibre.csv") self.csv = open(datafile, "r", encoding=self.importer.encoding) + + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """populate database""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/importers/test_goodreads_import.py b/bookwyrm/tests/importers/test_goodreads_import.py index 88f8eb3f4..0b5fd5e2d 100644 --- a/bookwyrm/tests/importers/test_goodreads_import.py +++ b/bookwyrm/tests/importers/test_goodreads_import.py @@ -23,12 +23,15 @@ def make_date(*args): class GoodreadsImport(TestCase): """importing from goodreads csv""" - # pylint: disable=invalid-name def setUp(self): """use a test csv""" self.importer = GoodreadsImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") self.csv = open(datafile, "r", encoding=self.importer.encoding) + + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """populate database""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index f48b97993..eb3041dc6 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -26,13 +26,15 @@ def make_date(*args): class GenericImporter(TestCase): """importing from csv""" - # pylint: disable=invalid-name def setUp(self): """use a test csv""" - self.importer = Importer() datafile = pathlib.Path(__file__).parent.joinpath("../data/generic.csv") self.csv = open(datafile, "r", encoding=self.importer.encoding) + + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """populate database""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/importers/test_librarything_import.py b/bookwyrm/tests/importers/test_librarything_import.py index 71a1c9796..c2fe7a9a8 100644 --- a/bookwyrm/tests/importers/test_librarything_import.py +++ b/bookwyrm/tests/importers/test_librarything_import.py @@ -23,7 +23,6 @@ def make_date(*args): class LibrarythingImport(TestCase): """importing from librarything tsv""" - # pylint: disable=invalid-name def setUp(self): """use a test tsv""" self.importer = LibrarythingImporter() @@ -31,6 +30,10 @@ class LibrarythingImport(TestCase): # Librarything generates latin encoded exports... self.csv = open(datafile, "r", encoding=self.importer.encoding) + + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """populate database""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/importers/test_openlibrary_import.py b/bookwyrm/tests/importers/test_openlibrary_import.py index 82b5ec3ea..2712930d9 100644 --- a/bookwyrm/tests/importers/test_openlibrary_import.py +++ b/bookwyrm/tests/importers/test_openlibrary_import.py @@ -23,12 +23,15 @@ def make_date(*args): class OpenLibraryImport(TestCase): """importing from openlibrary csv""" - # pylint: disable=invalid-name def setUp(self): """use a test csv""" self.importer = OpenLibraryImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/openlibrary.csv") self.csv = open(datafile, "r", encoding=self.importer.encoding) + + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """populate database""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/importers/test_storygraph_import.py b/bookwyrm/tests/importers/test_storygraph_import.py index 0befbeb3f..edc484629 100644 --- a/bookwyrm/tests/importers/test_storygraph_import.py +++ b/bookwyrm/tests/importers/test_storygraph_import.py @@ -23,12 +23,15 @@ def make_date(*args): class StorygraphImport(TestCase): """importing from storygraph csv""" - # pylint: disable=invalid-name def setUp(self): """use a test csv""" self.importer = StorygraphImporter() datafile = pathlib.Path(__file__).parent.joinpath("../data/storygraph.csv") self.csv = open(datafile, "r", encoding=self.importer.encoding) + + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """populate database""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/lists_stream/test_signals.py b/bookwyrm/tests/lists_stream/test_signals.py index 96f1ae231..51f0709b0 100644 --- a/bookwyrm/tests/lists_stream/test_signals.py +++ b/bookwyrm/tests/lists_stream/test_signals.py @@ -8,8 +8,9 @@ from bookwyrm import lists_stream, models class ListsStreamSignals(TestCase): """using redis to build activity streams""" - def setUp(self): - """use a test csv""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """database setup""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/lists_stream/test_stream.py b/bookwyrm/tests/lists_stream/test_stream.py index 0e87c7436..6dd6a1c8e 100644 --- a/bookwyrm/tests/lists_stream/test_stream.py +++ b/bookwyrm/tests/lists_stream/test_stream.py @@ -15,8 +15,9 @@ from bookwyrm import lists_stream, models class ListsStream(TestCase): """using redis to build activity streams""" - def setUp(self): - """use a test csv""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """database setup""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/lists_stream/test_tasks.py b/bookwyrm/tests/lists_stream/test_tasks.py index 2e01cecad..18ddecf18 100644 --- a/bookwyrm/tests/lists_stream/test_tasks.py +++ b/bookwyrm/tests/lists_stream/test_tasks.py @@ -10,8 +10,9 @@ from bookwyrm import lists_stream, models class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): - """use a test csv""" + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """database setup""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/management/test_populate_lists_streams.py b/bookwyrm/tests/management/test_populate_lists_streams.py index 2cce7b7a3..5990da4e3 100644 --- a/bookwyrm/tests/management/test_populate_lists_streams.py +++ b/bookwyrm/tests/management/test_populate_lists_streams.py @@ -12,7 +12,8 @@ from bookwyrm.management.commands.populate_lists_streams import populate_lists_s class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need some stuff""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/management/test_populate_streams.py b/bookwyrm/tests/management/test_populate_streams.py index c20a21ac5..4d6bf688f 100644 --- a/bookwyrm/tests/management/test_populate_streams.py +++ b/bookwyrm/tests/management/test_populate_streams.py @@ -10,7 +10,8 @@ from bookwyrm.management.commands.populate_streams import populate_streams class Activitystreams(TestCase): """using redis to build activity streams""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need some stuff""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index 645a6546b..c6c1b8235 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -26,7 +26,8 @@ from bookwyrm.settings import PAGE_LENGTH class ActivitypubMixins(TestCase): """functionality shared across models""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """shared data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -47,6 +48,8 @@ class ActivitypubMixins(TestCase): outbox="https://example.com/users/rat/outbox", ) + def setUp(self): + """test data""" self.object_mock = { "to": "to field", "cc": "cc field", diff --git a/bookwyrm/tests/models/test_automod.py b/bookwyrm/tests/models/test_automod.py index 9de7e6488..1ad139886 100644 --- a/bookwyrm/tests/models/test_automod.py +++ b/bookwyrm/tests/models/test_automod.py @@ -14,10 +14,9 @@ from bookwyrm.models.antispam import automod_task class AutomodModel(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -30,6 +29,9 @@ class AutomodModel(TestCase): is_superuser=True, ) + def setUp(self): + self.factory = RequestFactory() + def test_automod_task_no_rules(self, *_): """nothing to see here""" self.assertFalse(models.Report.objects.exists()) diff --git a/bookwyrm/tests/models/test_base_model.py b/bookwyrm/tests/models/test_base_model.py index b94592571..f1f465b73 100644 --- a/bookwyrm/tests/models/test_base_model.py +++ b/bookwyrm/tests/models/test_base_model.py @@ -12,7 +12,8 @@ from bookwyrm.settings import DOMAIN class BaseModel(TestCase): """functionality shared across models""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """shared data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -31,6 +32,7 @@ class BaseModel(TestCase): outbox="https://example.com/users/rat/outbox", ) + def setUp(self): class BookWyrmTestModel(base_model.BookWyrmModel): """just making it not abstract""" diff --git a/bookwyrm/tests/models/test_book_model.py b/bookwyrm/tests/models/test_book_model.py index 4347efcb6..c6b854180 100644 --- a/bookwyrm/tests/models/test_book_model.py +++ b/bookwyrm/tests/models/test_book_model.py @@ -18,7 +18,8 @@ from bookwyrm.settings import ENABLE_THUMBNAIL_GENERATION class Book(TestCase): """not too much going on in the books model but here we are""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we'll need some books""" self.work = models.Work.objects.create( title="Example Work", remote_id="https://example.com/book/1" diff --git a/bookwyrm/tests/models/test_group.py b/bookwyrm/tests/models/test_group.py index 86cafaa39..6f5388b19 100644 --- a/bookwyrm/tests/models/test_group.py +++ b/bookwyrm/tests/models/test_group.py @@ -9,7 +9,8 @@ from bookwyrm import models class Group(TestCase): """some activitypub oddness ahead""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """Set up for tests""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index d1ff209f4..7ca36d223 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -16,7 +16,8 @@ from bookwyrm.connectors import connector_manager class ImportJob(TestCase): """this is a fancy one!!!""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """data is from a goodreads export of The Raven Tower""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -24,6 +25,8 @@ class ImportJob(TestCase): self.local_user = models.User.objects.create_user( "mouse", "mouse@mouse.mouse", "password", local=True ) + + def setUp(self): self.job = models.ImportJob.objects.create(user=self.local_user, mappings={}) def test_isbn(self): diff --git a/bookwyrm/tests/models/test_link.py b/bookwyrm/tests/models/test_link.py index 8afecd6ce..f72bdc239 100644 --- a/bookwyrm/tests/models/test_link.py +++ b/bookwyrm/tests/models/test_link.py @@ -9,17 +9,6 @@ from bookwyrm import models class Link(TestCase): """some activitypub oddness ahead""" - def setUp(self): - """look, a list""" - with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( - "bookwyrm.activitystreams.populate_stream_task.delay" - ), patch("bookwyrm.lists_stream.populate_lists_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) - def test_create_domain(self, _): """generated default name""" domain = models.LinkDomain.objects.create(domain="beep.com") diff --git a/bookwyrm/tests/models/test_list.py b/bookwyrm/tests/models/test_list.py index f7e64c6f2..83d7ed6a5 100644 --- a/bookwyrm/tests/models/test_list.py +++ b/bookwyrm/tests/models/test_list.py @@ -11,7 +11,8 @@ from bookwyrm import models, settings class List(TestCase): """some activitypub oddness ahead""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """look, a list""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/models/test_notification.py b/bookwyrm/tests/models/test_notification.py index 352b7631d..93422640b 100644 --- a/bookwyrm/tests/models/test_notification.py +++ b/bookwyrm/tests/models/test_notification.py @@ -7,7 +7,8 @@ from bookwyrm import models class Notification(TestCase): """let people know things""" - def setUp(self): # pylint: disable=invalid-name + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """useful things for creating a notification""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -197,7 +198,8 @@ class Notification(TestCase): class NotifyInviteRequest(TestCase): """let admins know of invite requests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """ensure there is one admin""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/models/test_readthrough_model.py b/bookwyrm/tests/models/test_readthrough_model.py index 7e3963cff..d34a06aaf 100644 --- a/bookwyrm/tests/models/test_readthrough_model.py +++ b/bookwyrm/tests/models/test_readthrough_model.py @@ -11,7 +11,8 @@ from bookwyrm import models class ReadThrough(TestCase): """some activitypub oddness ahead""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """look, a shelf""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/models/test_relationship_models.py b/bookwyrm/tests/models/test_relationship_models.py index a5b4dbffd..8f849bc3b 100644 --- a/bookwyrm/tests/models/test_relationship_models.py +++ b/bookwyrm/tests/models/test_relationship_models.py @@ -14,7 +14,8 @@ from bookwyrm import models class Relationship(TestCase): """following, blocking, stuff like that""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need some users for this""" with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( diff --git a/bookwyrm/tests/models/test_shelf_model.py b/bookwyrm/tests/models/test_shelf_model.py index 4f7f35890..88b1fad06 100644 --- a/bookwyrm/tests/models/test_shelf_model.py +++ b/bookwyrm/tests/models/test_shelf_model.py @@ -15,7 +15,8 @@ from bookwyrm import models, settings class Shelf(TestCase): """some activitypub oddness ahead""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """look, a shelf""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/models/test_site.py b/bookwyrm/tests/models/test_site.py index 05882268e..f4accc04b 100644 --- a/bookwyrm/tests/models/test_site.py +++ b/bookwyrm/tests/models/test_site.py @@ -12,7 +12,8 @@ from bookwyrm import models, settings class SiteModels(TestCase): """tests for site models""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index d1f07b44e..9899f6bf3 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -24,8 +24,8 @@ from bookwyrm import activitypub, models, settings class Status(TestCase): """lotta types of statuses""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """useful things for creating a status""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -45,6 +45,10 @@ class Status(TestCase): ) self.book = models.Edition.objects.create(title="Test Edition") + def setUp(self): + """individual test setup""" + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False image_file = pathlib.Path(__file__).parent.joinpath( "../../static/images/default_avi.jpg" ) @@ -54,9 +58,6 @@ class Status(TestCase): image.save(output, format=image.format) self.book.cover.save("test.jpg", ContentFile(output.getvalue())) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False - def test_status_generated_fields(self, *_): """setting remote id""" status = models.Status.objects.create(content="bleh", user=self.local_user) diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index 30d7918c0..47a662e49 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -18,8 +18,8 @@ class User(TestCase): protocol = "https://" if USE_HTTPS else "http://" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): diff --git a/bookwyrm/tests/templatetags/test_book_display_tags.py b/bookwyrm/tests/templatetags/test_book_display_tags.py index 54ae8806b..dcff01a80 100644 --- a/bookwyrm/tests/templatetags/test_book_display_tags.py +++ b/bookwyrm/tests/templatetags/test_book_display_tags.py @@ -13,7 +13,8 @@ from bookwyrm.templatetags import book_display_tags class BookDisplayTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/templatetags/test_feed_page_tags.py b/bookwyrm/tests/templatetags/test_feed_page_tags.py index 5e5dc2357..d0a895f36 100644 --- a/bookwyrm/tests/templatetags/test_feed_page_tags.py +++ b/bookwyrm/tests/templatetags/test_feed_page_tags.py @@ -12,7 +12,8 @@ from bookwyrm.templatetags import feed_page_tags class FeedPageTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/templatetags/test_interaction.py b/bookwyrm/tests/templatetags/test_interaction.py index a48b3364d..a9d1267c0 100644 --- a/bookwyrm/tests/templatetags/test_interaction.py +++ b/bookwyrm/tests/templatetags/test_interaction.py @@ -12,7 +12,8 @@ from bookwyrm.templatetags import interaction class InteractionTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/templatetags/test_notification_page_tags.py b/bookwyrm/tests/templatetags/test_notification_page_tags.py index 3c92181b2..94f839ec5 100644 --- a/bookwyrm/tests/templatetags/test_notification_page_tags.py +++ b/bookwyrm/tests/templatetags/test_notification_page_tags.py @@ -12,7 +12,8 @@ from bookwyrm.templatetags import notification_page_tags class NotificationPageTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/templatetags/test_rating_tags.py b/bookwyrm/tests/templatetags/test_rating_tags.py index 8c07eeb8f..5225d57a6 100644 --- a/bookwyrm/tests/templatetags/test_rating_tags.py +++ b/bookwyrm/tests/templatetags/test_rating_tags.py @@ -12,7 +12,8 @@ from bookwyrm.templatetags import rating_tags class RatingTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/templatetags/test_shelf_tags.py b/bookwyrm/tests/templatetags/test_shelf_tags.py index 5a88604dd..7c456c815 100644 --- a/bookwyrm/tests/templatetags/test_shelf_tags.py +++ b/bookwyrm/tests/templatetags/test_shelf_tags.py @@ -15,9 +15,9 @@ from bookwyrm.templatetags import shelf_tags class ShelfTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -41,6 +41,10 @@ class ShelfTags(TestCase): parent_work=models.Work.objects.create(title="Test work"), ) + def setUp(self): + """test data""" + self.factory = RequestFactory() + def test_get_is_book_on_shelf(self, *_): """check if a book is on a shelf""" shelf = self.local_user.shelf_set.first() diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index af2fc9420..a9bab0b68 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -14,7 +14,8 @@ from bookwyrm.templatetags import status_display class StatusDisplayTags(TestCase): """lotta different things here""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/templatetags/test_utilities.py b/bookwyrm/tests/templatetags/test_utilities.py index c9e1c744f..1bf98fda8 100644 --- a/bookwyrm/tests/templatetags/test_utilities.py +++ b/bookwyrm/tests/templatetags/test_utilities.py @@ -14,8 +14,8 @@ from bookwyrm.templatetags import utilities class UtilitiesTags(TestCase): """lotta different things here""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create some filler objects""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/test_book_search.py b/bookwyrm/tests/test_book_search.py index ad954f585..d2056bfeb 100644 --- a/bookwyrm/tests/test_book_search.py +++ b/bookwyrm/tests/test_book_search.py @@ -10,7 +10,8 @@ from bookwyrm.connectors.abstract_connector import AbstractMinimalConnector class BookSearch(TestCase): """look for some books""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" self.work = models.Work.objects.create(title="Example Work") diff --git a/bookwyrm/tests/test_context_processors.py b/bookwyrm/tests/test_context_processors.py index 3d634aaf2..614db681c 100644 --- a/bookwyrm/tests/test_context_processors.py +++ b/bookwyrm/tests/test_context_processors.py @@ -11,9 +11,9 @@ from bookwyrm.context_processors import site_settings class ContextProcessor(TestCase): """pages you land on without really trying""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -28,6 +28,10 @@ class ContextProcessor(TestCase): self.anonymous_user.is_authenticated = False self.site = models.SiteSettings.objects.create() + def setUp(self): + """other test data""" + self.factory = RequestFactory() + def test_theme_unset(self): """logged in user, no selected theme""" request = self.factory.get("") diff --git a/bookwyrm/tests/test_emailing.py b/bookwyrm/tests/test_emailing.py index b2af59f4f..119941e85 100644 --- a/bookwyrm/tests/test_emailing.py +++ b/bookwyrm/tests/test_emailing.py @@ -11,10 +11,9 @@ from bookwyrm import emailing, models class Emailing(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -27,6 +26,10 @@ class Emailing(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """other test data""" + self.factory = RequestFactory() + def test_invite_email(self, email_mock): """load the invite email""" invite_request = models.InviteRequest.objects.create( diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index d61c32df5..b539f089b 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -35,8 +35,8 @@ Sender = namedtuple("Sender", ("remote_id", "key_pair")) class Signature(TestCase): """signature test""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """create users and test data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -54,15 +54,15 @@ class Signature(TestCase): self.cat = models.User.objects.create_user( f"cat@{DOMAIN}", "cat@example.com", "", local=True, localname="cat" ) + models.SiteSettings.objects.create() + def setUp(self): + """test data""" private_key, public_key = create_key_pair() - self.fake_remote = Sender( "http://localhost/user/remote", KeyPair(private_key, public_key) ) - models.SiteSettings.objects.create() - def send(self, signature, now, data, digest): """test request""" client = Client() diff --git a/bookwyrm/tests/views/admin/test_announcements.py b/bookwyrm/tests/views/admin/test_announcements.py index 94f748482..30bc94a1f 100644 --- a/bookwyrm/tests/views/admin/test_announcements.py +++ b/bookwyrm/tests/views/admin/test_announcements.py @@ -11,9 +11,9 @@ from bookwyrm.tests.validate_html import validate_html class AnnouncementViews(TestCase): """every response to a get request, html or json""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -27,6 +27,10 @@ class AnnouncementViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_announcements_page(self): """there are so many views, this just makes sure it LOADS""" models.Announcement.objects.create(preview="hi", user=self.local_user) diff --git a/bookwyrm/tests/views/admin/test_automod.py b/bookwyrm/tests/views/admin/test_automod.py index a1c03d436..1835a24ee 100644 --- a/bookwyrm/tests/views/admin/test_automod.py +++ b/bookwyrm/tests/views/admin/test_automod.py @@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class AutomodViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -35,6 +34,10 @@ class AutomodViews(TestCase): self.local_user.groups.set([group]) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_automod_rules_get(self): """there are so many views, this just makes sure it LOADS""" schedule = IntervalSchedule.objects.create(every=1, period="days") diff --git a/bookwyrm/tests/views/admin/test_celery.py b/bookwyrm/tests/views/admin/test_celery.py index f9429c4c0..d215a9657 100644 --- a/bookwyrm/tests/views/admin/test_celery.py +++ b/bookwyrm/tests/views/admin/test_celery.py @@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class CeleryStatusViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +33,10 @@ class CeleryStatusViews(TestCase): self.local_user.groups.set([group]) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_celery_status_get(self): """there are so many views, this just makes sure it LOADS""" view = views.CeleryStatus.as_view() diff --git a/bookwyrm/tests/views/admin/test_dashboard.py b/bookwyrm/tests/views/admin/test_dashboard.py index c36e2918f..8eeb754a8 100644 --- a/bookwyrm/tests/views/admin/test_dashboard.py +++ b/bookwyrm/tests/views/admin/test_dashboard.py @@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class DashboardViews(TestCase): """every response to a get request, html or json""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +34,10 @@ class DashboardViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_dashboard(self): """there are so many views, this just makes sure it LOADS""" view = views.Dashboard.as_view() diff --git a/bookwyrm/tests/views/admin/test_email_blocks.py b/bookwyrm/tests/views/admin/test_email_blocks.py index 3c0f548e6..75c0be929 100644 --- a/bookwyrm/tests/views/admin/test_email_blocks.py +++ b/bookwyrm/tests/views/admin/test_email_blocks.py @@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class EmailBlocklistViews(TestCase): """every response to a get request, html or json""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +34,10 @@ class EmailBlocklistViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_blocklist_page_get(self): """there are so many views, this just makes sure it LOADS""" view = views.EmailBlocklist.as_view() diff --git a/bookwyrm/tests/views/admin/test_email_config.py b/bookwyrm/tests/views/admin/test_email_config.py index 3aa16cb1d..63d85cbef 100644 --- a/bookwyrm/tests/views/admin/test_email_config.py +++ b/bookwyrm/tests/views/admin/test_email_config.py @@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class EmailConfigViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +33,10 @@ class EmailConfigViews(TestCase): self.local_user.groups.set([group]) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_email_config_get(self): """there are so many views, this just makes sure it LOADS""" view = views.EmailConfig.as_view() diff --git a/bookwyrm/tests/views/admin/test_federation.py b/bookwyrm/tests/views/admin/test_federation.py index 95b3225d5..1a5067299 100644 --- a/bookwyrm/tests/views/admin/test_federation.py +++ b/bookwyrm/tests/views/admin/test_federation.py @@ -17,10 +17,9 @@ from bookwyrm.tests.validate_html import validate_html class FederationViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -48,6 +47,10 @@ class FederationViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_federation_page(self): """there are so many views, this just makes sure it LOADS""" view = views.Federation.as_view() diff --git a/bookwyrm/tests/views/admin/test_imports.py b/bookwyrm/tests/views/admin/test_imports.py index eaa9fd84a..5a5599519 100644 --- a/bookwyrm/tests/views/admin/test_imports.py +++ b/bookwyrm/tests/views/admin/test_imports.py @@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class ImportsAdminViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +33,10 @@ class ImportsAdminViews(TestCase): self.local_user.groups.set([group]) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_celery_status_get(self): """there are so many views, this just makes sure it LOADS""" view = views.ImportList.as_view() diff --git a/bookwyrm/tests/views/admin/test_ip_blocklist.py b/bookwyrm/tests/views/admin/test_ip_blocklist.py index a15a4d368..06c110a06 100644 --- a/bookwyrm/tests/views/admin/test_ip_blocklist.py +++ b/bookwyrm/tests/views/admin/test_ip_blocklist.py @@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class IPBlocklistViews(TestCase): """every response to a get request, html or json""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +34,10 @@ class IPBlocklistViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_blocklist_page_get(self): """there are so many views, this just makes sure it LOADS""" view = views.IPBlocklist.as_view() diff --git a/bookwyrm/tests/views/admin/test_link_domains.py b/bookwyrm/tests/views/admin/test_link_domains.py index 5b2b8e025..14eed419b 100644 --- a/bookwyrm/tests/views/admin/test_link_domains.py +++ b/bookwyrm/tests/views/admin/test_link_domains.py @@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class LinkDomainViews(TestCase): """every response to a get request, html or json""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -41,6 +41,10 @@ class LinkDomainViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_domain_page_get(self): """there are so many views, this just makes sure it LOADS""" view = views.LinkDomain.as_view() diff --git a/bookwyrm/tests/views/admin/test_reports.py b/bookwyrm/tests/views/admin/test_reports.py index a74e8b0e1..4334eeed9 100644 --- a/bookwyrm/tests/views/admin/test_reports.py +++ b/bookwyrm/tests/views/admin/test_reports.py @@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class ReportViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -42,6 +41,10 @@ class ReportViews(TestCase): self.local_user.groups.set([group]) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_reports_page(self): """there are so many views, this just makes sure it LOADS""" view = views.ReportsAdmin.as_view() diff --git a/bookwyrm/tests/views/admin/test_site.py b/bookwyrm/tests/views/admin/test_site.py index 8eda6a2fb..b7c687e09 100644 --- a/bookwyrm/tests/views/admin/test_site.py +++ b/bookwyrm/tests/views/admin/test_site.py @@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class SiteSettingsViews(TestCase): """Edit site settings""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -35,6 +34,10 @@ class SiteSettingsViews(TestCase): self.site = models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_site_get(self): """there are so many views, this just makes sure it LOADS""" view = views.Site.as_view() diff --git a/bookwyrm/tests/views/admin/test_themes.py b/bookwyrm/tests/views/admin/test_themes.py index 296cd4d8d..66384f5fc 100644 --- a/bookwyrm/tests/views/admin/test_themes.py +++ b/bookwyrm/tests/views/admin/test_themes.py @@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class AdminThemesViews(TestCase): """Edit site settings""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -43,6 +42,10 @@ class AdminThemesViews(TestCase): self.site = models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_themes_get(self): """there are so many views, this just makes sure it LOADS""" view = views.Themes.as_view() diff --git a/bookwyrm/tests/views/admin/test_user_admin.py b/bookwyrm/tests/views/admin/test_user_admin.py index 1d11c7338..99c630526 100644 --- a/bookwyrm/tests/views/admin/test_user_admin.py +++ b/bookwyrm/tests/views/admin/test_user_admin.py @@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class UserAdminViews(TestCase): """every response to a get request, html or json""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +34,10 @@ class UserAdminViews(TestCase): self.local_user.groups.set([group]) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_user_admin_list_page(self): """there are so many views, this just makes sure it LOADS""" view = views.UserAdminList.as_view() diff --git a/bookwyrm/tests/views/books/test_book.py b/bookwyrm/tests/views/books/test_book.py index a829c4a4b..d1d118ec0 100644 --- a/bookwyrm/tests/views/books/test_book.py +++ b/bookwyrm/tests/views/books/test_book.py @@ -23,9 +23,9 @@ from bookwyrm.tests.validate_html import validate_html class BookViews(TestCase): """books books books""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -54,6 +54,10 @@ class BookViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_book_page(self): """there are so many views, this just makes sure it LOADS""" view = views.Book.as_view() diff --git a/bookwyrm/tests/views/books/test_edit_book.py b/bookwyrm/tests/views/books/test_edit_book.py index 49e8c7cdb..169112bab 100644 --- a/bookwyrm/tests/views/books/test_edit_book.py +++ b/bookwyrm/tests/views/books/test_edit_book.py @@ -19,9 +19,9 @@ from bookwyrm.tests.views.books.test_book import _setup_cover_url class EditBookViews(TestCase): """books books books""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -47,10 +47,13 @@ class EditBookViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() # pylint: disable=line-too-long self.authors_body = "1.10000000084510024" - - # pylint: disable=line-too-long self.author_body = "0000000084510024https://isni.org/isni/000000008451002460Catherine Amy Dawson Scottpoet and novelistpublicVIAFWKPQ544961C. A.Dawson Scott1865-1934publicVIAFNLPa28927850VIAF45886165ALLCREhttp://viaf.org/viaf/45886165Wikipediahttps://en.wikipedia.org/wiki/Catherine_Amy_Dawson_Scott" responses.get( @@ -86,8 +89,6 @@ class EditBookViews(TestCase): body=self.author_body, ) - models.SiteSettings.objects.create() - def test_edit_book_get(self): """there are so many views, this just makes sure it LOADS""" view = views.EditBook.as_view() diff --git a/bookwyrm/tests/views/books/test_editions.py b/bookwyrm/tests/views/books/test_editions.py index 70a95051a..64de34067 100644 --- a/bookwyrm/tests/views/books/test_editions.py +++ b/bookwyrm/tests/views/books/test_editions.py @@ -13,9 +13,9 @@ from bookwyrm.tests.validate_html import validate_html class BookViews(TestCase): """books books books""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -37,6 +37,10 @@ class BookViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_editions_page(self): """there are so many views, this just makes sure it LOADS""" view = views.Editions.as_view() diff --git a/bookwyrm/tests/views/books/test_links.py b/bookwyrm/tests/views/books/test_links.py index bace38b7e..817463656 100644 --- a/bookwyrm/tests/views/books/test_links.py +++ b/bookwyrm/tests/views/books/test_links.py @@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class LinkViews(TestCase): """books books books""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ): @@ -49,6 +48,10 @@ class LinkViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_add_link_page(self): """there are so many views, this just makes sure it LOADS""" view = views.AddFileLink.as_view() diff --git a/bookwyrm/tests/views/imports/test_import.py b/bookwyrm/tests/views/imports/test_import.py index 7dd87d4c2..d0612ee68 100644 --- a/bookwyrm/tests/views/imports/test_import.py +++ b/bookwyrm/tests/views/imports/test_import.py @@ -16,10 +16,9 @@ from bookwyrm.tests.validate_html import validate_html class ImportViews(TestCase): """goodreads import views""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -32,6 +31,10 @@ class ImportViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_import_page(self): """there are so many views, this just makes sure it LOADS""" view = views.Import.as_view() diff --git a/bookwyrm/tests/views/imports/test_import_review.py b/bookwyrm/tests/views/imports/test_import_review.py index 92839be6d..27bb3f9d1 100644 --- a/bookwyrm/tests/views/imports/test_import_review.py +++ b/bookwyrm/tests/views/imports/test_import_review.py @@ -11,10 +11,9 @@ from bookwyrm import models, views class ImportManualReviewViews(TestCase): """goodreads import views""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -35,6 +34,10 @@ class ImportManualReviewViews(TestCase): parent_work=work, ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_import_troubleshoot_get(self): """there are so many views, this just makes sure it LOADS""" view = views.ImportManualReview.as_view() diff --git a/bookwyrm/tests/views/imports/test_import_troubleshoot.py b/bookwyrm/tests/views/imports/test_import_troubleshoot.py index a40e96118..0e12c406a 100644 --- a/bookwyrm/tests/views/imports/test_import_troubleshoot.py +++ b/bookwyrm/tests/views/imports/test_import_troubleshoot.py @@ -12,10 +12,9 @@ from bookwyrm import models, views class ImportTroubleshootViews(TestCase): """goodreads import views""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -28,6 +27,10 @@ class ImportTroubleshootViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_import_troubleshoot_get(self): """there are so many views, this just makes sure it LOADS""" view = views.ImportTroubleshoot.as_view() diff --git a/bookwyrm/tests/views/inbox/test_inbox.py b/bookwyrm/tests/views/inbox/test_inbox.py index 61acde5d3..1c05806a5 100644 --- a/bookwyrm/tests/views/inbox/test_inbox.py +++ b/bookwyrm/tests/views/inbox/test_inbox.py @@ -15,12 +15,22 @@ from bookwyrm import models, views class Inbox(TestCase): """readthrough tests""" - # pylint: disable=invalid-name def setUp(self): - """basic user and book data""" + """individual test setup""" self.client = Client() self.factory = RequestFactory() + self.create_json = { + "id": "hi", + "type": "Create", + "actor": "hi", + "to": ["https://www.w3.org/ns/activitystreams#public"], + "cc": ["https://example.com/user/mouse/followers"], + "object": {}, + } + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument + """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -43,14 +53,6 @@ class Inbox(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - self.create_json = { - "id": "hi", - "type": "Create", - "actor": "hi", - "to": ["https://www.w3.org/ns/activitystreams#public"], - "cc": ["https://example.com/user/mouse/followers"], - "object": {}, - } models.SiteSettings.objects.create() def test_inbox_invalid_get(self): diff --git a/bookwyrm/tests/views/inbox/test_inbox_add.py b/bookwyrm/tests/views/inbox/test_inbox_add.py index fccd1a50f..5fbeaa33a 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_add.py +++ b/bookwyrm/tests/views/inbox/test_inbox_add.py @@ -11,7 +11,8 @@ from bookwyrm import models, views class InboxAdd(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/views/inbox/test_inbox_announce.py b/bookwyrm/tests/views/inbox/test_inbox_announce.py index c77c18bc5..e6fdf9375 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_announce.py +++ b/bookwyrm/tests/views/inbox/test_inbox_announce.py @@ -11,7 +11,8 @@ from bookwyrm import models, views class InboxActivities(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -44,6 +45,10 @@ class InboxActivities(TestCase): remote_id="https://example.com/status/1", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" self.create_json = { "id": "hi", "type": "Create", @@ -53,8 +58,6 @@ class InboxActivities(TestCase): "object": {}, } - models.SiteSettings.objects.create() - @patch("bookwyrm.activitystreams.handle_boost_task.delay") def test_boost(self, _): """boost a status""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_block.py b/bookwyrm/tests/views/inbox/test_inbox_block.py index eb73af094..9fef621ea 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_block.py +++ b/bookwyrm/tests/views/inbox/test_inbox_block.py @@ -10,7 +10,8 @@ from bookwyrm import models, views class InboxBlock(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/views/inbox/test_inbox_create.py b/bookwyrm/tests/views/inbox/test_inbox_create.py index f0fb84edf..c2045b092 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_create.py +++ b/bookwyrm/tests/views/inbox/test_inbox_create.py @@ -9,7 +9,7 @@ from bookwyrm import models, views from bookwyrm.activitypub import ActivitySerializerError -# pylint: disable=too-many-public-methods, invalid-name +# pylint: disable=too-many-public-methods class TransactionInboxCreate(TransactionTestCase): """readthrough tests""" @@ -71,7 +71,8 @@ class TransactionInboxCreate(TransactionTestCase): class InboxCreate(TestCase): """readthrough tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -96,6 +97,10 @@ class InboxCreate(TestCase): outbox="https://example.com/users/rat/outbox", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" self.create_json = { "id": "hi", "type": "Create", @@ -104,7 +109,6 @@ class InboxCreate(TestCase): "cc": ["https://example.com/user/mouse/followers"], "object": {}, } - models.SiteSettings.objects.create() def test_create_status(self, *_): """the "it justs works" mode""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 7b4c12564..8023308be 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -11,8 +11,8 @@ from bookwyrm import models, views class InboxActivities(TestCase): """inbox tests""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/views/inbox/test_inbox_follow.py b/bookwyrm/tests/views/inbox/test_inbox_follow.py index 13e46ff8d..180a57176 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_follow.py +++ b/bookwyrm/tests/views/inbox/test_inbox_follow.py @@ -11,7 +11,8 @@ from bookwyrm import models, views class InboxRelationships(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/views/inbox/test_inbox_like.py b/bookwyrm/tests/views/inbox/test_inbox_like.py index ea4d4a65a..34c8c830b 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_like.py +++ b/bookwyrm/tests/views/inbox/test_inbox_like.py @@ -10,7 +10,8 @@ from bookwyrm import models, views class InboxActivities(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -43,6 +44,10 @@ class InboxActivities(TestCase): remote_id="https://example.com/status/1", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" self.create_json = { "id": "hi", "type": "Create", @@ -52,8 +57,6 @@ class InboxActivities(TestCase): "object": {}, } - models.SiteSettings.objects.create() - def test_handle_favorite(self): """fav a status""" activity = { diff --git a/bookwyrm/tests/views/inbox/test_inbox_remove.py b/bookwyrm/tests/views/inbox/test_inbox_remove.py index d7b3f6778..d80a4fdd7 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_remove.py +++ b/bookwyrm/tests/views/inbox/test_inbox_remove.py @@ -10,7 +10,8 @@ from bookwyrm import models, views class InboxRemove(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index e8593c2be..b9f924bad 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -12,7 +12,8 @@ from bookwyrm import models, views class InboxUpdate(TestCase): """inbox tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -37,6 +38,10 @@ class InboxUpdate(TestCase): outbox="https://example.com/users/rat/outbox", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" self.update_json = { "id": "hi", "type": "Update", @@ -46,8 +51,6 @@ class InboxUpdate(TestCase): "object": {}, } - models.SiteSettings.objects.create() - def test_update_list(self): """a new list""" with patch( diff --git a/bookwyrm/tests/views/landing/test_invite.py b/bookwyrm/tests/views/landing/test_invite.py index a96ecb9f2..f7ec73cf4 100644 --- a/bookwyrm/tests/views/landing/test_invite.py +++ b/bookwyrm/tests/views/landing/test_invite.py @@ -14,10 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class InviteViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -30,6 +29,10 @@ class InviteViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_invite_page(self): """there are so many views, this just makes sure it LOADS""" view = views.Invite.as_view() diff --git a/bookwyrm/tests/views/landing/test_landing.py b/bookwyrm/tests/views/landing/test_landing.py index f56eaf7a9..b67857da8 100644 --- a/bookwyrm/tests/views/landing/test_landing.py +++ b/bookwyrm/tests/views/landing/test_landing.py @@ -14,9 +14,9 @@ from bookwyrm.tests.validate_html import validate_html class LandingViews(TestCase): """pages you land on without really trying""" - def setUp(self): # pylint: disable=invalid-name + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -27,9 +27,13 @@ class LandingViews(TestCase): local=True, localname="mouse", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create() @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") def test_home_page(self, _): diff --git a/bookwyrm/tests/views/landing/test_login.py b/bookwyrm/tests/views/landing/test_login.py index eab082609..19ad1d2a0 100644 --- a/bookwyrm/tests/views/landing/test_login.py +++ b/bookwyrm/tests/views/landing/test_login.py @@ -17,10 +17,9 @@ from bookwyrm.tests.validate_html import validate_html class LoginViews(TestCase): """login and password management""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -47,9 +46,13 @@ class LoginViews(TestCase): localname="badger", two_factor_auth=True, ) + models.SiteSettings.objects.create(id=1, require_confirm_email=False) + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create(id=1, require_confirm_email=False) def test_login_get(self, *_): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/landing/test_password.py b/bookwyrm/tests/views/landing/test_password.py index c1adf61e9..ceceeb3e4 100644 --- a/bookwyrm/tests/views/landing/test_password.py +++ b/bookwyrm/tests/views/landing/test_password.py @@ -16,9 +16,9 @@ from bookwyrm.tests.validate_html import validate_html class PasswordViews(TestCase): """view user and edit profile""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -29,9 +29,13 @@ class PasswordViews(TestCase): local=True, localname="mouse", ) + models.SiteSettings.objects.create(id=1) + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create(id=1) def test_password_reset_request(self): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/landing/test_register.py b/bookwyrm/tests/views/landing/test_register.py index 04f3a25ec..381a35a32 100644 --- a/bookwyrm/tests/views/landing/test_register.py +++ b/bookwyrm/tests/views/landing/test_register.py @@ -20,10 +20,9 @@ from bookwyrm.tests.validate_html import validate_html class RegisterViews(TestCase): """login and password management""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,13 +33,16 @@ class RegisterViews(TestCase): local=True, localname="mouse", ) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False - self.settings = models.SiteSettings.objects.create( id=1, require_confirm_email=False, allow_registration=True ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + def test_get_redirect(self, *_): """there's no dedicated registration page""" view = views.Register.as_view() diff --git a/bookwyrm/tests/views/lists/test_curate.py b/bookwyrm/tests/views/lists/test_curate.py index 9f3427b2c..7fa48f915 100644 --- a/bookwyrm/tests/views/lists/test_curate.py +++ b/bookwyrm/tests/views/lists/test_curate.py @@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class ListViews(TestCase): """list view""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -42,11 +42,15 @@ class ListViews(TestCase): self.list = models.List.objects.create( name="Test List", user=self.local_user ) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + def test_curate_page(self): """there are so many views, this just makes sure it LOADS""" view = views.Curate.as_view() diff --git a/bookwyrm/tests/views/lists/test_embed.py b/bookwyrm/tests/views/lists/test_embed.py index 4191ffe0d..40c51f5df 100644 --- a/bookwyrm/tests/views/lists/test_embed.py +++ b/bookwyrm/tests/views/lists/test_embed.py @@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class ListViews(TestCase): """list view""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -42,11 +42,15 @@ class ListViews(TestCase): self.list = models.List.objects.create( name="Test List", user=self.local_user ) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + def test_embed_call_without_key(self): """there are so many views, this just makes sure it DOESN’T load""" view = views.unsafe_embed_list diff --git a/bookwyrm/tests/views/lists/test_list.py b/bookwyrm/tests/views/lists/test_list.py index 98b0a461a..b1e7e2acc 100644 --- a/bookwyrm/tests/views/lists/test_list.py +++ b/bookwyrm/tests/views/lists/test_list.py @@ -18,9 +18,9 @@ from bookwyrm.tests.validate_html import validate_html class ListViews(TestCase): """list view""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -71,11 +71,15 @@ class ListViews(TestCase): self.list = models.List.objects.create( name="Test List", user=self.local_user ) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + def test_list_page(self): """there are so many views, this just makes sure it LOADS""" view = views.List.as_view() diff --git a/bookwyrm/tests/views/lists/test_list_item.py b/bookwyrm/tests/views/lists/test_list_item.py index b95282bef..ebdbdbc2e 100644 --- a/bookwyrm/tests/views/lists/test_list_item.py +++ b/bookwyrm/tests/views/lists/test_list_item.py @@ -12,9 +12,9 @@ from bookwyrm import models, views class ListItemViews(TestCase): """list view""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -41,6 +41,10 @@ class ListItemViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_add_list_item_notes(self): """there are so many views, this just makes sure it LOADS""" view = views.ListItem.as_view() diff --git a/bookwyrm/tests/views/lists/test_lists.py b/bookwyrm/tests/views/lists/test_lists.py index 38a97c412..0d2213ee7 100644 --- a/bookwyrm/tests/views/lists/test_lists.py +++ b/bookwyrm/tests/views/lists/test_lists.py @@ -15,10 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class ListViews(TestCase): """lists of lists""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -33,11 +32,15 @@ class ListViews(TestCase): self.another_user = models.User.objects.create_user( "rat@local.com", "rat@rat.com", "ratword", local=True, localname="rat" ) - self.anonymous_user = AnonymousUser - self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False + @patch("bookwyrm.lists_stream.ListsStream.get_list_stream") def test_lists_page(self, _): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/preferences/test_block.py b/bookwyrm/tests/views/preferences/test_block.py index 46de8f48e..86ef95e7e 100644 --- a/bookwyrm/tests/views/preferences/test_block.py +++ b/bookwyrm/tests/views/preferences/test_block.py @@ -13,9 +13,9 @@ from bookwyrm.tests.validate_html import validate_html class BlockViews(TestCase): """view user and edit profile""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -39,6 +39,10 @@ class BlockViews(TestCase): models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_block_get(self, _): """there are so many views, this just makes sure it LOADS""" view = views.Block.as_view() diff --git a/bookwyrm/tests/views/preferences/test_change_password.py b/bookwyrm/tests/views/preferences/test_change_password.py index 879ffd03d..49eac998c 100644 --- a/bookwyrm/tests/views/preferences/test_change_password.py +++ b/bookwyrm/tests/views/preferences/test_change_password.py @@ -12,9 +12,9 @@ from bookwyrm.tests.validate_html import validate_html class ChangePasswordViews(TestCase): """view user and edit profile""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -27,6 +27,10 @@ class ChangePasswordViews(TestCase): ) models.SiteSettings.objects.create(id=1) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_password_change_get(self): """there are so many views, this just makes sure it LOADS""" view = views.ChangePassword.as_view() diff --git a/bookwyrm/tests/views/preferences/test_delete_user.py b/bookwyrm/tests/views/preferences/test_delete_user.py index 1994a5a4d..d97ef0d38 100644 --- a/bookwyrm/tests/views/preferences/test_delete_user.py +++ b/bookwyrm/tests/views/preferences/test_delete_user.py @@ -16,10 +16,9 @@ from bookwyrm.tests.validate_html import validate_html class DeleteUserViews(TestCase): """view user and edit profile""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -50,9 +49,13 @@ class DeleteUserViews(TestCase): shelf=self.local_user.shelf_set.first(), ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create() def test_delete_user_page(self, _): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/preferences/test_edit_user.py b/bookwyrm/tests/views/preferences/test_edit_user.py index 11d333406..1ed4e3240 100644 --- a/bookwyrm/tests/views/preferences/test_edit_user.py +++ b/bookwyrm/tests/views/preferences/test_edit_user.py @@ -18,9 +18,9 @@ from bookwyrm.tests.validate_html import validate_html class EditUserViews(TestCase): """view user and edit profile""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -48,6 +48,10 @@ class EditUserViews(TestCase): ) models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index fbc55a9e3..4f498f589 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -17,9 +17,9 @@ from bookwyrm.tests.validate_html import validate_html class ExportViews(TestCase): """viewing and creating statuses""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ): @@ -40,6 +40,10 @@ class ExportViews(TestCase): bnf_id="beep", ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def tst_export_get(self, *_): """request export""" request = self.factory.get("") diff --git a/bookwyrm/tests/views/preferences/test_two_factor_auth.py b/bookwyrm/tests/views/preferences/test_two_factor_auth.py index ac6bd654c..dbd9c1f5b 100644 --- a/bookwyrm/tests/views/preferences/test_two_factor_auth.py +++ b/bookwyrm/tests/views/preferences/test_two_factor_auth.py @@ -17,9 +17,9 @@ from bookwyrm import forms, models, views class TwoFactorViews(TestCase): """Two Factor Authentication management""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +34,10 @@ class TwoFactorViews(TestCase): hotp_secret="DRMNMOU7ZRKH5YPW7PADOEYUF7MRIH46", hotp_count=0, ) + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False diff --git a/bookwyrm/tests/views/shelf/test_shelf.py b/bookwyrm/tests/views/shelf/test_shelf.py index 9aec632f7..492f214e3 100644 --- a/bookwyrm/tests/views/shelf/test_shelf.py +++ b/bookwyrm/tests/views/shelf/test_shelf.py @@ -20,9 +20,9 @@ from bookwyrm.tests.validate_html import validate_html class ShelfViews(TestCase): """tag views""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -46,6 +46,9 @@ class ShelfViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False diff --git a/bookwyrm/tests/views/shelf/test_shelf_actions.py b/bookwyrm/tests/views/shelf/test_shelf_actions.py index 290232580..eea17b62d 100644 --- a/bookwyrm/tests/views/shelf/test_shelf_actions.py +++ b/bookwyrm/tests/views/shelf/test_shelf_actions.py @@ -18,9 +18,9 @@ from bookwyrm import forms, models, views class ShelfActionViews(TestCase): """tag views""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -52,6 +52,10 @@ class ShelfActionViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_shelve(self, *_): """shelve a book""" request = self.factory.post( diff --git a/bookwyrm/tests/views/test_annual_summary.py b/bookwyrm/tests/views/test_annual_summary.py index aaba0aac6..d51060a72 100644 --- a/bookwyrm/tests/views/test_annual_summary.py +++ b/bookwyrm/tests/views/test_annual_summary.py @@ -21,10 +21,9 @@ def make_date(*args): class AnnualSummary(TestCase): """views""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -44,13 +43,15 @@ class AnnualSummary(TestCase): parent_work=self.work, pages=300, ) + models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.year = "2020" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - self.year = "2020" - models.SiteSettings.objects.create() - def test_annual_summary_not_authenticated(self, *_): """there are so many views, this just makes sure it DOESN’T LOAD""" view = views.AnnualSummary.as_view() diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index 1f8fc51c5..669149af2 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -16,9 +16,9 @@ from bookwyrm.tests.validate_html import validate_html class AuthorViews(TestCase): """author views""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -44,10 +44,13 @@ class AuthorViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, ) + models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create() def test_author_page(self): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/test_directory.py b/bookwyrm/tests/views/test_directory.py index bceb0e7aa..7e9e97522 100644 --- a/bookwyrm/tests/views/test_directory.py +++ b/bookwyrm/tests/views/test_directory.py @@ -13,9 +13,9 @@ from bookwyrm.tests.validate_html import validate_html class DirectoryViews(TestCase): """tag views""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -27,8 +27,11 @@ class DirectoryViews(TestCase): localname="mouse", remote_id="https://example.com/users/mouse", ) - models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False diff --git a/bookwyrm/tests/views/test_discover.py b/bookwyrm/tests/views/test_discover.py index ffe8c51c9..9aa139074 100644 --- a/bookwyrm/tests/views/test_discover.py +++ b/bookwyrm/tests/views/test_discover.py @@ -11,10 +11,9 @@ from bookwyrm.tests.validate_html import validate_html class DiscoverViews(TestCase): """pages you land on without really trying""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -25,9 +24,13 @@ class DiscoverViews(TestCase): local=True, localname="mouse", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create() def test_discover_page_empty(self): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index 99b2a396b..33dbd4ea5 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -24,9 +24,9 @@ from bookwyrm.tests.validate_html import validate_html class FeedViews(TestCase): """activity feed, statuses, dms""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -51,6 +51,10 @@ class FeedViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") def test_feed(self, *_): """there are so many views, this just makes sure it LOADS""" diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index d18e24f89..1a311b413 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -17,10 +17,10 @@ from bookwyrm.tests.validate_html import validate_html class FollowViews(TestCase): """follows""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" models.SiteSettings.objects.create() - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -57,6 +57,10 @@ class FollowViews(TestCase): parent_work=self.work, ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_handle_follow_remote(self, *_): """send a follow request""" request = self.factory.post("", {"user": self.remote_user.username}) diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 28b6a4d36..84a49cafc 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -12,9 +12,9 @@ from bookwyrm.tests.validate_html import validate_html class GetStartedViews(TestCase): """helping new users get oriented""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -39,6 +39,10 @@ class GetStartedViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_profile_view(self, *_): """there are so many views, this just makes sure it LOADS""" view = views.GetStartedProfile.as_view() diff --git a/bookwyrm/tests/views/test_goal.py b/bookwyrm/tests/views/test_goal.py index 0faeef117..3d87d8538 100644 --- a/bookwyrm/tests/views/test_goal.py +++ b/bookwyrm/tests/views/test_goal.py @@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class GoalViews(TestCase): """viewing and creating statuses""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -41,10 +41,14 @@ class GoalViews(TestCase): title="Example Edition", remote_id="https://example.com/book/1", ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.year = timezone.now().year + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - self.year = timezone.now().year - models.SiteSettings.objects.create() def test_goal_page_no_goal(self): """view a reading goal page for another's unset goal""" diff --git a/bookwyrm/tests/views/test_group.py b/bookwyrm/tests/views/test_group.py index 60fca6cb7..4d678c31a 100644 --- a/bookwyrm/tests/views/test_group.py +++ b/bookwyrm/tests/views/test_group.py @@ -16,9 +16,9 @@ from bookwyrm.tests.validate_html import validate_html class GroupViews(TestCase): """view group and edit details""" - def setUp(self): # pylint: disable=invalid-name + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -46,11 +46,14 @@ class GroupViews(TestCase): self.membership = models.GroupMember.objects.create( group=self.testgroup, user=self.local_user ) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create() - def test_group_get(self, _): """there are so many views, this just makes sure it LOADS""" view = views.Group.as_view() diff --git a/bookwyrm/tests/views/test_hashtag.py b/bookwyrm/tests/views/test_hashtag.py index d3115dbce..1c8b31dce 100644 --- a/bookwyrm/tests/views/test_hashtag.py +++ b/bookwyrm/tests/views/test_hashtag.py @@ -14,8 +14,8 @@ from bookwyrm.tests.validate_html import validate_html class HashtagView(TestCase): """hashtag view""" - def setUp(self): - self.factory = RequestFactory() + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -64,9 +64,13 @@ class HashtagView(TestCase): for status in self.statuses_bookclub: status.mention_hashtags.add(self.hashtag_bookclub) + models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False - models.SiteSettings.objects.create() def test_hashtag_page(self): """just make sure it loads""" diff --git a/bookwyrm/tests/views/test_helpers.py b/bookwyrm/tests/views/test_helpers.py index dd30526ec..9472cf762 100644 --- a/bookwyrm/tests/views/test_helpers.py +++ b/bookwyrm/tests/views/test_helpers.py @@ -15,13 +15,12 @@ from bookwyrm.settings import USER_AGENT, DOMAIN @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): +class ViewsHelpers(TestCase): # pylint: disable=too-many-public-methods """viewing and creating statuses""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -53,14 +52,18 @@ class ViewsHelpers(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, ) - datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") - self.userdata = json.loads(datafile.read_bytes()) - del self.userdata["icon"] with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): self.shelf = models.Shelf.objects.create( name="Test Shelf", identifier="test-shelf", user=self.local_user ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json") + self.userdata = json.loads(datafile.read_bytes()) + del self.userdata["icon"] + 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) diff --git a/bookwyrm/tests/views/test_interaction.py b/bookwyrm/tests/views/test_interaction.py index 74878df7d..1565b96a8 100644 --- a/bookwyrm/tests/views/test_interaction.py +++ b/bookwyrm/tests/views/test_interaction.py @@ -12,9 +12,9 @@ from bookwyrm import models, views class InteractionViews(TestCase): """viewing and creating statuses""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -36,7 +36,6 @@ class InteractionViews(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Example Edition", @@ -44,6 +43,10 @@ class InteractionViews(TestCase): parent_work=work, ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_favorite(self, *_): """create and broadcast faving a status""" view = views.Favorite.as_view() diff --git a/bookwyrm/tests/views/test_isbn.py b/bookwyrm/tests/views/test_isbn.py index e09379418..ca451bef8 100644 --- a/bookwyrm/tests/views/test_isbn.py +++ b/bookwyrm/tests/views/test_isbn.py @@ -14,9 +14,9 @@ from bookwyrm.settings import DOMAIN class IsbnViews(TestCase): """tag views""" - def setUp(self): # pylint: disable=invalid-name + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -37,6 +37,10 @@ class IsbnViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_isbn_json_response(self): """searches local data only and returns book data in json format""" view = views.Isbn.as_view() diff --git a/bookwyrm/tests/views/test_notifications.py b/bookwyrm/tests/views/test_notifications.py index 8e5dfa2b5..8d239d77a 100644 --- a/bookwyrm/tests/views/test_notifications.py +++ b/bookwyrm/tests/views/test_notifications.py @@ -12,9 +12,9 @@ from bookwyrm.tests.validate_html import validate_html class NotificationViews(TestCase): """notifications""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -34,6 +34,10 @@ class NotificationViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_notifications_page_empty(self): """there are so many views, this just makes sure it LOADS""" view = views.Notifications.as_view() diff --git a/bookwyrm/tests/views/test_outbox.py b/bookwyrm/tests/views/test_outbox.py index 598cce514..78c4d0edc 100644 --- a/bookwyrm/tests/views/test_outbox.py +++ b/bookwyrm/tests/views/test_outbox.py @@ -15,9 +15,9 @@ from bookwyrm.settings import USER_AGENT class OutboxView(TestCase): """sends out activities""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we'll need some data""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -36,6 +36,10 @@ class OutboxView(TestCase): parent_work=work, ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_outbox(self, _): """returns user's statuses""" request = self.factory.get("") diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py index 759866947..fab1c1fc9 100644 --- a/bookwyrm/tests/views/test_reading.py +++ b/bookwyrm/tests/views/test_reading.py @@ -15,9 +15,9 @@ from bookwyrm import models, views class ReadingViews(TestCase): """viewing and creating statuses""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -46,6 +46,10 @@ class ReadingViews(TestCase): parent_work=self.work, ) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_start_reading(self, *_): """begin a book""" shelf = self.local_user.shelf_set.get(identifier=models.Shelf.READING) diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index f4ca3af61..4f5b1e478 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -15,10 +15,9 @@ from bookwyrm import models class ReadThrough(TestCase): """readthrough tests""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """basic user and book data""" - self.client = Client() - self.work = models.Work.objects.create(title="Example Work") self.edition = models.Edition.objects.create( @@ -32,6 +31,9 @@ class ReadThrough(TestCase): "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" ) + def setUp(self): + """individual test setup""" + self.client = Client() with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): self.client.force_login(self.user) diff --git a/bookwyrm/tests/views/test_report.py b/bookwyrm/tests/views/test_report.py index 487b02929..3e4c64f68 100644 --- a/bookwyrm/tests/views/test_report.py +++ b/bookwyrm/tests/views/test_report.py @@ -11,10 +11,9 @@ from bookwyrm.tests.validate_html import validate_html class ReportViews(TestCase): """every response to a get request, html or json""" - # pylint: disable=invalid-name - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -41,6 +40,10 @@ class ReportViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_report_modal_view(self): """a user reports another user""" request = self.factory.get("") diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index cfbec3360..a63bdea94 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -12,7 +12,8 @@ from bookwyrm.views import rss_feed class RssFeedView(TestCase): """rss feed behaves as expected""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -25,10 +26,12 @@ class RssFeedView(TestCase): remote_id="https://example.com/book/1", parent_work=work, ) - self.factory = RequestFactory() - models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_rss_empty(self, *_): """load an rss feed""" view = rss_feed.RssFeed() diff --git a/bookwyrm/tests/views/test_search.py b/bookwyrm/tests/views/test_search.py index 28f8268e3..425b96cd3 100644 --- a/bookwyrm/tests/views/test_search.py +++ b/bookwyrm/tests/views/test_search.py @@ -17,9 +17,9 @@ from bookwyrm.tests.validate_html import validate_html class Views(TestCase): """tag views""" - def setUp(self): # pylint: disable=invalid-name + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -39,6 +39,10 @@ class Views(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_search_json_response(self): """searches local data only and returns book data in json format""" view = views.Search.as_view() diff --git a/bookwyrm/tests/views/test_setup.py b/bookwyrm/tests/views/test_setup.py index 7b8da3c33..d2bdba340 100644 --- a/bookwyrm/tests/views/test_setup.py +++ b/bookwyrm/tests/views/test_setup.py @@ -13,11 +13,15 @@ from bookwyrm.tests.validate_html import validate_html class SetupViews(TestCase): """activity feed, statuses, dms""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() self.site = models.SiteSettings.objects.create(install_mode=True) + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_instance_config_permission_denied(self): """there are so many views, this just makes sure it LOADS""" self.site.install_mode = False diff --git a/bookwyrm/tests/views/test_status.py b/bookwyrm/tests/views/test_status.py index 424698130..7b0c39338 100644 --- a/bookwyrm/tests/views/test_status.py +++ b/bookwyrm/tests/views/test_status.py @@ -11,7 +11,7 @@ from bookwyrm.settings import DOMAIN from bookwyrm.tests.validate_html import validate_html -# pylint: disable=invalid-name + @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") class StatusTransactions(TransactionTestCase): """Test full database transactions""" @@ -74,9 +74,9 @@ class StatusTransactions(TransactionTestCase): class StatusViews(TestCase): """viewing and creating statuses""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -106,7 +106,6 @@ class StatusViews(TestCase): inbox="https://example.com/users/rat/inbox", outbox="https://example.com/users/rat/outbox", ) - work = models.Work.objects.create(title="Test Work") self.book = models.Edition.objects.create( title="Example Edition", @@ -115,6 +114,10 @@ class StatusViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_create_status_comment(self, *_): """create a status""" view = views.CreateStatus.as_view() @@ -323,14 +326,14 @@ class StatusViews(TestCase): def test_find_mentions_unknown_remote(self, *_): """mention a user that isn't in the database""" - with patch("bookwyrm.views.status.handle_remote_webfinger") as rw: - rw.return_value = self.another_user + with patch("bookwyrm.views.status.handle_remote_webfinger") as rwf: + rwf.return_value = self.another_user result = find_mentions(self.local_user, "@beep@beep.com") self.assertEqual(result["@nutria"], self.another_user) self.assertEqual(result[f"@nutria@{DOMAIN}"], self.another_user) - with patch("bookwyrm.views.status.handle_remote_webfinger") as rw: - rw.return_value = None + with patch("bookwyrm.views.status.handle_remote_webfinger") as rwf: + rwf.return_value = None result = find_mentions(self.local_user, "@beep@beep.com") self.assertEqual(result, {}) diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index 03cf58668..37cb2e6c6 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -12,9 +12,9 @@ from bookwyrm import models, views class UpdateViews(TestCase): """lets the ui check for unread notification""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -27,6 +27,10 @@ class UpdateViews(TestCase): ) models.SiteSettings.objects.create() + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() + def test_get_notification_count(self): """there are so many views, this just makes sure it LOADS""" request = self.factory.get("") diff --git a/bookwyrm/tests/views/test_user.py b/bookwyrm/tests/views/test_user.py index 2b6bc247c..d4e11ff2e 100644 --- a/bookwyrm/tests/views/test_user.py +++ b/bookwyrm/tests/views/test_user.py @@ -15,9 +15,9 @@ from bookwyrm.tests.validate_html import validate_html class UserViews(TestCase): """view user and edit profile""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -44,8 +44,11 @@ class UserViews(TestCase): user=self.local_user, shelf=self.local_user.shelf_set.first(), ) - models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False diff --git a/bookwyrm/tests/views/test_wellknown.py b/bookwyrm/tests/views/test_wellknown.py index 80f5a56ae..4617942fa 100644 --- a/bookwyrm/tests/views/test_wellknown.py +++ b/bookwyrm/tests/views/test_wellknown.py @@ -13,9 +13,9 @@ from bookwyrm import models, views class WellknownViews(TestCase): """view user and edit profile""" - def setUp(self): + @classmethod + def setUpTestData(self): # pylint: disable=bad-classmethod-argument """we need basic test data and mocks""" - self.factory = RequestFactory() with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" ), patch("bookwyrm.lists_stream.populate_lists_task.delay"): @@ -40,6 +40,10 @@ class WellknownViews(TestCase): outbox="https://example.com/users/rat/outbox", ) models.SiteSettings.objects.create() + + def setUp(self): + """individual test setup""" + self.factory = RequestFactory() self.anonymous_user = AnonymousUser self.anonymous_user.is_authenticated = False diff --git a/pytest.ini b/pytest.ini index c5cdc35d1..b50efd602 100644 --- a/pytest.ini +++ b/pytest.ini @@ -6,6 +6,7 @@ markers = integration: marks tests as requiring external resources (deselect with '-m "not integration"') env = + LANGUAGE_CODE = en-US SECRET_KEY = beepbeep DEBUG = false USE_HTTPS = true From aa67f598dd75941acb0fa7e361341869d3c0c0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Mon, 11 Dec 2023 19:40:48 -0300 Subject: [PATCH 16/17] Explicitly set doctype to html5 when invoking tidy_document() Many tests break without this on newer versions of html-tidy. --- bookwyrm/tests/validate_html.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/tests/validate_html.py b/bookwyrm/tests/validate_html.py index 423a86586..85e5c6277 100644 --- a/bookwyrm/tests/validate_html.py +++ b/bookwyrm/tests/validate_html.py @@ -8,6 +8,7 @@ def validate_html(html): _, errors = tidy_document( html.content, options={ + "doctype": "html5", "drop-empty-elements": False, "warn-proprietary-attributes": False, }, From 8bb5a664c53449290c95aa53c82ec96ddc5bd526 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 11 Dec 2023 20:12:14 -0800 Subject: [PATCH 17/17] Fixes incorrect translation and display of moved user page --- bookwyrm/templates/shelf/shelf.html | 15 +-------------- .../templates/snippets/moved_user_notice.html | 12 ++++++++++++ bookwyrm/templates/user/layout.html | 7 +------ 3 files changed, 14 insertions(+), 20 deletions(-) create mode 100644 bookwyrm/templates/snippets/moved_user_notice.html diff --git a/bookwyrm/templates/shelf/shelf.html b/bookwyrm/templates/shelf/shelf.html index a2410ef95..45a94fed9 100644 --- a/bookwyrm/templates/shelf/shelf.html +++ b/bookwyrm/templates/shelf/shelf.html @@ -19,20 +19,7 @@ {% if user.moved_to %} -
    -
    -

    - {% trans "You have have moved to" %} - {% id_to_username user.moved_to %} -

    -

    {% trans "You can undo this move to restore full functionality, but some followers may have already unfollowed this account." %}

    -
    - {% csrf_token %} - - -
    -
    -
    + {% include "snippets/moved_user_notice.html" with user=user %} {% else %}
    {% if user.moved_to %} -
    -
    -

    {{ user.localname }} {% trans "has moved to" %} {% id_to_username user.moved_to %}

    -
    -
    - + {% include "snippets/moved_user_notice.html" with user=user %} {% else %} {% if not is_self and request.user.is_authenticated %} {% include 'snippets/follow_button.html' with user=user %}