Merge branch 'main' into let-a-user-search-within-their-books

This commit is contained in:
Ross Chapman 2023-12-14 10:25:05 -08:00
commit 7cca199a11
151 changed files with 855 additions and 383 deletions

View file

@ -171,9 +171,19 @@ 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"""
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,
):
# Reject the first model that can be built.
obj.reject()
break
@dataclass(init=False)

View file

@ -153,7 +153,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")

View file

@ -1,8 +1,9 @@
""" using django model forms """
from django import forms
from file_resubmit.widgets import ResubmitImageWidget
from bookwyrm import models
from bookwyrm.models.fields import ClearableFileInputWithWarning
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": ResubmitImageWidget(attrs={"aria-describedby": "desc_cover"}),
"physical_format": Select(
attrs={"aria-describedby": "desc_physical_format"}
),

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -99,6 +99,7 @@ INSTALLED_APPS = [
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.humanize",
"file_resubmit",
"sass_processor",
"bookwyrm",
"celery",
@ -119,6 +120,7 @@ MIDDLEWARE = [
"bookwyrm.middleware.IPBlocklistMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"bookwyrm.middleware.FileTooBig",
]
ROOT_URLCONF = "bookwyrm.urls"
@ -242,7 +244,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 = {
@ -252,7 +258,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"

View file

@ -0,0 +1,16 @@
{% extends 'layout.html' %}
{% load i18n %}
{% block title %}{% trans "File too large" %}{% endblock %}
{% block content %}
<div class="block">
<h1 class="title">{% trans "File too large" %}</h1>
<p class="content">{% trans "The file you are uploading is too large." %}</p>
<p class="content">
{% blocktrans %}
You you can try using a smaller file, or ask your BookWyrm server administrator to increase the <code>DATA_UPLOAD_MAX_MEMORY_SIZE</code> setting.
{% endblocktrans %}
</p>
</div>
{% endblock %}

View file

@ -19,20 +19,7 @@
</h1>
</header>
{% if user.moved_to %}
<div class="container my-6">
<div class="notification is-info has-text-centered">
<p>
{% trans "You have have moved to" %}
<a href="{{user.moved_to}}">{% id_to_username user.moved_to %}</a>
</p>
<p> {% trans "You can undo this move to restore full functionality, but some followers may have already unfollowed this account." %}</p>
<form name="remove-alias" action="{% url 'prefs-unmove' %}" method="post">
{% csrf_token %}
<input type="hidden" name="remote_id" id="remote_id" value="{{user.moved_to}}">
<button type="submit" class="button is-small">{% trans "Undo move" %}</button>
</form>
</div>
</div>
{% include "snippets/moved_user_notice.html" with user=user %}
{% else %}
<nav class="breadcrumb subtitle" aria-label="breadcrumbs">
<ul>

View file

@ -43,7 +43,7 @@
</div>
{% if not minimal %}
<div class="control">
{% 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" %}
</div>
{% endif %}
</div>

View file

@ -0,0 +1,12 @@
{% load i18n %}
{% load utilities %}
<div class="container my-6">
<div class="notification is-info has-text-centered">
<p>
{% id_to_username user.moved_to as moved_to_name %}
{% blocktrans trimmed with user=user|username moved_to_link=user.moved_to %}
<em>{{ user }}</em> has moved to <a href="{{ moved_to_link }}">{{ moved_to_name }}</a>
{% endblocktrans %}
</p>
</div>
</div>

View file

@ -0,0 +1,5 @@
{% load i18n %}
<form name="remove" method="post" action="/remove-follow/{{ user.id }}">
{% csrf_token %}
<button class="button is-danger is-light is-small {{ class }}" type="submit">{% trans "Remove" %}</button>
</form>

View file

@ -20,4 +20,9 @@
<li role="menuitem">
{% include 'snippets/block_button.html' with user=user class="is-fullwidth" blocks=False %}
</li>
{% if followers_page %}
<li role="menuitem">
{% include 'snippets/remove_follower_button.html' with user=user class="is-fullwidth" %}
</li>
{% endif %}
{% endblock %}

View file

@ -45,12 +45,7 @@
</div>
<div>
{% if user.moved_to %}
<div class="container my-6">
<div class="notification is-info has-text-centered">
<p><em>{{ user.localname }}</em> {% trans "has moved to" %} <a href="{{user.moved_to}}">{% id_to_username user.moved_to %}</a></p>
</div>
</div>
{% 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 %}

View file

@ -25,6 +25,11 @@
</nav>
{% endblock %}
{% block panel %}
{% with followers_page=True %}
{{ block.super }}
{% endwith %}
{% endblock %}
{% block nullstate %}
<div>

View file

@ -31,7 +31,7 @@
({{ follow.username }})
</div>
<div class="column is-narrow">
{% include 'snippets/follow_button.html' with user=follow %}
{% include 'snippets/follow_button.html' with user=follow followers_page=followers_page %}
</div>
</div>
{% endfor %}

View file

@ -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",

View file

@ -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

View file

@ -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"

View file

@ -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())

View file

@ -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"""

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"""

View file

@ -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"

View file

@ -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)

View file

@ -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"""

View file

@ -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):

View file

@ -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")

View file

@ -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

View file

@ -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")

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"):

View file

@ -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"

View file

@ -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"

View file

@ -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",
@ -391,11 +394,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 +421,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("")

View file

@ -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())

View file

@ -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"""

View file

@ -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"

View file

@ -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(

View file

@ -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):

View file

@ -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")

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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(

View file

@ -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"

View file

@ -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"

View file

@ -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)

View file

@ -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"):

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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()

View file

@ -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"

View file

@ -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"

View file

@ -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")
@ -26,10 +27,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 +77,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"""

View file

@ -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("")

View file

@ -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(

View file

@ -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()

View file

@ -8,6 +8,7 @@ def validate_html(html):
_, errors = tidy_document(
html.content,
options={
"doctype": "html5",
"drop-empty-elements": False,
"warn-proprietary-attributes": False,
},

View file

@ -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)

View file

@ -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")

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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 = "<?xml version='1.0' encoding='UTF-8' ?><?xml-stylesheet type='text/xsl' href='http://isni.oclc.org/sru/DB=1.2/?xsl=searchRetrieveResponse' ?><srw:searchRetrieveResponse xmlns:srw='http://www.loc.gov/zing/srw/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:diag='http://www.loc.gov/zing/srw/diagnostic/' xmlns:xcql='http://www.loc.gov/zing/cql/xcql/'><srw:version>1.1</srw:version><srw:records><srw:record><isniUnformatted>0000000084510024</isniUnformatted></srw:record></srw:records></srw:searchRetrieveResponse>"
# pylint: disable=line-too-long
self.author_body = "<?xml version='1.0' encoding='UTF-8' ?><?xml-stylesheet type='text/xsl' href='http://isni.oclc.org/sru/DB=1.2/?xsl=searchRetrieveResponse' ?><srw:searchRetrieveResponse xmlns:srw='http://www.loc.gov/zing/srw/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:diag='http://www.loc.gov/zing/srw/diagnostic/' xmlns:xcql='http://www.loc.gov/zing/cql/xcql/'><srw:records><srw:record><srw:recordData><responseRecord><ISNIAssigned><isniUnformatted>0000000084510024</isniUnformatted><isniURI>https://isni.org/isni/0000000084510024</isniURI><dataConfidence>60</dataConfidence><ISNIMetadata><identity><personOrFiction><personalName><surname>Catherine Amy Dawson Scott</surname><nameTitle>poet and novelist</nameTitle><nameUse>public</nameUse><source>VIAF</source><source>WKP</source><subsourceIdentifier>Q544961</subsourceIdentifier></personalName><personalName><forename>C. A.</forename><surname>Dawson Scott</surname><marcDate>1865-1934</marcDate><nameUse>public</nameUse><source>VIAF</source><source>NLP</source><subsourceIdentifier>a28927850</subsourceIdentifier></personalName><sources><codeOfSource>VIAF</codeOfSource><sourceIdentifier>45886165</sourceIdentifier><reference><class>ALL</class><role>CRE</role><URI>http://viaf.org/viaf/45886165</URI></reference></sources><externalInformation><information>Wikipedia</information><URI>https://en.wikipedia.org/wiki/Catherine_Amy_Dawson_Scott</URI></externalInformation></ISNIMetadata></ISNIAssigned></responseRecord></srw:recordData></srw:record></srw:records></srw:searchRetrieveResponse>"
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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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):

View file

@ -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"

View file

@ -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"""

View file

@ -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"

View file

@ -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"""

View file

@ -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"

View file

@ -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"

Some files were not shown because too many files have changed in this diff Show more