mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-01 05:51:16 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
a0c1809355
142 changed files with 1670 additions and 1347 deletions
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
|
@ -40,7 +40,7 @@ jobs:
|
|||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
|
@ -51,7 +51,7 @@ jobs:
|
|||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
@ -65,4 +65,4 @@ jobs:
|
|||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
|
|
@ -10,7 +10,6 @@ BookWyrm is a social network for tracking your reading, talking about books, wri
|
|||
## Links
|
||||
|
||||
[![Mastodon Follow](https://img.shields.io/mastodon/follow/000146121?domain=https%3A%2F%2Ftech.lgbt&style=social)](https://tech.lgbt/@bookwyrm)
|
||||
[![Twitter Follow](https://img.shields.io/twitter/follow/BookWyrmSocial?style=social)](https://twitter.com/BookWyrmSocial)
|
||||
|
||||
- [Project homepage](https://joinbookwyrm.com/)
|
||||
- [Support](https://patreon.com/bookwyrm)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 3.2.25 on 2024-04-02 19:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0198_book_search_vector_author_aliases"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name="status",
|
||||
index=models.Index(
|
||||
fields=["remote_id"], name="bookwyrm_st_remote__06aeba_idx"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -260,12 +260,12 @@ class PrivacyField(ActivitypubFieldMixin, models.CharField):
|
|||
|
||||
if to == [self.public]:
|
||||
setattr(instance, self.name, "public")
|
||||
elif self.public in cc:
|
||||
setattr(instance, self.name, "unlisted")
|
||||
elif to == [user.followers_url]:
|
||||
setattr(instance, self.name, "followers")
|
||||
elif cc == []:
|
||||
setattr(instance, self.name, "direct")
|
||||
elif self.public in cc:
|
||||
setattr(instance, self.name, "unlisted")
|
||||
else:
|
||||
setattr(instance, self.name, "followers")
|
||||
return original == getattr(instance, self.name)
|
||||
|
|
|
@ -80,6 +80,9 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
"""default sorting"""
|
||||
|
||||
ordering = ("-published_date",)
|
||||
indexes = [
|
||||
models.Index(fields=["remote_id"]),
|
||||
]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""save and notify"""
|
||||
|
|
|
@ -175,11 +175,13 @@ def generate_instance_layer(content_width):
|
|||
site = models.SiteSettings.objects.get()
|
||||
|
||||
if site.logo_small:
|
||||
logo_img = Image.open(site.logo_small)
|
||||
with Image.open(site.logo_small) as logo_img:
|
||||
logo_img.load()
|
||||
else:
|
||||
try:
|
||||
static_path = os.path.join(settings.STATIC_ROOT, "images/logo-small.png")
|
||||
logo_img = Image.open(static_path)
|
||||
with Image.open(static_path) as logo_img:
|
||||
logo_img.load()
|
||||
except FileNotFoundError:
|
||||
logo_img = None
|
||||
|
||||
|
@ -211,18 +213,9 @@ def generate_instance_layer(content_width):
|
|||
|
||||
def generate_rating_layer(rating, content_width):
|
||||
"""Places components for rating preview"""
|
||||
try:
|
||||
icon_star_full = Image.open(
|
||||
os.path.join(settings.STATIC_ROOT, "images/icons/star-full.png")
|
||||
)
|
||||
icon_star_empty = Image.open(
|
||||
os.path.join(settings.STATIC_ROOT, "images/icons/star-empty.png")
|
||||
)
|
||||
icon_star_half = Image.open(
|
||||
os.path.join(settings.STATIC_ROOT, "images/icons/star-half.png")
|
||||
)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
path_star_full = os.path.join(settings.STATIC_ROOT, "images/icons/star-full.png")
|
||||
path_star_empty = os.path.join(settings.STATIC_ROOT, "images/icons/star-empty.png")
|
||||
path_star_half = os.path.join(settings.STATIC_ROOT, "images/icons/star-half.png")
|
||||
|
||||
icon_size = 64
|
||||
icon_margin = 10
|
||||
|
@ -237,17 +230,23 @@ def generate_rating_layer(rating, content_width):
|
|||
|
||||
position_x = 0
|
||||
|
||||
for _ in range(math.floor(rating)):
|
||||
rating_layer_mask.alpha_composite(icon_star_full, (position_x, 0))
|
||||
position_x = position_x + icon_size + icon_margin
|
||||
try:
|
||||
with Image.open(path_star_full) as icon_star_full:
|
||||
for _ in range(math.floor(rating)):
|
||||
rating_layer_mask.alpha_composite(icon_star_full, (position_x, 0))
|
||||
position_x = position_x + icon_size + icon_margin
|
||||
|
||||
if math.floor(rating) != math.ceil(rating):
|
||||
rating_layer_mask.alpha_composite(icon_star_half, (position_x, 0))
|
||||
position_x = position_x + icon_size + icon_margin
|
||||
if math.floor(rating) != math.ceil(rating):
|
||||
with Image.open(path_star_half) as icon_star_half:
|
||||
rating_layer_mask.alpha_composite(icon_star_half, (position_x, 0))
|
||||
position_x = position_x + icon_size + icon_margin
|
||||
|
||||
for _ in range(5 - math.ceil(rating)):
|
||||
rating_layer_mask.alpha_composite(icon_star_empty, (position_x, 0))
|
||||
position_x = position_x + icon_size + icon_margin
|
||||
with Image.open(path_star_empty) as icon_star_empty:
|
||||
for _ in range(5 - math.ceil(rating)):
|
||||
rating_layer_mask.alpha_composite(icon_star_empty, (position_x, 0))
|
||||
position_x = position_x + icon_size + icon_margin
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
rating_layer_mask = rating_layer_mask.getchannel("A")
|
||||
rating_layer_mask = ImageOps.invert(rating_layer_mask)
|
||||
|
@ -290,7 +289,8 @@ def generate_preview_image(
|
|||
texts = texts or {}
|
||||
# Cover
|
||||
try:
|
||||
inner_img_layer = Image.open(picture)
|
||||
with Image.open(picture) as inner_img_layer:
|
||||
inner_img_layer.load()
|
||||
inner_img_layer.thumbnail(
|
||||
(inner_img_width, inner_img_height), Image.Resampling.LANCZOS
|
||||
)
|
||||
|
|
|
@ -19,7 +19,6 @@ DOMAIN = env("DOMAIN")
|
|||
with open("VERSION", encoding="utf-8") as f:
|
||||
version = f.read()
|
||||
version = version.replace("\n", "")
|
||||
f.close()
|
||||
|
||||
VERSION = version
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ class Author(TestCase):
|
|||
"""serialize author tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""initial data"""
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
self.author = models.Author.objects.create(
|
||||
cls.author = models.Author.objects.create(
|
||||
name="Author fullname",
|
||||
aliases=["One", "Two"],
|
||||
bio="bio bio bio",
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
""" tests the base functionality for activitypub dataclasses """
|
||||
from io import BytesIO
|
||||
import json
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
|
||||
from dataclasses import dataclass
|
||||
from django.test import TestCase
|
||||
from PIL import Image
|
||||
import responses
|
||||
|
||||
from bookwyrm import activitypub
|
||||
|
@ -29,16 +27,18 @@ class BaseActivity(TestCase):
|
|||
"""the super class for model-linked activitypub dataclasses"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
self.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
self.user.remote_id = "http://example.com/a/b"
|
||||
self.user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.user.remote_id = "http://example.com/a/b"
|
||||
cls.user.save(broadcast=False, update_fields=["remote_id"])
|
||||
|
||||
def setUp(self):
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
|
@ -46,13 +46,11 @@ class BaseActivity(TestCase):
|
|||
# don't try to load the user icon
|
||||
del self.userdata["icon"]
|
||||
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
self.image_data = output.getvalue()
|
||||
with open(image_path, "rb") as image_file:
|
||||
self.image_data = image_file.read()
|
||||
|
||||
def test_get_representative_not_existing(self, *_):
|
||||
"""test that an instance representative actor is created if it does not exist"""
|
||||
|
@ -232,10 +230,12 @@ class BaseActivity(TestCase):
|
|||
)
|
||||
|
||||
# sets the celery task call to the function call
|
||||
with patch("bookwyrm.activitypub.base_activity.set_related_field.delay"):
|
||||
with patch("bookwyrm.models.status.Status.ignore_activity") as discarder:
|
||||
discarder.return_value = False
|
||||
update_data.to_model(model=models.Status, instance=status)
|
||||
with (
|
||||
patch("bookwyrm.activitypub.base_activity.set_related_field.delay"),
|
||||
patch("bookwyrm.models.status.Status.ignore_activity") as discarder,
|
||||
):
|
||||
discarder.return_value = False
|
||||
update_data.to_model(model=models.Status, instance=status)
|
||||
self.assertIsNone(status.attachments.first())
|
||||
|
||||
@responses.activate
|
||||
|
|
|
@ -11,18 +11,20 @@ class Note(TestCase):
|
|||
"""the model-linked ActivityPub dataclass for Note-based types"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create a shared user"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
self.user.remote_id = "https://test-instance.org/user/critic"
|
||||
self.user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.user.remote_id = "https://test-instance.org/user/critic"
|
||||
cls.user.save(broadcast=False, update_fields=["remote_id"])
|
||||
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test Edition", remote_id="http://book.com/book"
|
||||
)
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ class Quotation(TestCase):
|
|||
"""we have hecka ways to create statuses"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""model objects we'll need"""
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.user = models.User.objects.create_user(
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -23,7 +23,7 @@ class Quotation(TestCase):
|
|||
outbox="https://example.com/user/mouse/outbox",
|
||||
remote_id="https://example.com/user/mouse",
|
||||
)
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
)
|
||||
|
|
|
@ -16,15 +16,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""use a test csv"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -32,7 +34,7 @@ class Activitystreams(TestCase):
|
|||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -42,7 +44,7 @@ class Activitystreams(TestCase):
|
|||
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)
|
||||
cls.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
|
||||
def setUp(self):
|
||||
"""per-test setUp"""
|
||||
|
@ -105,9 +107,11 @@ class Activitystreams(TestCase):
|
|||
privacy="direct",
|
||||
book=self.book,
|
||||
)
|
||||
with patch("bookwyrm.activitystreams.r.set"), patch(
|
||||
"bookwyrm.activitystreams.r.delete"
|
||||
), patch("bookwyrm.activitystreams.ActivityStream.get_store") as redis_mock:
|
||||
with (
|
||||
patch("bookwyrm.activitystreams.r.set"),
|
||||
patch("bookwyrm.activitystreams.r.delete"),
|
||||
patch("bookwyrm.activitystreams.ActivityStream.get_store") as redis_mock,
|
||||
):
|
||||
redis_mock.return_value = [status.id, status2.id]
|
||||
result = self.test_stream.get_activity_stream(self.local_user)
|
||||
self.assertEqual(result.count(), 2)
|
||||
|
|
|
@ -15,16 +15,18 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""use a test csv"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -34,7 +36,7 @@ class Activitystreams(TestCase):
|
|||
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)
|
||||
cls.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
|
||||
def test_get_statuses_for_user_books(self, *_):
|
||||
"""create a stream for a user"""
|
||||
|
|
|
@ -13,15 +13,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""use a test csv"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -29,7 +31,7 @@ class Activitystreams(TestCase):
|
|||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -13,15 +13,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""use a test csv"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -29,7 +31,7 @@ class Activitystreams(TestCase):
|
|||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -39,7 +41,7 @@ class Activitystreams(TestCase):
|
|||
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)
|
||||
cls.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
|
||||
def test_localstream_get_audience_remote_status(self, *_):
|
||||
"""get a list of users that should see a status"""
|
||||
|
|
|
@ -15,16 +15,18 @@ class ActivitystreamsSignals(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""use a test csv"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -8,15 +8,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""use a test csv"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -24,7 +26,7 @@ class Activitystreams(TestCase):
|
|||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -34,11 +36,9 @@ class Activitystreams(TestCase):
|
|||
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)
|
||||
cls.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
self.status = models.Status.objects.create(
|
||||
content="hi", user=self.local_user
|
||||
)
|
||||
cls.status = models.Status.objects.create(content="hi", user=cls.local_user)
|
||||
|
||||
def test_add_book_statuses_task(self):
|
||||
"""statuses related to a book"""
|
||||
|
|
|
@ -13,7 +13,7 @@ class AbstractConnector(TestCase):
|
|||
"""generic code for connecting to outside data sources"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need an example connector in the database"""
|
||||
models.Connector.objects.create(
|
||||
identifier="example.com",
|
||||
|
@ -23,7 +23,7 @@ class AbstractConnector(TestCase):
|
|||
covers_url="https://example.com/covers",
|
||||
search_url="https://example.com/search?q=",
|
||||
)
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
remote_id="https://example.com/book/1234",
|
||||
openlibrary_key="OL1234M",
|
||||
|
|
|
@ -10,9 +10,9 @@ class AbstractConnector(TestCase):
|
|||
"""generic code for connecting to outside data sources"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need an example connector in the database"""
|
||||
self.connector_info = models.Connector.objects.create(
|
||||
cls.connector_info = models.Connector.objects.create(
|
||||
identifier="example.com",
|
||||
connector_file="openlibrary",
|
||||
base_url="https://example.com",
|
||||
|
|
|
@ -12,7 +12,7 @@ class BookWyrmConnector(TestCase):
|
|||
"""this connector doesn't do much, just search"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create bookwrym_connector in the database"""
|
||||
models.Connector.objects.create(
|
||||
identifier="example.com",
|
||||
|
|
|
@ -11,18 +11,18 @@ class ConnectorManager(TestCase):
|
|||
"""interface between the app and various connectors"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we'll need some books and a connector info entry"""
|
||||
self.work = models.Work.objects.create(title="Example Work")
|
||||
cls.work = models.Work.objects.create(title="Example Work")
|
||||
|
||||
models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work, isbn_10="0000000000"
|
||||
title="Example Edition", parent_work=cls.work, isbn_10="0000000000"
|
||||
)
|
||||
self.edition = models.Edition.objects.create(
|
||||
title="Another Edition", parent_work=self.work, isbn_10="1111111111"
|
||||
cls.edition = models.Edition.objects.create(
|
||||
title="Another Edition", parent_work=cls.work, isbn_10="1111111111"
|
||||
)
|
||||
|
||||
self.remote_connector = models.Connector.objects.create(
|
||||
cls.remote_connector = models.Connector.objects.create(
|
||||
identifier="test_connector_remote",
|
||||
priority=1,
|
||||
connector_file="bookwyrm_connector",
|
||||
|
|
|
@ -15,7 +15,7 @@ class Inventaire(TestCase):
|
|||
"""test loading data from inventaire.io"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""creates the connector in the database"""
|
||||
models.Connector.objects.create(
|
||||
identifier="inventaire.io",
|
||||
|
@ -212,11 +212,14 @@ class Inventaire(TestCase):
|
|||
json={"entities": {}},
|
||||
)
|
||||
data = {"uri": "blah"}
|
||||
with patch(
|
||||
"bookwyrm.connectors.inventaire.Connector.load_edition_data"
|
||||
) as loader_mock, patch(
|
||||
"bookwyrm.connectors.inventaire.Connector.get_book_data"
|
||||
) as getter_mock:
|
||||
with (
|
||||
patch(
|
||||
"bookwyrm.connectors.inventaire.Connector.load_edition_data"
|
||||
) as loader_mock,
|
||||
patch(
|
||||
"bookwyrm.connectors.inventaire.Connector.get_book_data"
|
||||
) as getter_mock,
|
||||
):
|
||||
loader_mock.return_value = {"uris": ["hello"]}
|
||||
self.connector.get_edition_from_work_data(data)
|
||||
self.assertTrue(getter_mock.called)
|
||||
|
|
|
@ -19,7 +19,7 @@ class Openlibrary(TestCase):
|
|||
"""test loading data from openlibrary.org"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""creates the connector in the database"""
|
||||
models.Connector.objects.create(
|
||||
identifier="openlibrary.org",
|
||||
|
|
|
@ -9,7 +9,6 @@ from bookwyrm.importers import CalibreImporter
|
|||
from bookwyrm.models.import_job import handle_imported_book
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
|
@ -20,20 +19,27 @@ class CalibreImport(TestCase):
|
|||
"""use a test csv"""
|
||||
self.importer = CalibreImporter()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/calibre.csv")
|
||||
# pylint: disable-next=consider-using-with
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
|
||||
def tearDown(self):
|
||||
"""close test csv"""
|
||||
self.csv.close()
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
|
|
@ -16,7 +16,6 @@ def make_date(*args):
|
|||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
|
@ -27,20 +26,27 @@ class GoodreadsImport(TestCase):
|
|||
"""use a test csv"""
|
||||
self.importer = GoodreadsImporter()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
||||
# pylint: disable-next=consider-using-with
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
|
||||
def tearDown(self):
|
||||
"""close test csv"""
|
||||
self.csv.close()
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
|
|
@ -19,7 +19,6 @@ def make_date(*args):
|
|||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
|
@ -30,20 +29,27 @@ class GenericImporter(TestCase):
|
|||
"""use a test csv"""
|
||||
self.importer = Importer()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/generic.csv")
|
||||
# pylint: disable-next=consider-using-with
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
|
||||
def tearDown(self):
|
||||
"""close test csv"""
|
||||
self.csv.close()
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
@ -266,9 +272,11 @@ class GenericImporter(TestCase):
|
|||
import_item.book = self.book
|
||||
import_item.save()
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
with patch("bookwyrm.models.Status.broadcast") as broadcast_mock:
|
||||
handle_imported_book(import_item)
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.models.Status.broadcast") as broadcast_mock,
|
||||
):
|
||||
handle_imported_book(import_item)
|
||||
kwargs = broadcast_mock.call_args.kwargs
|
||||
self.assertEqual(kwargs["software"], "bookwyrm")
|
||||
review = models.Review.objects.get(book=self.book, user=self.local_user)
|
||||
|
|
|
@ -16,7 +16,6 @@ def make_date(*args):
|
|||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
|
@ -29,20 +28,27 @@ class LibrarythingImport(TestCase):
|
|||
datafile = pathlib.Path(__file__).parent.joinpath("../data/librarything.tsv")
|
||||
|
||||
# Librarything generates latin encoded exports...
|
||||
# pylint: disable-next=consider-using-with
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
|
||||
def tearDown(self):
|
||||
"""close test csv"""
|
||||
self.csv.close()
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mmai", "mmai@mmai.mmai", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
|
|
@ -16,7 +16,6 @@ def make_date(*args):
|
|||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
|
@ -27,20 +26,27 @@ class OpenLibraryImport(TestCase):
|
|||
"""use a test csv"""
|
||||
self.importer = OpenLibraryImporter()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/openlibrary.csv")
|
||||
# pylint: disable-next=consider-using-with
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
|
||||
def tearDown(self):
|
||||
"""close test csv"""
|
||||
self.csv.close()
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
|
|
@ -16,7 +16,6 @@ def make_date(*args):
|
|||
return datetime.datetime(*args, tzinfo=pytz.UTC)
|
||||
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
|
||||
|
@ -27,20 +26,27 @@ class StorygraphImport(TestCase):
|
|||
"""use a test csv"""
|
||||
self.importer = StorygraphImporter()
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/storygraph.csv")
|
||||
# pylint: disable-next=consider-using-with
|
||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||
|
||||
def tearDown(self):
|
||||
"""close test csv"""
|
||||
self.csv.close()
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
|
|
@ -9,19 +9,21 @@ class ListsStreamSignals(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.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(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -16,15 +16,17 @@ class ListsStream(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -32,7 +34,7 @@ class ListsStream(TestCase):
|
|||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -41,7 +43,7 @@ class ListsStream(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.stream = lists_stream.ListsStream()
|
||||
cls.stream = lists_stream.ListsStream()
|
||||
|
||||
def test_lists_stream_ids(self, *_):
|
||||
"""the abstract base class for stream objects"""
|
||||
|
|
|
@ -11,15 +11,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -27,7 +29,7 @@ class Activitystreams(TestCase):
|
|||
localname="nutria",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -36,11 +38,12 @@ class Activitystreams(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.lists_stream.remove_list_task.delay"):
|
||||
self.list = models.List.objects.create(
|
||||
user=self.local_user, name="hi", privacy="public"
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
):
|
||||
cls.list = models.List.objects.create(
|
||||
user=cls.local_user, name="hi", privacy="public"
|
||||
)
|
||||
|
||||
def test_populate_lists_task(self, *_):
|
||||
|
|
|
@ -13,15 +13,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need some stuff"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -37,7 +39,7 @@ class Activitystreams(TestCase):
|
|||
is_active=False,
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -46,7 +48,7 @@ class Activitystreams(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="test book")
|
||||
cls.book = models.Edition.objects.create(title="test book")
|
||||
|
||||
def test_populate_streams(self, *_):
|
||||
"""make sure the function on the redis manager gets called"""
|
||||
|
|
|
@ -11,15 +11,17 @@ class Activitystreams(TestCase):
|
|||
"""using redis to build activity streams"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need some stuff"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
"nutria@nutria.nutria",
|
||||
"password",
|
||||
|
@ -35,7 +37,7 @@ class Activitystreams(TestCase):
|
|||
is_active=False,
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -44,7 +46,7 @@ class Activitystreams(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="test book")
|
||||
cls.book = models.Edition.objects.create(title="test book")
|
||||
|
||||
def test_populate_streams(self, _):
|
||||
"""make sure the function on the redis manager gets called"""
|
||||
|
@ -53,11 +55,10 @@ class Activitystreams(TestCase):
|
|||
user=self.local_user, content="hi", book=self.book
|
||||
)
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
) as redis_mock, patch(
|
||||
"bookwyrm.lists_stream.populate_lists_task.delay"
|
||||
) as list_mock:
|
||||
with (
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay") as redis_mock,
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay") as list_mock,
|
||||
):
|
||||
populate_streams()
|
||||
self.assertEqual(redis_mock.call_count, 6) # 2 users x 3 streams
|
||||
self.assertEqual(list_mock.call_count, 2) # 2 users
|
||||
|
|
|
@ -27,18 +27,20 @@ class ActivitypubMixins(TestCase):
|
|||
"""functionality shared across models"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""shared 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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
self.local_user.remote_id = "http://example.com/a/b"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "http://example.com/a/b"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -15,12 +15,14 @@ class AutomodModel(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
|
|
@ -13,16 +13,18 @@ class BaseModel(TestCase):
|
|||
"""functionality shared across models"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""shared 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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
""" testing models """
|
||||
from io import BytesIO
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
from dateutil.parser import parse
|
||||
from PIL import Image
|
||||
from django.core.files.base import ContentFile
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
|
@ -19,17 +16,17 @@ class Book(TestCase):
|
|||
"""not too much going on in the books model but here we are"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we'll need some books"""
|
||||
self.work = models.Work.objects.create(
|
||||
cls.work = models.Work.objects.create(
|
||||
title="Example Work", remote_id="https://example.com/book/1"
|
||||
)
|
||||
self.first_edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work
|
||||
cls.first_edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=cls.work
|
||||
)
|
||||
self.second_edition = models.Edition.objects.create(
|
||||
cls.second_edition = models.Edition.objects.create(
|
||||
title="Another Example Edition",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
def test_remote_id(self):
|
||||
|
@ -130,15 +127,13 @@ class Book(TestCase):
|
|||
)
|
||||
def test_thumbnail_fields(self):
|
||||
"""Just hit them"""
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
|
||||
book = models.Edition.objects.create(title="hello")
|
||||
book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||
with open(image_path, "rb") as image_file:
|
||||
book.cover.save("test.jpg", image_file)
|
||||
|
||||
self.assertIsNotNone(book.cover_bw_book_xsmall_webp.url)
|
||||
self.assertIsNotNone(book.cover_bw_book_xsmall_jpg.url)
|
||||
|
|
|
@ -16,16 +16,14 @@ class BookwyrmExport(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""lots of stuff to set up for a user export"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"), patch(
|
||||
"bookwyrm.suggested_users.rerank_user_task.delay"
|
||||
), patch(
|
||||
"bookwyrm.lists_stream.remove_list_task.delay"
|
||||
), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch(
|
||||
"bookwyrm.activitystreams.add_book_statuses_task"
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
patch("bookwyrm.suggested_users.rerank_user_task.delay"),
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.activitystreams.add_book_statuses_task"),
|
||||
):
|
||||
|
||||
self.local_user = models.User.objects.create_user(
|
||||
|
|
|
@ -18,12 +18,12 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
def setUp(self):
|
||||
"""setting stuff up"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"), patch(
|
||||
"bookwyrm.suggested_users.rerank_user_task.delay"
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
patch("bookwyrm.suggested_users.rerank_user_task.delay"),
|
||||
):
|
||||
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse",
|
||||
"mouse@mouse.mouse",
|
||||
|
@ -78,16 +78,18 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
def test_update_user_profile(self):
|
||||
"""Test update the user's profile from import data"""
|
||||
|
||||
with patch("bookwyrm.suggested_users.remove_user_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.suggested_users.rerank_user_task.delay"):
|
||||
|
||||
with open(self.archive_file, "rb") as fileobj:
|
||||
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||
|
||||
models.bookwyrm_import_job.update_user_profile(
|
||||
self.local_user, tarfile, self.json_data
|
||||
)
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.remove_user_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.suggested_users.rerank_user_task.delay"),
|
||||
):
|
||||
with (
|
||||
open(self.archive_file, "rb") as fileobj,
|
||||
BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile,
|
||||
):
|
||||
models.bookwyrm_import_job.update_user_profile(
|
||||
self.local_user, tarfile, self.json_data
|
||||
)
|
||||
|
||||
self.local_user.refresh_from_db()
|
||||
|
||||
|
@ -103,10 +105,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
def test_update_user_settings(self):
|
||||
"""Test updating the user's settings from import data"""
|
||||
|
||||
with patch("bookwyrm.suggested_users.remove_user_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.suggested_users.rerank_user_task.delay"):
|
||||
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.remove_user_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.suggested_users.rerank_user_task.delay"),
|
||||
):
|
||||
models.bookwyrm_import_job.update_user_settings(
|
||||
self.local_user, self.json_data
|
||||
)
|
||||
|
@ -145,8 +148,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
def test_upsert_saved_lists_existing(self):
|
||||
"""Test upserting an existing saved list"""
|
||||
|
||||
with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
book_list = models.List.objects.create(
|
||||
name="My cool list",
|
||||
|
@ -172,8 +176,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
def test_upsert_saved_lists_not_existing(self):
|
||||
"""Test upserting a new saved list"""
|
||||
|
||||
with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
book_list = models.List.objects.create(
|
||||
name="My cool list",
|
||||
|
@ -199,9 +204,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
self.assertFalse(before_follow)
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"), patch(
|
||||
"bookwyrm.lists_stream.add_user_lists_task.delay"
|
||||
), patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
with (
|
||||
patch("bookwyrm.activitystreams.add_user_statuses_task.delay"),
|
||||
patch("bookwyrm.lists_stream.add_user_lists_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
models.bookwyrm_import_job.upsert_follows(
|
||||
self.local_user, self.json_data.get("follows")
|
||||
)
|
||||
|
@ -222,10 +229,11 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
).exists()
|
||||
self.assertFalse(blocked_before)
|
||||
|
||||
with patch("bookwyrm.suggested_users.remove_suggestion_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
|
||||
), patch("bookwyrm.lists_stream.remove_user_lists_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.remove_suggestion_task.delay"),
|
||||
patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"),
|
||||
patch("bookwyrm.lists_stream.remove_user_lists_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
models.bookwyrm_import_job.upsert_user_blocks(
|
||||
self.local_user, self.json_data.get("blocks")
|
||||
|
@ -246,14 +254,15 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
self.assertEqual(models.Edition.objects.count(), 1)
|
||||
|
||||
with open(self.archive_file, "rb") as fileobj:
|
||||
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||
with (
|
||||
open(self.archive_file, "rb") as fileobj,
|
||||
BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile,
|
||||
):
|
||||
bookwyrm_import_job.get_or_create_edition(
|
||||
self.json_data["books"][1], tarfile
|
||||
) # Sand Talk
|
||||
|
||||
bookwyrm_import_job.get_or_create_edition(
|
||||
self.json_data["books"][1], tarfile
|
||||
) # Sand Talk
|
||||
|
||||
self.assertEqual(models.Edition.objects.count(), 1)
|
||||
self.assertEqual(models.Edition.objects.count(), 1)
|
||||
|
||||
def test_get_or_create_edition_not_existing(self):
|
||||
"""Test take a JSON string of books and editions,
|
||||
|
@ -262,12 +271,13 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
self.assertEqual(models.Edition.objects.count(), 1)
|
||||
|
||||
with open(self.archive_file, "rb") as fileobj:
|
||||
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||
|
||||
bookwyrm_import_job.get_or_create_edition(
|
||||
self.json_data["books"][0], tarfile
|
||||
) # Seeing like a state
|
||||
with (
|
||||
open(self.archive_file, "rb") as fileobj,
|
||||
BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile,
|
||||
):
|
||||
bookwyrm_import_job.get_or_create_edition(
|
||||
self.json_data["books"][0], tarfile
|
||||
) # Seeing like a state
|
||||
|
||||
self.assertTrue(models.Edition.objects.filter(isbn_13="9780300070163").exists())
|
||||
self.assertEqual(models.Edition.objects.count(), 2)
|
||||
|
@ -312,10 +322,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
self.assertEqual(models.Review.objects.filter(user=self.local_user).count(), 0)
|
||||
reviews = self.json_data["books"][0]["reviews"]
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True):
|
||||
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True),
|
||||
):
|
||||
bookwyrm_import_job.upsert_statuses(
|
||||
self.local_user, models.Review, reviews, self.book.remote_id
|
||||
)
|
||||
|
@ -349,10 +359,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
self.assertEqual(models.Comment.objects.filter(user=self.local_user).count(), 0)
|
||||
comments = self.json_data["books"][1]["comments"]
|
||||
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True):
|
||||
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True),
|
||||
):
|
||||
bookwyrm_import_job.upsert_statuses(
|
||||
self.local_user, models.Comment, comments, self.book.remote_id
|
||||
)
|
||||
|
@ -378,9 +388,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
models.Quotation.objects.filter(user=self.local_user).count(), 0
|
||||
)
|
||||
quotes = self.json_data["books"][1]["quotations"]
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True):
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=True),
|
||||
):
|
||||
|
||||
bookwyrm_import_job.upsert_statuses(
|
||||
self.local_user, models.Quotation, quotes, self.book.remote_id
|
||||
|
@ -411,9 +422,10 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
models.Quotation.objects.filter(user=self.local_user).count(), 0
|
||||
)
|
||||
quotes = self.json_data["books"][1]["quotations"]
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=False):
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.models.bookwyrm_import_job.is_alias", return_value=False),
|
||||
):
|
||||
|
||||
bookwyrm_import_job.upsert_statuses(
|
||||
self.local_user, models.Quotation, quotes, self.book.remote_id
|
||||
|
@ -432,8 +444,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
title="Another Book", remote_id="https://example.com/book/9876"
|
||||
)
|
||||
|
||||
with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
book_list = models.List.objects.create(
|
||||
name="my list of books", user=self.local_user
|
||||
|
@ -452,8 +465,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
1,
|
||||
)
|
||||
|
||||
with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
bookwyrm_import_job.upsert_lists(
|
||||
self.local_user,
|
||||
|
@ -479,8 +493,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
self.assertEqual(models.List.objects.filter(user=self.local_user).count(), 0)
|
||||
self.assertFalse(models.ListItem.objects.filter(book=self.book.id).exists())
|
||||
|
||||
with patch("bookwyrm.lists_stream.remove_list_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
bookwyrm_import_job.upsert_lists(
|
||||
self.local_user,
|
||||
|
@ -503,16 +518,18 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
shelf = models.Shelf.objects.get(name="Read", user=self.local_user)
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.activitystreams.add_book_statuses_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
models.ShelfBook.objects.create(
|
||||
book=self.book, shelf=shelf, user=self.local_user
|
||||
)
|
||||
|
||||
book_data = self.json_data["books"][0]
|
||||
with patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.activitystreams.add_book_statuses_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
bookwyrm_import_job.upsert_shelves(self.book, self.local_user, book_data)
|
||||
|
||||
|
@ -530,8 +547,9 @@ class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
|||
|
||||
book_data = self.json_data["books"][0]
|
||||
|
||||
with patch("bookwyrm.activitystreams.add_book_statuses_task.delay"), patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
with (
|
||||
patch("bookwyrm.activitystreams.add_book_statuses_task.delay"),
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
):
|
||||
bookwyrm_import_job.upsert_shelves(self.book, self.local_user, book_data)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
""" testing models """
|
||||
from io import BytesIO
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
import datetime
|
||||
|
@ -10,7 +9,6 @@ from typing import List
|
|||
from unittest import expectedFailure
|
||||
from unittest.mock import patch
|
||||
|
||||
from PIL import Image
|
||||
import responses
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -420,13 +418,11 @@ class ModelFields(TestCase):
|
|||
user = User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
user.avatar.save("test.jpg", ContentFile(output.getvalue()))
|
||||
with open(image_path, "rb") as image_file:
|
||||
user.avatar.save("test.jpg", image_file)
|
||||
|
||||
instance = fields.ImageField()
|
||||
|
||||
|
@ -516,30 +512,25 @@ class ModelFields(TestCase):
|
|||
@responses.activate
|
||||
def test_image_field_set_field_from_activity_no_overwrite_with_cover(self, *_):
|
||||
"""update a model instance from an activitypub object"""
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
|
||||
another_image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
another_image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/logo.png"
|
||||
)
|
||||
another_image = Image.open(another_image_file)
|
||||
another_output = BytesIO()
|
||||
another_image.save(another_output, format=another_image.format)
|
||||
|
||||
instance = fields.ImageField(activitypub_field="cover", name="cover")
|
||||
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
body=another_image.tobytes(),
|
||||
status=200,
|
||||
)
|
||||
with open(another_image_path, "rb") as another_image_file:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
body=another_image_file.read(),
|
||||
status=200,
|
||||
)
|
||||
book = Edition.objects.create(title="hello")
|
||||
book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||
with open(image_path, "rb") as image_file:
|
||||
book.cover.save("test.jpg", image_file)
|
||||
cover_size = book.cover.size
|
||||
self.assertIsNotNone(cover_size)
|
||||
|
||||
|
@ -553,24 +544,22 @@ class ModelFields(TestCase):
|
|||
@responses.activate
|
||||
def test_image_field_set_field_from_activity_with_overwrite_with_cover(self, *_):
|
||||
"""update a model instance from an activitypub object"""
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
book = Edition.objects.create(title="hello")
|
||||
book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||
with open(image_path, "rb") as image_file:
|
||||
book.cover.save("test.jpg", image_file)
|
||||
cover_size = book.cover.size
|
||||
self.assertIsNotNone(cover_size)
|
||||
|
||||
another_image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
another_image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/logo.png"
|
||||
)
|
||||
|
||||
instance = fields.ImageField(activitypub_field="cover", name="cover")
|
||||
|
||||
with open(another_image_file, "rb") as another_image:
|
||||
with open(another_image_path, "rb") as another_image:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://www.example.com/image.jpg",
|
||||
|
|
|
@ -10,21 +10,23 @@ class Group(TestCase):
|
|||
"""some activitypub oddness ahead"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""Set up for tests"""
|
||||
|
||||
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.owner_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.owner_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
||||
self.rat = models.User.objects.create_user(
|
||||
cls.rat = models.User.objects.create_user(
|
||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||
)
|
||||
|
||||
self.badger = models.User.objects.create_user(
|
||||
cls.badger = models.User.objects.create_user(
|
||||
"badger",
|
||||
"badger@badger.badger",
|
||||
"badgerword",
|
||||
|
@ -32,7 +34,7 @@ class Group(TestCase):
|
|||
localname="badger",
|
||||
)
|
||||
|
||||
self.capybara = models.User.objects.create_user(
|
||||
cls.capybara = models.User.objects.create_user(
|
||||
"capybara",
|
||||
"capybara@capybara.capybara",
|
||||
"capybaraword",
|
||||
|
@ -40,32 +42,32 @@ class Group(TestCase):
|
|||
localname="capybara",
|
||||
)
|
||||
|
||||
self.public_group = models.Group.objects.create(
|
||||
cls.public_group = models.Group.objects.create(
|
||||
name="Public Group",
|
||||
description="Initial description",
|
||||
user=self.owner_user,
|
||||
user=cls.owner_user,
|
||||
privacy="public",
|
||||
)
|
||||
|
||||
self.private_group = models.Group.objects.create(
|
||||
cls.private_group = models.Group.objects.create(
|
||||
name="Private Group",
|
||||
description="Top secret",
|
||||
user=self.owner_user,
|
||||
user=cls.owner_user,
|
||||
privacy="direct",
|
||||
)
|
||||
|
||||
self.followers_only_group = models.Group.objects.create(
|
||||
cls.followers_only_group = models.Group.objects.create(
|
||||
name="Followers Group",
|
||||
description="No strangers",
|
||||
user=self.owner_user,
|
||||
user=cls.owner_user,
|
||||
privacy="followers",
|
||||
)
|
||||
|
||||
models.GroupMember.objects.create(group=self.private_group, user=self.badger)
|
||||
models.GroupMember.objects.create(group=cls.private_group, user=cls.badger)
|
||||
models.GroupMember.objects.create(
|
||||
group=self.followers_only_group, user=self.badger
|
||||
group=cls.followers_only_group, user=cls.badger
|
||||
)
|
||||
models.GroupMember.objects.create(group=self.public_group, user=self.capybara)
|
||||
models.GroupMember.objects.create(group=cls.public_group, user=cls.capybara)
|
||||
|
||||
def test_group_members_can_see_private_groups(self, _):
|
||||
"""direct privacy group should not be excluded from group listings for group
|
||||
|
@ -81,9 +83,10 @@ class Group(TestCase):
|
|||
"""follower-only group booklists should not be excluded from group booklist
|
||||
listing for group members who do not follower list owner"""
|
||||
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.lists_stream.remove_list_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
):
|
||||
followers_list = models.List.objects.create(
|
||||
name="Followers List",
|
||||
curation="group",
|
||||
|
@ -104,9 +107,10 @@ class Group(TestCase):
|
|||
"""private group booklists should not be excluded from group booklist listing
|
||||
for group members"""
|
||||
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.lists_stream.remove_list_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
):
|
||||
private_list = models.List.objects.create(
|
||||
name="Private List",
|
||||
privacy="direct",
|
||||
|
|
|
@ -17,12 +17,14 @@ class ImportJob(TestCase):
|
|||
"""this is a fancy one!!!"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||
)
|
||||
|
||||
|
@ -192,14 +194,16 @@ class ImportJob(TestCase):
|
|||
status=200,
|
||||
)
|
||||
|
||||
with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"):
|
||||
with patch(
|
||||
with (
|
||||
patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"),
|
||||
patch(
|
||||
"bookwyrm.connectors.connector_manager.first_search_result"
|
||||
) as search:
|
||||
search.return_value = result
|
||||
with patch(
|
||||
"bookwyrm.connectors.openlibrary.Connector.get_authors_from_data"
|
||||
):
|
||||
book = item.get_book_from_identifier()
|
||||
) as search,
|
||||
):
|
||||
search.return_value = result
|
||||
with patch(
|
||||
"bookwyrm.connectors.openlibrary.Connector.get_authors_from_data"
|
||||
):
|
||||
book = item.get_book_from_identifier()
|
||||
|
||||
self.assertEqual(book.title, "Sabriel")
|
||||
|
|
|
@ -12,16 +12,18 @@ class List(TestCase):
|
|||
"""some activitypub oddness ahead"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.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)
|
||||
cls.book = models.Edition.objects.create(title="hi", parent_work=work)
|
||||
|
||||
def test_remote_id(self, *_):
|
||||
"""shelves use custom remote ids"""
|
||||
|
|
|
@ -8,19 +8,21 @@ class Notification(TestCase):
|
|||
"""let people know things"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""useful things for creating a notification"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -29,14 +31,14 @@ class Notification(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
isbn_13="1234567890123",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
)
|
||||
self.another_book = models.Edition.objects.create(
|
||||
cls.another_book = models.Edition.objects.create(
|
||||
title="Second Test Book",
|
||||
parent_work=models.Work.objects.create(title="Test Work"),
|
||||
)
|
||||
|
@ -199,12 +201,14 @@ class NotifyInviteRequest(TestCase):
|
|||
"""let admins know of invite requests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""ensure there is one admin"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -264,9 +268,11 @@ class NotifyInviteRequest(TestCase):
|
|||
|
||||
def test_notify_multiple_admins(self):
|
||||
"""all admins are notified"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
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(
|
||||
"admin@local.com",
|
||||
"admin@example.com",
|
||||
|
|
|
@ -12,18 +12,20 @@ class ReadThrough(TestCase):
|
|||
"""some activitypub oddness ahead"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""look, a shelf"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
||||
self.work = models.Work.objects.create(title="Example Work")
|
||||
self.edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work
|
||||
cls.work = models.Work.objects.create(title="Example Work")
|
||||
cls.edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=cls.work
|
||||
)
|
||||
|
||||
def test_valid_date(self):
|
||||
|
|
|
@ -15,10 +15,10 @@ class Relationship(TestCase):
|
|||
"""following, blocking, stuff like that"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need some users for this"""
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -27,14 +27,16 @@ class Relationship(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
self.local_user.remote_id = "http://local.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "http://local.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
|
||||
def test_user_follows(self, *_):
|
||||
"""basic functionality of user follows"""
|
||||
|
|
|
@ -16,16 +16,18 @@ class Shelf(TestCase):
|
|||
"""some activitypub oddness ahead"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""look, a shelf"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
cls.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
|
||||
def test_remote_id(self, *_):
|
||||
"""shelves use custom remote ids"""
|
||||
|
|
|
@ -13,12 +13,14 @@ class SiteModels(TestCase):
|
|||
"""tests for site models"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
""" testing models """
|
||||
from unittest.mock import patch
|
||||
from io import BytesIO
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
from django.http import Http404
|
||||
from django.core.files.base import ContentFile
|
||||
from django.db import IntegrityError
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
from PIL import Image
|
||||
import responses
|
||||
|
||||
from bookwyrm import activitypub, models, settings
|
||||
|
@ -25,16 +22,18 @@ class Status(TestCase):
|
|||
"""lotta types of statuses"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""useful things for creating a status"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -43,20 +42,20 @@ class Status(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="Test Edition")
|
||||
cls.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(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
with patch("bookwyrm.models.Status.broadcast"):
|
||||
image.save(output, format=image.format)
|
||||
self.book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||
with (
|
||||
patch("bookwyrm.models.Status.broadcast"),
|
||||
open(image_path, "rb") as image_file,
|
||||
):
|
||||
self.book.cover.save("test.jpg", image_file)
|
||||
|
||||
def test_status_generated_fields(self, *_):
|
||||
"""setting remote id"""
|
||||
|
|
|
@ -19,11 +19,13 @@ class User(TestCase):
|
|||
protocol = "https://" if USE_HTTPS else "http://"
|
||||
|
||||
@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"):
|
||||
self.user = models.User.objects.create_user(
|
||||
def setUpTestData(cls):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
f"mouse@{DOMAIN}",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -33,7 +35,7 @@ class User(TestCase):
|
|||
summary="a summary",
|
||||
bookwyrm_user=False,
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
f"nutria@{DOMAIN}",
|
||||
"nutria@nutria.nutria",
|
||||
"nutriaword",
|
||||
|
@ -122,9 +124,11 @@ class User(TestCase):
|
|||
|
||||
site.default_user_auth_group = Group.objects.get(name="editor")
|
||||
site.save()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
user = models.User.objects.create_user(
|
||||
f"test2{DOMAIN}",
|
||||
"test2@bookwyrm.test",
|
||||
|
@ -135,9 +139,11 @@ class User(TestCase):
|
|||
|
||||
site.default_user_auth_group = None
|
||||
site.save()
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
user = models.User.objects.create_user(
|
||||
f"test1{DOMAIN}",
|
||||
"test1@bookwyrm.test",
|
||||
|
@ -228,11 +234,14 @@ class User(TestCase):
|
|||
self.assertEqual(self.user.name, "hi")
|
||||
self.assertEqual(self.user.summary, "a summary")
|
||||
self.assertEqual(self.user.email, "mouse@mouse.mouse")
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
) as broadcast_mock, patch(
|
||||
"bookwyrm.models.user.User.erase_user_statuses"
|
||||
) as erase_statuses_mock:
|
||||
with (
|
||||
patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
) as broadcast_mock,
|
||||
patch(
|
||||
"bookwyrm.models.user.User.erase_user_statuses"
|
||||
) as erase_statuses_mock,
|
||||
):
|
||||
self.user.delete()
|
||||
|
||||
self.assertEqual(erase_statuses_mock.call_count, 1)
|
||||
|
|
|
@ -14,19 +14,21 @@ class BookDisplayTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="Test Book")
|
||||
cls.book = models.Edition.objects.create(title="Test Book")
|
||||
|
||||
def test_get_book_description(self, *_):
|
||||
"""grab it from the edition or the parent"""
|
||||
|
|
|
@ -13,19 +13,21 @@ class FeedPageTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="Test Book")
|
||||
cls.book = models.Edition.objects.create(title="Test Book")
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_load_subclass(self, *_):
|
||||
|
|
|
@ -13,12 +13,14 @@ class InteractionTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -26,14 +28,14 @@ class InteractionTags(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.rat",
|
||||
"ratword",
|
||||
remote_id="http://example.com/rat",
|
||||
local=False,
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="Test Book")
|
||||
cls.book = models.Edition.objects.create(title="Test Book")
|
||||
|
||||
def test_get_user_liked(self, *_):
|
||||
"""did a user like a status"""
|
||||
|
|
|
@ -13,12 +13,14 @@ class NotificationPageTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
|
|
@ -13,12 +13,14 @@ class RatingTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -26,7 +28,7 @@ class RatingTags(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.rat",
|
||||
"ratword",
|
||||
|
@ -34,7 +36,7 @@ class RatingTags(TestCase):
|
|||
local=False,
|
||||
)
|
||||
work = models.Work.objects.create(title="Work title")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
parent_work=work,
|
||||
)
|
||||
|
|
|
@ -16,12 +16,14 @@ class ShelfTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -29,14 +31,14 @@ class ShelfTags(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.rat",
|
||||
"ratword",
|
||||
remote_id="http://example.com/rat",
|
||||
local=False,
|
||||
)
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test Book",
|
||||
parent_work=models.Work.objects.create(title="Test work"),
|
||||
)
|
||||
|
|
|
@ -15,12 +15,14 @@ class StatusDisplayTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -28,14 +30,14 @@ class StatusDisplayTags(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.rat",
|
||||
"ratword",
|
||||
remote_id="http://example.com/rat",
|
||||
local=False,
|
||||
)
|
||||
self.book = models.Edition.objects.create(title="Test Book")
|
||||
cls.book = models.Edition.objects.create(title="Test Book")
|
||||
|
||||
def test_get_mentions(self, *_):
|
||||
"""list of people mentioned"""
|
||||
|
|
|
@ -15,12 +15,14 @@ class UtilitiesTags(TestCase):
|
|||
"""lotta different things here"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create some filler objects"""
|
||||
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.user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.mouse",
|
||||
"mouseword",
|
||||
|
@ -28,15 +30,15 @@ class UtilitiesTags(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.rat",
|
||||
"ratword",
|
||||
remote_id="http://example.com/rat",
|
||||
local=False,
|
||||
)
|
||||
self.author = models.Author.objects.create(name="Jessica", isni="4")
|
||||
self.book = models.Edition.objects.create(title="Test Book")
|
||||
cls.author = models.Author.objects.create(name="Jessica", isni="4")
|
||||
cls.book = models.Edition.objects.create(title="Test Book")
|
||||
|
||||
def test_get_uuid(self, *_):
|
||||
"""uuid functionality"""
|
||||
|
|
|
@ -12,43 +12,43 @@ class BookSearch(TestCase):
|
|||
"""look for some books"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
self.first_author = models.Author.objects.create(
|
||||
cls.first_author = models.Author.objects.create(
|
||||
name="Author One", aliases=["The First"]
|
||||
)
|
||||
self.second_author = models.Author.objects.create(
|
||||
cls.second_author = models.Author.objects.create(
|
||||
name="Author Two", aliases=["The Second"]
|
||||
)
|
||||
|
||||
self.work = models.Work.objects.create(title="Example Work")
|
||||
cls.work = models.Work.objects.create(title="Example Work")
|
||||
|
||||
self.first_edition = models.Edition.objects.create(
|
||||
cls.first_edition = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
isbn_10="0000000000",
|
||||
physical_format="Paperback",
|
||||
published_date=datetime.datetime(2019, 4, 9, 0, 0, tzinfo=timezone.utc),
|
||||
)
|
||||
self.first_edition.authors.add(self.first_author)
|
||||
cls.first_edition.authors.add(cls.first_author)
|
||||
|
||||
self.second_edition = models.Edition.objects.create(
|
||||
cls.second_edition = models.Edition.objects.create(
|
||||
title="Another Edition",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
isbn_10="1111111111",
|
||||
openlibrary_key="hello",
|
||||
pages=150,
|
||||
)
|
||||
self.second_edition.authors.add(self.first_author)
|
||||
self.second_edition.authors.add(self.second_author)
|
||||
cls.second_edition.authors.add(cls.first_author)
|
||||
cls.second_edition.authors.add(cls.second_author)
|
||||
|
||||
self.third_edition = models.Edition.objects.create(
|
||||
cls.third_edition = models.Edition.objects.create(
|
||||
title="Another Edition with annoying ISBN",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
isbn_10="022222222X",
|
||||
)
|
||||
self.third_edition.authors.add(self.first_author)
|
||||
self.third_edition.authors.add(self.second_author)
|
||||
cls.third_edition.authors.add(cls.first_author)
|
||||
cls.third_edition.authors.add(cls.second_author)
|
||||
|
||||
def test_search(self):
|
||||
"""search for a book in the db"""
|
||||
|
|
|
@ -12,21 +12,23 @@ class ContextProcessor(TestCase):
|
|||
"""pages you land on without really trying"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.anonymous_user = AnonymousUser
|
||||
self.anonymous_user.is_authenticated = False
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
cls.anonymous_user = AnonymousUser
|
||||
cls.anonymous_user.is_authenticated = False
|
||||
cls.site = models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""other test data"""
|
||||
|
|
|
@ -12,12 +12,14 @@ class Emailing(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
|
|
@ -21,19 +21,21 @@ from bookwyrm.preview_images import (
|
|||
|
||||
# pylint: disable=unused-argument
|
||||
# pylint: disable=missing-function-docstring
|
||||
# pylint: disable=consider-using-with
|
||||
class PreviewImages(TestCase):
|
||||
"""every response to a get request, html or json"""
|
||||
|
||||
def setUp(self):
|
||||
"""we need basic test data and mocks"""
|
||||
self.factory = RequestFactory()
|
||||
avatar_file = pathlib.Path(__file__).parent.joinpath(
|
||||
avatar_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../static/images/no_cover.jpg"
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
open(avatar_path, "rb") as avatar_file,
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"possum@local.com",
|
||||
"possum@possum.possum",
|
||||
|
@ -41,15 +43,17 @@ class PreviewImages(TestCase):
|
|||
local=True,
|
||||
localname="possum",
|
||||
avatar=SimpleUploadedFile(
|
||||
avatar_file,
|
||||
open(avatar_file, "rb").read(),
|
||||
avatar_path,
|
||||
avatar_file.read(),
|
||||
content_type="image/jpeg",
|
||||
),
|
||||
)
|
||||
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
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.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
|
@ -60,9 +64,12 @@ class PreviewImages(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
open(avatar_path, "rb") as avatar_file,
|
||||
):
|
||||
self.remote_user_with_preview = models.User.objects.create_user(
|
||||
"badger@your.domain.here",
|
||||
"badger@badger.com",
|
||||
|
@ -72,8 +79,8 @@ class PreviewImages(TestCase):
|
|||
inbox="https://example.com/users/badger/inbox",
|
||||
outbox="https://example.com/users/badger/outbox",
|
||||
avatar=SimpleUploadedFile(
|
||||
avatar_file,
|
||||
open(avatar_file, "rb").read(),
|
||||
avatar_path,
|
||||
avatar_file.read(),
|
||||
content_type="image/jpeg",
|
||||
),
|
||||
)
|
||||
|
@ -90,7 +97,7 @@ class PreviewImages(TestCase):
|
|||
settings.ENABLE_PREVIEW_IMAGES = True
|
||||
|
||||
def test_generate_preview_image(self, *args, **kwargs):
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../static/images/no_cover.jpg"
|
||||
)
|
||||
|
||||
|
@ -99,7 +106,7 @@ class PreviewImages(TestCase):
|
|||
"text_three": "@possum@local.com",
|
||||
}
|
||||
|
||||
result = generate_preview_image(texts=texts, picture=image_file, rating=5)
|
||||
result = generate_preview_image(texts=texts, picture=image_path, rating=5)
|
||||
self.assertIsInstance(result, Image.Image)
|
||||
self.assertEqual(
|
||||
result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT)
|
||||
|
|
|
@ -36,22 +36,24 @@ class Signature(TestCase):
|
|||
"""signature test"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""create users and test 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"):
|
||||
self.mouse = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.mouse = models.User.objects.create_user(
|
||||
f"mouse@{DOMAIN}",
|
||||
"mouse@example.com",
|
||||
"",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.rat = models.User.objects.create_user(
|
||||
cls.rat = models.User.objects.create_user(
|
||||
f"rat@{DOMAIN}", "rat@example.com", "", local=True, localname="rat"
|
||||
)
|
||||
self.cat = models.User.objects.create_user(
|
||||
cls.cat = models.User.objects.create_user(
|
||||
f"cat@{DOMAIN}", "cat@example.com", "", local=True, localname="cat"
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
@ -89,9 +91,11 @@ class Signature(TestCase):
|
|||
signature = make_signature(
|
||||
"post", signer or sender, self.rat.inbox, now, digest=digest
|
||||
)
|
||||
with patch("bookwyrm.views.inbox.activity_task.apply_async"):
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
return self.send(signature, now, send_data or data, digest)
|
||||
with (
|
||||
patch("bookwyrm.views.inbox.activity_task.apply_async"),
|
||||
patch("bookwyrm.models.user.set_remote_server.delay"),
|
||||
):
|
||||
return self.send(signature, now, send_data or data, digest)
|
||||
|
||||
def test_correct_signature(self):
|
||||
"""this one should just work"""
|
||||
|
|
|
@ -22,9 +22,11 @@ class SuggestedUsers(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""use a test csv"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||
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", "password", local=True, localname="mouse"
|
||||
)
|
||||
|
|
|
@ -12,12 +12,14 @@ class AnnouncementViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
|
|
@ -16,12 +16,14 @@ class AutomodViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -31,7 +33,7 @@ class AutomodViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -15,12 +15,14 @@ class CeleryStatusViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,7 +32,7 @@ class CeleryStatusViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -15,12 +15,14 @@ class DashboardViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,7 +32,7 @@ class DashboardViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@ class EmailBlocklistViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,7 +32,7 @@ class EmailBlocklistViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@ class EmailConfigViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,7 +32,7 @@ class EmailConfigViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
""" test for app action functionality """
|
||||
import os
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
|
@ -18,12 +17,14 @@ class FederationViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -31,7 +32,7 @@ class FederationViews(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -43,7 +44,7 @@ class FederationViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
@ -177,7 +178,6 @@ class FederationViews(TestCase):
|
|||
self.assertEqual(server.application_type, "coolsoft")
|
||||
self.assertEqual(server.status, "blocked")
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
def test_import_blocklist(self):
|
||||
"""load a json file with a list of servers to block"""
|
||||
server = models.FederatedServer.objects.create(server_name="hi.there.com")
|
||||
|
@ -189,14 +189,13 @@ class FederationViews(TestCase):
|
|||
{"instance": "hi.there.com", "url": "https://explanation.url"}, # existing
|
||||
{"a": "b"}, # invalid
|
||||
]
|
||||
json.dump(data, open("file.json", "w")) # pylint: disable=unspecified-encoding
|
||||
|
||||
view = views.ImportServerBlocklist.as_view()
|
||||
request = self.factory.post(
|
||||
"",
|
||||
{
|
||||
"json_file": SimpleUploadedFile(
|
||||
"file.json", open("file.json", "rb").read()
|
||||
"file.json", json.dumps(data).encode("utf-8")
|
||||
)
|
||||
},
|
||||
)
|
||||
|
@ -212,6 +211,3 @@ class FederationViews(TestCase):
|
|||
created = models.FederatedServer.objects.get(server_name="server.name")
|
||||
self.assertEqual(created.status, "blocked")
|
||||
self.assertEqual(created.notes, "https://explanation.url")
|
||||
|
||||
# remove file.json after test
|
||||
os.remove("file.json")
|
||||
|
|
|
@ -15,12 +15,14 @@ class ImportsAdminViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,7 +32,7 @@ class ImportsAdminViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -15,12 +15,14 @@ class IPBlocklistViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,7 +32,7 @@ class IPBlocklistViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@ class LinkDomainViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,13 +32,13 @@ class LinkDomainViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
self.book = models.Edition.objects.create(title="hello")
|
||||
cls.book = models.Edition.objects.create(title="hello")
|
||||
models.FileLink.objects.create(
|
||||
book=self.book,
|
||||
book=cls.book,
|
||||
url="https://beep.com/book/1",
|
||||
added_by=self.local_user,
|
||||
added_by=cls.local_user,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
|
|
@ -16,19 +16,21 @@ class ReportViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.rat = models.User.objects.create_user(
|
||||
cls.rat = models.User.objects.create_user(
|
||||
"rat@local.com",
|
||||
"rat@mouse.mouse",
|
||||
"password",
|
||||
|
@ -38,7 +40,7 @@ class ReportViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -15,12 +15,14 @@ class SiteSettingsViews(TestCase):
|
|||
"""Edit site settings"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -30,9 +32,9 @@ class SiteSettingsViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
cls.site = models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -16,19 +16,21 @@ class AdminThemesViews(TestCase):
|
|||
"""Edit site settings"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
cls.another_user = models.User.objects.create_user(
|
||||
"rat@local.com",
|
||||
"rat@rat.rat",
|
||||
"password",
|
||||
|
@ -38,9 +40,9 @@ class AdminThemesViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="admin")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
|
||||
self.site = models.SiteSettings.objects.create()
|
||||
cls.site = models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
"""individual test setup"""
|
||||
|
|
|
@ -16,12 +16,14 @@ class UserAdminViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -31,7 +33,7 @@ class UserAdminViews(TestCase):
|
|||
initdb.init_groups()
|
||||
initdb.init_permissions()
|
||||
group = Group.objects.get(name="moderator")
|
||||
self.local_user.groups.set([group])
|
||||
cls.local_user.groups.set([group])
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
""" test for app action functionality """
|
||||
from io import BytesIO
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
from PIL import Image
|
||||
|
||||
import responses
|
||||
|
||||
|
@ -24,12 +22,14 @@ class BookViews(TestCase):
|
|||
"""books books books"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
|
@ -37,19 +37,19 @@ class BookViews(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
self.group = Group.objects.create(name="editor")
|
||||
self.group.permissions.add(
|
||||
cls.group = Group.objects.create(name="editor")
|
||||
cls.group.permissions.add(
|
||||
Permission.objects.create(
|
||||
name="edit_book",
|
||||
codename="edit_book",
|
||||
content_type=ContentType.objects.get_for_model(models.User),
|
||||
).id
|
||||
)
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
@ -159,15 +159,15 @@ class BookViews(TestCase):
|
|||
def test_upload_cover_file(self):
|
||||
"""add a cover via file upload"""
|
||||
self.assertFalse(self.book.cover)
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../../static/images/default_avi.jpg"
|
||||
)
|
||||
|
||||
form = forms.CoverForm(instance=self.book)
|
||||
# pylint: disable=consider-using-with
|
||||
form.data["cover"] = SimpleUploadedFile(
|
||||
image_file, open(image_file, "rb").read(), content_type="image/jpeg"
|
||||
)
|
||||
with open(image_path, "rb") as image_file:
|
||||
form.data["cover"] = SimpleUploadedFile(
|
||||
image_path, image_file.read(), content_type="image/jpeg"
|
||||
)
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
@ -294,16 +294,14 @@ class BookViews(TestCase):
|
|||
def _setup_cover_url():
|
||||
"""creates cover url mock"""
|
||||
cover_url = "http://example.com"
|
||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||
image_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../../static/images/default_avi.jpg"
|
||||
)
|
||||
image = Image.open(image_file)
|
||||
output = BytesIO()
|
||||
image.save(output, format=image.format)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
cover_url,
|
||||
body=output.getvalue(),
|
||||
status=200,
|
||||
)
|
||||
with open(image_path, "rb") as image_file:
|
||||
responses.add(
|
||||
responses.GET,
|
||||
cover_url,
|
||||
body=image_file.read(),
|
||||
status=200,
|
||||
)
|
||||
return cover_url
|
||||
|
|
|
@ -20,12 +20,14 @@ class EditBookViews(TestCase):
|
|||
"""books books books"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
|
@ -33,19 +35,19 @@ class EditBookViews(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
self.group = Group.objects.create(name="editor")
|
||||
self.group.permissions.add(
|
||||
cls.group = Group.objects.create(name="editor")
|
||||
cls.group.permissions.add(
|
||||
Permission.objects.create(
|
||||
name="edit_book",
|
||||
codename="edit_book",
|
||||
content_type=ContentType.objects.get_for_model(models.User),
|
||||
).id
|
||||
)
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -14,12 +14,14 @@ class BookViews(TestCase):
|
|||
"""books books books"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
|
@ -27,11 +29,11 @@ class BookViews(TestCase):
|
|||
localname="mouse",
|
||||
remote_id="https://example.com/users/mouse",
|
||||
)
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
physical_format="paperback",
|
||||
)
|
||||
|
||||
|
|
|
@ -16,12 +16,13 @@ class LinkViews(TestCase):
|
|||
"""books books books"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
|
@ -37,13 +38,13 @@ class LinkViews(TestCase):
|
|||
content_type=ContentType.objects.get_for_model(models.User),
|
||||
).id
|
||||
)
|
||||
self.local_user.groups.add(group)
|
||||
cls.local_user.groups.add(group)
|
||||
|
||||
self.work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.work = models.Work.objects.create(title="Test Work")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
|
|
@ -17,12 +17,14 @@ class ImportViews(TestCase):
|
|||
"""goodreads import views"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -79,13 +81,13 @@ class ImportViews(TestCase):
|
|||
form.data["source"] = "Goodreads"
|
||||
form.data["privacy"] = "public"
|
||||
form.data["include_reviews"] = False
|
||||
csv_file = pathlib.Path(__file__).parent.joinpath("../../data/goodreads.csv")
|
||||
form.data["csv_file"] = SimpleUploadedFile(
|
||||
# pylint: disable=consider-using-with
|
||||
csv_file,
|
||||
open(csv_file, "rb").read(),
|
||||
content_type="text/csv",
|
||||
)
|
||||
csv_path = pathlib.Path(__file__).parent.joinpath("../../data/goodreads.csv")
|
||||
with open(csv_path, "rb") as csv_file:
|
||||
form.data["csv_file"] = SimpleUploadedFile(
|
||||
csv_path,
|
||||
csv_file.read(),
|
||||
content_type="text/csv",
|
||||
)
|
||||
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
|
|
@ -12,12 +12,14 @@ class ImportManualReviewViews(TestCase):
|
|||
"""goodreads import views"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
@ -25,10 +27,10 @@ class ImportManualReviewViews(TestCase):
|
|||
localname="mouse",
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
self.job = models.ImportJob.objects.create(user=self.local_user, mappings={})
|
||||
cls.job = models.ImportJob.objects.create(user=cls.local_user, mappings={})
|
||||
|
||||
work = models.Work.objects.create(title="Test Work")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Example Edition",
|
||||
remote_id="https://example.com/book/1",
|
||||
parent_work=work,
|
||||
|
|
|
@ -13,12 +13,14 @@ class ImportTroubleshootViews(TestCase):
|
|||
"""goodreads import views"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
|
|
@ -18,9 +18,11 @@ class ImportUserViews(TestCase):
|
|||
def setUp(self):
|
||||
"""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"):
|
||||
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@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
|
@ -45,16 +47,16 @@ class ImportUserViews(TestCase):
|
|||
|
||||
view = views.UserImport.as_view()
|
||||
form = forms.ImportUserForm()
|
||||
archive_file = pathlib.Path(__file__).parent.joinpath(
|
||||
archive_path = pathlib.Path(__file__).parent.joinpath(
|
||||
"../../data/bookwyrm_account_export.tar.gz"
|
||||
)
|
||||
|
||||
form.data["archive_file"] = SimpleUploadedFile(
|
||||
# pylint: disable=consider-using-with
|
||||
archive_file,
|
||||
open(archive_file, "rb").read(),
|
||||
content_type="application/gzip",
|
||||
)
|
||||
with open(archive_path, "rb") as archive_file:
|
||||
form.data["archive_file"] = SimpleUploadedFile(
|
||||
archive_path,
|
||||
archive_file.read(),
|
||||
content_type="application/gzip",
|
||||
)
|
||||
|
||||
form.data["include_user_settings"] = ""
|
||||
form.data["include_goals"] = "on"
|
||||
|
|
|
@ -29,11 +29,13 @@ class Inbox(TestCase):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
|
@ -44,7 +46,7 @@ class Inbox(TestCase):
|
|||
local_user.remote_id = "https://example.com/user/mouse"
|
||||
local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -12,11 +12,13 @@ class InboxAdd(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
|
@ -27,7 +29,7 @@ class InboxAdd(TestCase):
|
|||
local_user.remote_id = "https://example.com/user/mouse"
|
||||
local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -38,7 +40,7 @@ class InboxAdd(TestCase):
|
|||
)
|
||||
|
||||
work = models.Work.objects.create(title="work title")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test",
|
||||
remote_id="https://example.com/book/37292",
|
||||
parent_work=work,
|
||||
|
|
|
@ -12,22 +12,24 @@ class InboxActivities(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -37,13 +39,15 @@ class InboxActivities(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.activitystreams.add_status_task.delay"),
|
||||
):
|
||||
cls.status = models.Status.objects.create(
|
||||
user=cls.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -11,22 +11,24 @@ class InboxBlock(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -56,9 +58,12 @@ class InboxBlock(TestCase):
|
|||
"object": "https://example.com/user/mouse",
|
||||
}
|
||||
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
|
||||
) as redis_mock, patch("bookwyrm.lists_stream.remove_user_lists_task.delay"):
|
||||
with (
|
||||
patch(
|
||||
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
|
||||
) as redis_mock,
|
||||
patch("bookwyrm.lists_stream.remove_user_lists_task.delay"),
|
||||
):
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertTrue(redis_mock.called)
|
||||
views.inbox.activity_task(activity)
|
||||
|
|
|
@ -15,9 +15,11 @@ class TransactionInboxCreate(TransactionTestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""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"):
|
||||
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@example.com",
|
||||
"mouse@mouse.com",
|
||||
|
@ -72,22 +74,24 @@ class InboxCreate(TestCase):
|
|||
"""readthrough tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -12,22 +12,24 @@ class InboxActivities(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -37,8 +39,8 @@ class InboxActivities(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.remote_user,
|
||||
cls.status = models.Status.objects.create(
|
||||
user=cls.remote_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
|
|
@ -12,22 +12,24 @@ class InboxRelationships(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
|
|
@ -11,22 +11,24 @@ class InboxActivities(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -36,13 +38,15 @@ class InboxActivities(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
self.status = models.Status.objects.create(
|
||||
user=self.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.activitystreams.add_status_task.delay"),
|
||||
):
|
||||
cls.status = models.Status.objects.create(
|
||||
user=cls.local_user,
|
||||
content="Test status",
|
||||
remote_id="https://example.com/status/1",
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
|
|
|
@ -11,22 +11,24 @@ class InboxRemove(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -36,11 +38,11 @@ class InboxRemove(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
self.work = models.Work.objects.create(title="work title")
|
||||
self.book = models.Edition.objects.create(
|
||||
cls.work = models.Work.objects.create(title="work title")
|
||||
cls.book = models.Edition.objects.create(
|
||||
title="Test",
|
||||
remote_id="https://bookwyrm.social/book/37292",
|
||||
parent_work=self.work,
|
||||
parent_work=cls.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
@ -76,9 +78,10 @@ class InboxRemove(TestCase):
|
|||
|
||||
def test_handle_remove_book_from_list(self):
|
||||
"""listing a book"""
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.lists_stream.remove_list_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
):
|
||||
booklist = models.List.objects.create(
|
||||
name="test list",
|
||||
user=self.local_user,
|
||||
|
|
|
@ -13,22 +13,24 @@ class InboxUpdate(TestCase):
|
|||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""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"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
"rat@rat.com",
|
||||
"ratword",
|
||||
|
@ -53,9 +55,10 @@ class InboxUpdate(TestCase):
|
|||
|
||||
def test_update_list(self):
|
||||
"""a new list"""
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
), patch("bookwyrm.lists_stream.remove_list_task.delay"):
|
||||
with (
|
||||
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
|
||||
patch("bookwyrm.lists_stream.remove_list_task.delay"),
|
||||
):
|
||||
book_list = models.List.objects.create(
|
||||
name="hi", remote_id="https://example.com/list/22", user=self.local_user
|
||||
)
|
||||
|
|
|
@ -15,12 +15,14 @@ class InviteViews(TestCase):
|
|||
"""every response to a get request, html or json"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
|
|
@ -15,12 +15,14 @@ class LandingViews(TestCase):
|
|||
"""pages you land on without really trying"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@local.com",
|
||||
"mouse@mouse.mouse",
|
||||
"password",
|
||||
|
|
|
@ -18,12 +18,14 @@ class LoginViews(TestCase):
|
|||
"""login and password management"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self): # pylint: disable=bad-classmethod-argument
|
||||
def setUpTestData(cls):
|
||||
"""we need basic test data and mocks"""
|
||||
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(
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
patch("bookwyrm.activitystreams.populate_stream_task.delay"),
|
||||
patch("bookwyrm.lists_stream.populate_lists_task.delay"),
|
||||
):
|
||||
cls.local_user = models.User.objects.create_user(
|
||||
"mouse@your.domain.here",
|
||||
"mouse@mouse.com",
|
||||
"password",
|
||||
|
@ -31,14 +33,14 @@ class LoginViews(TestCase):
|
|||
localname="mouse",
|
||||
two_factor_auth=False,
|
||||
)
|
||||
self.rat = models.User.objects.create_user(
|
||||
cls.rat = models.User.objects.create_user(
|
||||
"rat@your.domain.here",
|
||||
"rat@rat.com",
|
||||
"password",
|
||||
local=True,
|
||||
localname="rat",
|
||||
)
|
||||
self.badger = models.User.objects.create_user(
|
||||
cls.badger = models.User.objects.create_user(
|
||||
"badger@your.domain.here",
|
||||
"badger@badger.com",
|
||||
"password",
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue