forked from mirrors/bookwyrm
Merge pull request #1142 from joachimesque/opengraph-image-generation
Generate OpenGraph images for books, users, and site.
This commit is contained in:
commit
ea556bd83b
101 changed files with 2738 additions and 1560 deletions
|
@ -41,3 +41,15 @@ EMAIL_HOST_USER=mail@your.domain.here
|
||||||
EMAIL_HOST_PASSWORD=emailpassword123
|
EMAIL_HOST_PASSWORD=emailpassword123
|
||||||
EMAIL_USE_TLS=true
|
EMAIL_USE_TLS=true
|
||||||
EMAIL_USE_SSL=false
|
EMAIL_USE_SSL=false
|
||||||
|
|
||||||
|
# Preview image generation can be computing and storage intensive
|
||||||
|
# ENABLE_PREVIEW_IMAGES=True
|
||||||
|
|
||||||
|
# Specify RGB tuple or RGB hex strings,
|
||||||
|
# or use_dominant_color_light / use_dominant_color_dark
|
||||||
|
PREVIEW_BG_COLOR=use_dominant_color_light
|
||||||
|
# Change to #FFF if you use use_dominant_color_dark
|
||||||
|
PREVIEW_TEXT_COLOR="#363636"
|
||||||
|
PREVIEW_IMG_WIDTH=1200
|
||||||
|
PREVIEW_IMG_HEIGHT=630
|
||||||
|
PREVIEW_DEFAULT_COVER_COLOR="#002549"
|
||||||
|
|
|
@ -41,3 +41,15 @@ EMAIL_HOST_USER=mail@your.domain.here
|
||||||
EMAIL_HOST_PASSWORD=emailpassword123
|
EMAIL_HOST_PASSWORD=emailpassword123
|
||||||
EMAIL_USE_TLS=true
|
EMAIL_USE_TLS=true
|
||||||
EMAIL_USE_SSL=false
|
EMAIL_USE_SSL=false
|
||||||
|
|
||||||
|
# Preview image generation can be computing and storage intensive
|
||||||
|
# ENABLE_PREVIEW_IMAGES=True
|
||||||
|
|
||||||
|
# Specify RGB tuple or RGB hex strings,
|
||||||
|
# or use_dominant_color_light / use_dominant_color_dark
|
||||||
|
PREVIEW_BG_COLOR=use_dominant_color_light
|
||||||
|
# Change to #FFF if you use use_dominant_color_dark
|
||||||
|
PREVIEW_TEXT_COLOR="#363636"
|
||||||
|
PREVIEW_IMG_WIDTH=1200
|
||||||
|
PREVIEW_IMG_HEIGHT=630
|
||||||
|
PREVIEW_DEFAULT_COVER_COLOR="#002549"
|
||||||
|
|
1
.github/workflows/django-tests.yml
vendored
1
.github/workflows/django-tests.yml
vendored
|
@ -64,5 +64,6 @@ jobs:
|
||||||
EMAIL_HOST_USER: ""
|
EMAIL_HOST_USER: ""
|
||||||
EMAIL_HOST_PASSWORD: ""
|
EMAIL_HOST_PASSWORD: ""
|
||||||
EMAIL_USE_TLS: true
|
EMAIL_USE_TLS: true
|
||||||
|
ENABLE_PREVIEW_IMAGES: true
|
||||||
run: |
|
run: |
|
||||||
python manage.py test
|
python manage.py test
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -27,3 +27,6 @@
|
||||||
|
|
||||||
#nginx
|
#nginx
|
||||||
nginx/default.conf
|
nginx/default.conf
|
||||||
|
|
||||||
|
#macOS
|
||||||
|
**/.DS_Store
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
""" customize the info available in context for rendering templates """
|
""" customize the info available in context for rendering templates """
|
||||||
from bookwyrm import models
|
from bookwyrm import models, settings
|
||||||
|
|
||||||
|
|
||||||
def site_settings(request): # pylint: disable=unused-argument
|
def site_settings(request): # pylint: disable=unused-argument
|
||||||
"""include the custom info about the site"""
|
"""include the custom info about the site"""
|
||||||
|
request_protocol = "https://"
|
||||||
|
if not request.is_secure():
|
||||||
|
request_protocol = "http://"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"site": models.SiteSettings.objects.get(),
|
"site": models.SiteSettings.objects.get(),
|
||||||
"active_announcements": models.Announcement.active_announcements(),
|
"active_announcements": models.Announcement.active_announcements(),
|
||||||
|
"static_url": settings.STATIC_URL,
|
||||||
|
"media_url": settings.MEDIA_URL,
|
||||||
|
"static_path": settings.STATIC_PATH,
|
||||||
|
"media_path": settings.MEDIA_PATH,
|
||||||
|
"preview_images_enabled": settings.ENABLE_PREVIEW_IMAGES,
|
||||||
|
"request_protocol": request_protocol,
|
||||||
}
|
}
|
||||||
|
|
64
bookwyrm/management/commands/generate_preview_images.py
Normal file
64
bookwyrm/management/commands/generate_preview_images.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
""" Generate preview images """
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from bookwyrm import activitystreams, models, settings, preview_images
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Generate preview images"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"--all",
|
||||||
|
"-a",
|
||||||
|
action="store_true",
|
||||||
|
help="Generates images for ALL types: site, users and books. Can use a lot of computing power.",
|
||||||
|
)
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use,unused-argument
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
"""generate preview images"""
|
||||||
|
self.stdout.write(
|
||||||
|
" | Hello! I will be generating preview images for your instance."
|
||||||
|
)
|
||||||
|
if options["all"]:
|
||||||
|
self.stdout.write(
|
||||||
|
"🧑🎨 ⎨ This might take quite long if your instance has a lot of books and users."
|
||||||
|
)
|
||||||
|
self.stdout.write(" | ✧ Thank you for your patience ✧")
|
||||||
|
else:
|
||||||
|
self.stdout.write("🧑🎨 ⎨ I will only generate the instance preview image.")
|
||||||
|
self.stdout.write(" | ✧ Be right back! ✧")
|
||||||
|
|
||||||
|
# Site
|
||||||
|
self.stdout.write(" → Site preview image: ", ending="")
|
||||||
|
preview_images.generate_site_preview_image_task.delay()
|
||||||
|
self.stdout.write(" OK 🖼")
|
||||||
|
|
||||||
|
if options["all"]:
|
||||||
|
# Users
|
||||||
|
users = models.User.objects.filter(
|
||||||
|
local=True,
|
||||||
|
is_active=True,
|
||||||
|
)
|
||||||
|
self.stdout.write(
|
||||||
|
" → User preview images ({}): ".format(len(users)), ending=""
|
||||||
|
)
|
||||||
|
for user in users:
|
||||||
|
preview_images.generate_user_preview_image_task.delay(user.id)
|
||||||
|
self.stdout.write(".", ending="")
|
||||||
|
self.stdout.write(" OK 🖼")
|
||||||
|
|
||||||
|
# Books
|
||||||
|
books = models.Book.objects.select_subclasses().filter()
|
||||||
|
self.stdout.write(
|
||||||
|
" → Book preview images ({}): ".format(len(books)), ending=""
|
||||||
|
)
|
||||||
|
for book in books:
|
||||||
|
preview_images.generate_edition_preview_image_task.delay(book.id)
|
||||||
|
self.stdout.write(".", ending="")
|
||||||
|
self.stdout.write(" OK 🖼")
|
||||||
|
|
||||||
|
self.stdout.write("🧑🎨 ⎨ I’m all done! ✧ Enjoy ✧")
|
32
bookwyrm/migrations/0076_preview_images.py
Normal file
32
bookwyrm/migrations/0076_preview_images.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Generated by Django 3.2 on 2021-05-26 12:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookwyrm", "0075_announcement"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="book",
|
||||||
|
name="preview_image",
|
||||||
|
field=models.ImageField(
|
||||||
|
blank=True, null=True, upload_to="previews/covers/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="sitesettings",
|
||||||
|
name="preview_image",
|
||||||
|
field=models.ImageField(blank=True, null=True, upload_to="previews/logos/"),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="preview_image",
|
||||||
|
field=models.ImageField(
|
||||||
|
blank=True, null=True, upload_to="previews/avatars/"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,10 +2,14 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from model_utils import FieldTracker
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
|
from bookwyrm.preview_images import generate_edition_preview_image_task
|
||||||
from bookwyrm.settings import DOMAIN, DEFAULT_LANGUAGE
|
from bookwyrm.settings import DOMAIN, DEFAULT_LANGUAGE
|
||||||
|
from bookwyrm.tasks import app
|
||||||
|
|
||||||
from .activitypub_mixin import OrderedCollectionPageMixin, ObjectMixin
|
from .activitypub_mixin import OrderedCollectionPageMixin, ObjectMixin
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
|
@ -82,10 +86,14 @@ class Book(BookDataModel):
|
||||||
cover = fields.ImageField(
|
cover = fields.ImageField(
|
||||||
upload_to="covers/", blank=True, null=True, alt_field="alt_text"
|
upload_to="covers/", blank=True, null=True, alt_field="alt_text"
|
||||||
)
|
)
|
||||||
|
preview_image = models.ImageField(
|
||||||
|
upload_to="previews/covers/", blank=True, null=True
|
||||||
|
)
|
||||||
first_published_date = fields.DateTimeField(blank=True, null=True)
|
first_published_date = fields.DateTimeField(blank=True, null=True)
|
||||||
published_date = fields.DateTimeField(blank=True, null=True)
|
published_date = fields.DateTimeField(blank=True, null=True)
|
||||||
|
|
||||||
objects = InheritanceManager()
|
objects = InheritanceManager()
|
||||||
|
field_tracker = FieldTracker(fields=["authors", "title", "subtitle", "cover"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def author_text(self):
|
def author_text(self):
|
||||||
|
@ -293,3 +301,14 @@ def isbn_13_to_10(isbn_13):
|
||||||
if checkdigit == 10:
|
if checkdigit == 10:
|
||||||
checkdigit = "X"
|
checkdigit = "X"
|
||||||
return converted + str(checkdigit)
|
return converted + str(checkdigit)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.post_save, sender=Edition)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def preview_image(instance, *args, **kwargs):
|
||||||
|
changed_fields = {}
|
||||||
|
if instance.field_tracker:
|
||||||
|
changed_fields = instance.field_tracker.changed()
|
||||||
|
|
||||||
|
if len(changed_fields) > 0:
|
||||||
|
generate_edition_preview_image_task.delay(instance.id)
|
||||||
|
|
|
@ -4,9 +4,13 @@ import datetime
|
||||||
|
|
||||||
from Crypto import Random
|
from Crypto import Random
|
||||||
from django.db import models, IntegrityError
|
from django.db import models, IntegrityError
|
||||||
|
from django.dispatch import receiver
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from model_utils import FieldTracker
|
||||||
|
|
||||||
|
from bookwyrm.preview_images import generate_site_preview_image_task
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
from bookwyrm.tasks import app
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
|
@ -35,6 +39,9 @@ class SiteSettings(models.Model):
|
||||||
logo = models.ImageField(upload_to="logos/", null=True, blank=True)
|
logo = models.ImageField(upload_to="logos/", null=True, blank=True)
|
||||||
logo_small = models.ImageField(upload_to="logos/", null=True, blank=True)
|
logo_small = models.ImageField(upload_to="logos/", null=True, blank=True)
|
||||||
favicon = models.ImageField(upload_to="logos/", null=True, blank=True)
|
favicon = models.ImageField(upload_to="logos/", null=True, blank=True)
|
||||||
|
preview_image = models.ImageField(
|
||||||
|
upload_to="previews/logos/", null=True, blank=True
|
||||||
|
)
|
||||||
|
|
||||||
# footer
|
# footer
|
||||||
support_link = models.CharField(max_length=255, null=True, blank=True)
|
support_link = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
@ -42,6 +49,8 @@ class SiteSettings(models.Model):
|
||||||
admin_email = models.EmailField(max_length=255, null=True, blank=True)
|
admin_email = models.EmailField(max_length=255, null=True, blank=True)
|
||||||
footer_item = models.TextField(null=True, blank=True)
|
footer_item = models.TextField(null=True, blank=True)
|
||||||
|
|
||||||
|
field_tracker = FieldTracker(fields=["name", "instance_tagline", "logo"])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls):
|
def get(cls):
|
||||||
"""gets the site settings db entry or defaults"""
|
"""gets the site settings db entry or defaults"""
|
||||||
|
@ -119,3 +128,12 @@ class PasswordReset(models.Model):
|
||||||
def link(self):
|
def link(self):
|
||||||
"""formats the invite link"""
|
"""formats the invite link"""
|
||||||
return "https://{}/password-reset/{}".format(DOMAIN, self.code)
|
return "https://{}/password-reset/{}".format(DOMAIN, self.code)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.post_save, sender=SiteSettings)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def preview_image(instance, *args, **kwargs):
|
||||||
|
changed_fields = instance.field_tracker.changed()
|
||||||
|
|
||||||
|
if len(changed_fields) > 0:
|
||||||
|
generate_site_preview_image_task.delay()
|
||||||
|
|
|
@ -5,11 +5,14 @@ import re
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.dispatch import receiver
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from model_utils import FieldTracker
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
|
from bookwyrm.preview_images import generate_edition_preview_image_task
|
||||||
from .activitypub_mixin import ActivitypubMixin, ActivityMixin
|
from .activitypub_mixin import ActivitypubMixin, ActivityMixin
|
||||||
from .activitypub_mixin import OrderedCollectionPageMixin
|
from .activitypub_mixin import OrderedCollectionPageMixin
|
||||||
from .base_model import BookWyrmModel
|
from .base_model import BookWyrmModel
|
||||||
|
@ -304,6 +307,8 @@ class Review(Status):
|
||||||
max_digits=3,
|
max_digits=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
field_tracker = FieldTracker(fields=["rating"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pure_name(self):
|
def pure_name(self):
|
||||||
"""clarify review names for mastodon serialization"""
|
"""clarify review names for mastodon serialization"""
|
||||||
|
@ -398,3 +403,14 @@ class Boost(ActivityMixin, Status):
|
||||||
# This constraint can't work as it would cross tables.
|
# This constraint can't work as it would cross tables.
|
||||||
# class Meta:
|
# class Meta:
|
||||||
# unique_together = ('user', 'boosted_status')
|
# unique_together = ('user', 'boosted_status')
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.post_save)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def preview_image(instance, sender, *args, **kwargs):
|
||||||
|
if sender in (Review, ReviewRating):
|
||||||
|
changed_fields = instance.field_tracker.changed()
|
||||||
|
|
||||||
|
if len(changed_fields) > 0:
|
||||||
|
edition = instance.book
|
||||||
|
generate_edition_preview_image_task.delay(edition.id)
|
||||||
|
|
|
@ -6,14 +6,17 @@ from django.apps import apps
|
||||||
from django.contrib.auth.models import AbstractUser, Group
|
from django.contrib.auth.models import AbstractUser, Group
|
||||||
from django.contrib.postgres.fields import CICharField
|
from django.contrib.postgres.fields import CICharField
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
from django.dispatch import receiver
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from model_utils import FieldTracker
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
from bookwyrm.connectors import get_data, ConnectorException
|
from bookwyrm.connectors import get_data, ConnectorException
|
||||||
from bookwyrm.models.shelf import Shelf
|
from bookwyrm.models.shelf import Shelf
|
||||||
from bookwyrm.models.status import Status, Review
|
from bookwyrm.models.status import Status, Review
|
||||||
|
from bookwyrm.preview_images import generate_user_preview_image_task
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
from bookwyrm.signatures import create_key_pair
|
from bookwyrm.signatures import create_key_pair
|
||||||
from bookwyrm.tasks import app
|
from bookwyrm.tasks import app
|
||||||
|
@ -70,6 +73,9 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||||
activitypub_field="icon",
|
activitypub_field="icon",
|
||||||
alt_field="alt_text",
|
alt_field="alt_text",
|
||||||
)
|
)
|
||||||
|
preview_image = models.ImageField(
|
||||||
|
upload_to="previews/avatars/", blank=True, null=True
|
||||||
|
)
|
||||||
followers = fields.ManyToManyField(
|
followers = fields.ManyToManyField(
|
||||||
"self",
|
"self",
|
||||||
link_only=True,
|
link_only=True,
|
||||||
|
@ -117,6 +123,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
||||||
|
|
||||||
name_field = "username"
|
name_field = "username"
|
||||||
property_fields = [("following_link", "following")]
|
property_fields = [("following_link", "following")]
|
||||||
|
field_tracker = FieldTracker(fields=["name", "avatar"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def following_link(self):
|
def following_link(self):
|
||||||
|
@ -443,3 +450,12 @@ def get_remote_reviews(outbox):
|
||||||
if not activity["type"] == "Review":
|
if not activity["type"] == "Review":
|
||||||
continue
|
continue
|
||||||
activitypub.Review(**activity).to_model()
|
activitypub.Review(**activity).to_model()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(models.signals.post_save, sender=User)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def preview_image(instance, *args, **kwargs):
|
||||||
|
changed_fields = instance.field_tracker.changed()
|
||||||
|
|
||||||
|
if len(changed_fields) > 0:
|
||||||
|
generate_user_preview_image_task.delay(instance.id)
|
||||||
|
|
412
bookwyrm/preview_images.py
Normal file
412
bookwyrm/preview_images.py
Normal file
|
@ -0,0 +1,412 @@
|
||||||
|
import colorsys
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
from colorthief import ColorThief
|
||||||
|
from io import BytesIO
|
||||||
|
from PIL import Image, ImageDraw, ImageFont, ImageOps, ImageColor
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from django.core.files.base import ContentFile
|
||||||
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||||
|
from django.db.models import Avg
|
||||||
|
|
||||||
|
from bookwyrm import models, settings
|
||||||
|
from bookwyrm.tasks import app
|
||||||
|
|
||||||
|
|
||||||
|
IMG_WIDTH = settings.PREVIEW_IMG_WIDTH
|
||||||
|
IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT
|
||||||
|
BG_COLOR = settings.PREVIEW_BG_COLOR
|
||||||
|
TEXT_COLOR = settings.PREVIEW_TEXT_COLOR
|
||||||
|
DEFAULT_COVER_COLOR = settings.PREVIEW_DEFAULT_COVER_COLOR
|
||||||
|
TRANSPARENT_COLOR = (0, 0, 0, 0)
|
||||||
|
|
||||||
|
margin = math.floor(IMG_HEIGHT / 10)
|
||||||
|
gutter = math.floor(margin / 2)
|
||||||
|
inner_img_height = math.floor(IMG_HEIGHT * 0.8)
|
||||||
|
inner_img_width = math.floor(inner_img_height * 0.7)
|
||||||
|
font_dir = os.path.join(settings.STATIC_ROOT, "fonts/public_sans")
|
||||||
|
|
||||||
|
|
||||||
|
def get_font(font_name, size=28):
|
||||||
|
if font_name == "light":
|
||||||
|
font_path = os.path.join(font_dir, "PublicSans-Light.ttf")
|
||||||
|
if font_name == "regular":
|
||||||
|
font_path = os.path.join(font_dir, "PublicSans-Regular.ttf")
|
||||||
|
elif font_name == "bold":
|
||||||
|
font_path = os.path.join(font_dir, "PublicSans-Bold.ttf")
|
||||||
|
|
||||||
|
try:
|
||||||
|
font = ImageFont.truetype(font_path, size)
|
||||||
|
except OSError:
|
||||||
|
font = ImageFont.load_default()
|
||||||
|
|
||||||
|
return font
|
||||||
|
|
||||||
|
|
||||||
|
def generate_texts_layer(texts, content_width):
|
||||||
|
font_text_zero = get_font("bold", size=20)
|
||||||
|
font_text_one = get_font("bold", size=48)
|
||||||
|
font_text_two = get_font("bold", size=40)
|
||||||
|
font_text_three = get_font("regular", size=40)
|
||||||
|
|
||||||
|
text_layer = Image.new("RGBA", (content_width, IMG_HEIGHT), color=TRANSPARENT_COLOR)
|
||||||
|
text_layer_draw = ImageDraw.Draw(text_layer)
|
||||||
|
|
||||||
|
text_y = 0
|
||||||
|
|
||||||
|
if "text_zero" in texts and texts["text_zero"]:
|
||||||
|
# Text one (Book title)
|
||||||
|
text_zero = textwrap.fill(texts["text_zero"], width=72)
|
||||||
|
text_layer_draw.multiline_text(
|
||||||
|
(0, text_y), text_zero, font=font_text_zero, fill=TEXT_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
text_y = text_y + font_text_zero.getsize_multiline(text_zero)[1] + 16
|
||||||
|
except:
|
||||||
|
text_y = text_y + 26
|
||||||
|
|
||||||
|
if "text_one" in texts and texts["text_one"]:
|
||||||
|
# Text one (Book title)
|
||||||
|
text_one = textwrap.fill(texts["text_one"], width=28)
|
||||||
|
text_layer_draw.multiline_text(
|
||||||
|
(0, text_y), text_one, font=font_text_one, fill=TEXT_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
text_y = text_y + font_text_one.getsize_multiline(text_one)[1] + 16
|
||||||
|
except:
|
||||||
|
text_y = text_y + 26
|
||||||
|
|
||||||
|
if "text_two" in texts and texts["text_two"]:
|
||||||
|
# Text one (Book subtitle)
|
||||||
|
text_two = textwrap.fill(texts["text_two"], width=36)
|
||||||
|
text_layer_draw.multiline_text(
|
||||||
|
(0, text_y), text_two, font=font_text_two, fill=TEXT_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
text_y = text_y + font_text_one.getsize_multiline(text_two)[1] + 16
|
||||||
|
except:
|
||||||
|
text_y = text_y + 26
|
||||||
|
|
||||||
|
if "text_three" in texts and texts["text_three"]:
|
||||||
|
# Text three (Book authors)
|
||||||
|
text_three = textwrap.fill(texts["text_three"], width=36)
|
||||||
|
text_layer_draw.multiline_text(
|
||||||
|
(0, text_y), text_three, font=font_text_three, fill=TEXT_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
|
text_layer_box = text_layer.getbbox()
|
||||||
|
return text_layer.crop(text_layer_box)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_instance_layer(content_width):
|
||||||
|
font_instance = get_font("light", size=28)
|
||||||
|
|
||||||
|
site = models.SiteSettings.objects.get()
|
||||||
|
|
||||||
|
if site.logo_small:
|
||||||
|
logo_img = Image.open(site.logo_small)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
static_path = os.path.join(settings.STATIC_ROOT, "images/logo-small.png")
|
||||||
|
logo_img = Image.open(static_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logo_img = None
|
||||||
|
|
||||||
|
instance_layer = Image.new("RGBA", (content_width, 62), color=TRANSPARENT_COLOR)
|
||||||
|
|
||||||
|
instance_text_x = 0
|
||||||
|
|
||||||
|
if logo_img:
|
||||||
|
logo_img.thumbnail((50, 50), Image.ANTIALIAS)
|
||||||
|
|
||||||
|
instance_layer.paste(logo_img, (0, 0))
|
||||||
|
|
||||||
|
instance_text_x = instance_text_x + 60
|
||||||
|
|
||||||
|
instance_layer_draw = ImageDraw.Draw(instance_layer)
|
||||||
|
instance_layer_draw.text(
|
||||||
|
(instance_text_x, 10), site.name, font=font_instance, fill=TEXT_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
|
line_width = 50 + 10 + font_instance.getsize(site.name)[0]
|
||||||
|
|
||||||
|
line_layer = Image.new(
|
||||||
|
"RGBA", (line_width, 2), color=(*(ImageColor.getrgb(TEXT_COLOR)), 50)
|
||||||
|
)
|
||||||
|
instance_layer.alpha_composite(line_layer, (0, 60))
|
||||||
|
|
||||||
|
return instance_layer
|
||||||
|
|
||||||
|
|
||||||
|
def generate_rating_layer(rating, content_width):
|
||||||
|
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")
|
||||||
|
)
|
||||||
|
|
||||||
|
icon_size = 64
|
||||||
|
icon_margin = 10
|
||||||
|
|
||||||
|
rating_layer_base = Image.new(
|
||||||
|
"RGBA", (content_width, icon_size), color=TRANSPARENT_COLOR
|
||||||
|
)
|
||||||
|
rating_layer_color = Image.new(
|
||||||
|
"RGBA", (content_width, icon_size), color=TEXT_COLOR
|
||||||
|
)
|
||||||
|
rating_layer_mask = Image.new(
|
||||||
|
"RGBA", (content_width, icon_size), color=TRANSPARENT_COLOR
|
||||||
|
)
|
||||||
|
|
||||||
|
position_x = 0
|
||||||
|
|
||||||
|
for r 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
|
||||||
|
|
||||||
|
for r 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
|
||||||
|
|
||||||
|
rating_layer_mask = rating_layer_mask.getchannel("A")
|
||||||
|
rating_layer_mask = ImageOps.invert(rating_layer_mask)
|
||||||
|
|
||||||
|
rating_layer_composite = Image.composite(
|
||||||
|
rating_layer_base, rating_layer_color, rating_layer_mask
|
||||||
|
)
|
||||||
|
|
||||||
|
return rating_layer_composite
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def generate_default_inner_img():
|
||||||
|
font_cover = get_font("light", size=28)
|
||||||
|
|
||||||
|
default_cover = Image.new(
|
||||||
|
"RGB", (inner_img_width, inner_img_height), color=DEFAULT_COVER_COLOR
|
||||||
|
)
|
||||||
|
default_cover_draw = ImageDraw.Draw(default_cover)
|
||||||
|
|
||||||
|
text = "no image :("
|
||||||
|
text_dimensions = font_cover.getsize(text)
|
||||||
|
text_coords = (
|
||||||
|
math.floor((inner_img_width - text_dimensions[0]) / 2),
|
||||||
|
math.floor((inner_img_height - text_dimensions[1]) / 2),
|
||||||
|
)
|
||||||
|
default_cover_draw.text(text_coords, text, font=font_cover, fill="white")
|
||||||
|
|
||||||
|
return default_cover
|
||||||
|
|
||||||
|
|
||||||
|
def generate_preview_image(
|
||||||
|
texts={}, picture=None, rating=None, show_instance_layer=True
|
||||||
|
):
|
||||||
|
# Cover
|
||||||
|
try:
|
||||||
|
inner_img_layer = Image.open(picture)
|
||||||
|
inner_img_layer.thumbnail((inner_img_width, inner_img_height), Image.ANTIALIAS)
|
||||||
|
color_thief = ColorThief(picture)
|
||||||
|
dominant_color = color_thief.get_color(quality=1)
|
||||||
|
except:
|
||||||
|
inner_img_layer = generate_default_inner_img()
|
||||||
|
dominant_color = ImageColor.getrgb(DEFAULT_COVER_COLOR)
|
||||||
|
|
||||||
|
# Color
|
||||||
|
if BG_COLOR in ["use_dominant_color_light", "use_dominant_color_dark"]:
|
||||||
|
image_bg_color = "rgb(%s, %s, %s)" % dominant_color
|
||||||
|
|
||||||
|
# Adjust color
|
||||||
|
image_bg_color_rgb = [x / 255.0 for x in ImageColor.getrgb(image_bg_color)]
|
||||||
|
image_bg_color_hls = colorsys.rgb_to_hls(*image_bg_color_rgb)
|
||||||
|
|
||||||
|
if BG_COLOR == "use_dominant_color_light":
|
||||||
|
lightness = max(0.9, image_bg_color_hls[1])
|
||||||
|
else:
|
||||||
|
lightness = min(0.15, image_bg_color_hls[1])
|
||||||
|
|
||||||
|
image_bg_color_hls = (
|
||||||
|
image_bg_color_hls[0],
|
||||||
|
lightness,
|
||||||
|
image_bg_color_hls[2],
|
||||||
|
)
|
||||||
|
image_bg_color = tuple(
|
||||||
|
[math.ceil(x * 255) for x in colorsys.hls_to_rgb(*image_bg_color_hls)]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
image_bg_color = BG_COLOR
|
||||||
|
|
||||||
|
# Background (using the color)
|
||||||
|
img = Image.new("RGBA", (IMG_WIDTH, IMG_HEIGHT), color=image_bg_color)
|
||||||
|
|
||||||
|
# Contents
|
||||||
|
inner_img_x = margin + inner_img_width - inner_img_layer.width
|
||||||
|
inner_img_y = math.floor((IMG_HEIGHT - inner_img_layer.height) / 2)
|
||||||
|
content_x = margin + inner_img_width + gutter
|
||||||
|
content_width = IMG_WIDTH - content_x - margin
|
||||||
|
|
||||||
|
contents_layer = Image.new(
|
||||||
|
"RGBA", (content_width, IMG_HEIGHT), color=TRANSPARENT_COLOR
|
||||||
|
)
|
||||||
|
contents_composite_y = 0
|
||||||
|
|
||||||
|
if show_instance_layer:
|
||||||
|
instance_layer = generate_instance_layer(content_width)
|
||||||
|
contents_layer.alpha_composite(instance_layer, (0, contents_composite_y))
|
||||||
|
contents_composite_y = contents_composite_y + instance_layer.height + gutter
|
||||||
|
|
||||||
|
texts_layer = generate_texts_layer(texts, content_width)
|
||||||
|
contents_layer.alpha_composite(texts_layer, (0, contents_composite_y))
|
||||||
|
contents_composite_y = contents_composite_y + texts_layer.height + gutter
|
||||||
|
|
||||||
|
if rating:
|
||||||
|
# Add some more margin
|
||||||
|
contents_composite_y = contents_composite_y + gutter
|
||||||
|
rating_layer = generate_rating_layer(rating, content_width)
|
||||||
|
|
||||||
|
if rating_layer:
|
||||||
|
contents_layer.alpha_composite(rating_layer, (0, contents_composite_y))
|
||||||
|
contents_composite_y = contents_composite_y + rating_layer.height + gutter
|
||||||
|
|
||||||
|
contents_layer_box = contents_layer.getbbox()
|
||||||
|
contents_layer_height = contents_layer_box[3] - contents_layer_box[1]
|
||||||
|
|
||||||
|
contents_y = math.floor((IMG_HEIGHT - contents_layer_height) / 2)
|
||||||
|
|
||||||
|
if show_instance_layer:
|
||||||
|
# Remove Instance Layer from centering calculations
|
||||||
|
contents_y = contents_y - math.floor((instance_layer.height + gutter) / 2)
|
||||||
|
|
||||||
|
if contents_y < margin:
|
||||||
|
contents_y = margin
|
||||||
|
|
||||||
|
# Composite layers
|
||||||
|
img.paste(
|
||||||
|
inner_img_layer, (inner_img_x, inner_img_y), inner_img_layer.convert("RGBA")
|
||||||
|
)
|
||||||
|
img.alpha_composite(contents_layer, (content_x, contents_y))
|
||||||
|
|
||||||
|
return img.convert("RGB")
|
||||||
|
|
||||||
|
|
||||||
|
def save_and_cleanup(image, instance=None):
|
||||||
|
if isinstance(instance, (models.Book, models.User, models.SiteSettings)):
|
||||||
|
file_name = "%s-%s.jpg" % (str(instance.id), str(uuid4()))
|
||||||
|
image_buffer = BytesIO()
|
||||||
|
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
old_path = instance.preview_image.path
|
||||||
|
except ValueError:
|
||||||
|
old_path = ""
|
||||||
|
|
||||||
|
# Save
|
||||||
|
image.save(image_buffer, format="jpeg", quality=75)
|
||||||
|
|
||||||
|
instance.preview_image = InMemoryUploadedFile(
|
||||||
|
ContentFile(image_buffer.getvalue()),
|
||||||
|
"preview_image",
|
||||||
|
file_name,
|
||||||
|
"image/jpg",
|
||||||
|
image_buffer.tell(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
|
save_without_broadcast = isinstance(instance, (models.Book, models.User))
|
||||||
|
if save_without_broadcast:
|
||||||
|
result = instance.save(broadcast=False)
|
||||||
|
else:
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
# Clean up old file after saving
|
||||||
|
if os.path.exists(old_path):
|
||||||
|
os.remove(old_path)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
image_buffer.close()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@app.task
|
||||||
|
def generate_site_preview_image_task():
|
||||||
|
"""generate preview_image for the website"""
|
||||||
|
if settings.ENABLE_PREVIEW_IMAGES == True:
|
||||||
|
site = models.SiteSettings.objects.get()
|
||||||
|
|
||||||
|
if site.logo:
|
||||||
|
logo = site.logo
|
||||||
|
else:
|
||||||
|
logo = os.path.join(settings.STATIC_ROOT, "images/logo.png")
|
||||||
|
|
||||||
|
texts = {
|
||||||
|
"text_zero": settings.DOMAIN,
|
||||||
|
"text_one": site.name,
|
||||||
|
"text_three": site.instance_tagline,
|
||||||
|
}
|
||||||
|
|
||||||
|
image = generate_preview_image(
|
||||||
|
texts=texts, picture=logo, show_instance_layer=False
|
||||||
|
)
|
||||||
|
|
||||||
|
save_and_cleanup(image, instance=site)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task
|
||||||
|
def generate_edition_preview_image_task(book_id):
|
||||||
|
"""generate preview_image for a book"""
|
||||||
|
if settings.ENABLE_PREVIEW_IMAGES == True:
|
||||||
|
book = models.Book.objects.select_subclasses().get(id=book_id)
|
||||||
|
|
||||||
|
rating = models.Review.objects.filter(
|
||||||
|
privacy="public",
|
||||||
|
deleted=False,
|
||||||
|
book__in=[book_id],
|
||||||
|
).aggregate(Avg("rating"))["rating__avg"]
|
||||||
|
|
||||||
|
texts = {
|
||||||
|
"text_one": book.title,
|
||||||
|
"text_two": book.subtitle,
|
||||||
|
"text_three": book.author_text,
|
||||||
|
}
|
||||||
|
|
||||||
|
image = generate_preview_image(texts=texts, picture=book.cover, rating=rating)
|
||||||
|
|
||||||
|
save_and_cleanup(image, instance=book)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task
|
||||||
|
def generate_user_preview_image_task(user_id):
|
||||||
|
"""generate preview_image for a book"""
|
||||||
|
if settings.ENABLE_PREVIEW_IMAGES == True:
|
||||||
|
user = models.User.objects.get(id=user_id)
|
||||||
|
|
||||||
|
texts = {
|
||||||
|
"text_one": user.display_name,
|
||||||
|
"text_three": "@{}@{}".format(user.localname, settings.DOMAIN),
|
||||||
|
}
|
||||||
|
|
||||||
|
if user.avatar:
|
||||||
|
avatar = user.avatar
|
||||||
|
else:
|
||||||
|
avatar = os.path.join(settings.STATIC_ROOT, "images/default_avi.jpg")
|
||||||
|
|
||||||
|
image = generate_preview_image(texts=texts, picture=avatar)
|
||||||
|
|
||||||
|
save_and_cleanup(image, instance=user)
|
|
@ -42,6 +42,14 @@ LOCALE_PATHS = [
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||||
|
|
||||||
|
# Preview image
|
||||||
|
ENABLE_PREVIEW_IMAGES = env.bool("ENABLE_PREVIEW_IMAGES", False)
|
||||||
|
PREVIEW_BG_COLOR = env.str("PREVIEW_BG_COLOR", "use_dominant_color_light")
|
||||||
|
PREVIEW_TEXT_COLOR = env.str("PREVIEW_TEXT_COLOR", "#363636")
|
||||||
|
PREVIEW_IMG_WIDTH = env.int("PREVIEW_IMG_WIDTH", 1200)
|
||||||
|
PREVIEW_IMG_HEIGHT = env.int("PREVIEW_IMG_HEIGHT", 630)
|
||||||
|
PREVIEW_DEFAULT_COVER_COLOR = env.str("PREVIEW_DEFAULT_COVER_COLOR", "#002549")
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||||
|
|
||||||
|
@ -175,8 +183,10 @@ USE_TZ = True
|
||||||
|
|
||||||
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
|
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/static/"
|
||||||
|
STATIC_PATH = "%s/%s" % (DOMAIN, env("STATIC_ROOT", "static"))
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static"))
|
STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static"))
|
||||||
MEDIA_URL = "/images/"
|
MEDIA_URL = "/images/"
|
||||||
|
MEDIA_PATH = "%s/%s" % (DOMAIN, env("MEDIA_ROOT", "images"))
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images"))
|
MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images"))
|
||||||
|
|
||||||
USER_AGENT = "%s (BookWyrm/%s; +https://%s/)" % (
|
USER_AGENT = "%s (BookWyrm/%s; +https://%s/)" % (
|
||||||
|
|
94
bookwyrm/static/fonts/public_sans/OFL.txt
Normal file
94
bookwyrm/static/fonts/public_sans/OFL.txt
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
Copyright (c) 2015, Pablo Impallari, Rodrigo Fuenzalida
|
||||||
|
(Modified by Dan O. Williams and USWDS) (https://github.com/uswds/public-sans)
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
BIN
bookwyrm/static/fonts/public_sans/PublicSans-Bold.ttf
Normal file
BIN
bookwyrm/static/fonts/public_sans/PublicSans-Bold.ttf
Normal file
Binary file not shown.
BIN
bookwyrm/static/fonts/public_sans/PublicSans-Light.ttf
Normal file
BIN
bookwyrm/static/fonts/public_sans/PublicSans-Light.ttf
Normal file
Binary file not shown.
BIN
bookwyrm/static/fonts/public_sans/PublicSans-Regular.ttf
Normal file
BIN
bookwyrm/static/fonts/public_sans/PublicSans-Regular.ttf
Normal file
Binary file not shown.
BIN
bookwyrm/static/images/icons/star-empty.png
Executable file
BIN
bookwyrm/static/images/icons/star-empty.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
bookwyrm/static/images/icons/star-full.png
Executable file
BIN
bookwyrm/static/images/icons/star-full.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 923 B |
BIN
bookwyrm/static/images/icons/star-half.png
Executable file
BIN
bookwyrm/static/images/icons/star-half.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -1,8 +1,12 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% load i18n %}{% load bookwyrm_tags %}{% load humanize %}{% load utilities %}
|
{% load i18n %}{% load bookwyrm_tags %}{% load humanize %}{% load utilities %}{% load layout %}
|
||||||
|
|
||||||
{% block title %}{{ book|book_title }}{% endblock %}
|
{% block title %}{{ book|book_title }}{% endblock %}
|
||||||
|
|
||||||
|
{% block opengraph_images %}
|
||||||
|
{% include 'snippets/opengraph_images.html' with image=book.preview_image %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% with user_authenticated=request.user.is_authenticated can_edit_book=perms.bookwyrm.edit_book %}
|
{% with user_authenticated=request.user.is_authenticated can_edit_book=perms.bookwyrm.edit_book %}
|
||||||
<div class="block" itemscope itemtype="https://schema.org/Book">
|
<div class="block" itemscope itemtype="https://schema.org/Book">
|
||||||
|
|
|
@ -8,16 +8,21 @@
|
||||||
<link rel="stylesheet" href="/static/css/vendor/icons.css">
|
<link rel="stylesheet" href="/static/css/vendor/icons.css">
|
||||||
<link rel="stylesheet" href="/static/css/bookwyrm.css">
|
<link rel="stylesheet" href="/static/css/bookwyrm.css">
|
||||||
|
|
||||||
<link rel="shortcut icon" type="image/x-icon" href="{% if site.favicon %}/images/{{ site.favicon }}{% else %}/static/images/favicon.ico{% endif %}">
|
<link rel="shortcut icon" type="image/x-icon" href="{% if site.favicon %}{{ media_url }}{{ site.favicon }}{% else %}/static/images/favicon.ico{% endif %}">
|
||||||
|
|
||||||
|
{% if preview_images_enabled is True %}
|
||||||
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
|
{% else %}
|
||||||
<meta name="twitter:card" content="summary">
|
<meta name="twitter:card" content="summary">
|
||||||
|
{% endif %}
|
||||||
<meta name="twitter:title" content="{% if title %}{{ title }} | {% endif %}{{ site.name }}">
|
<meta name="twitter:title" content="{% if title %}{{ title }} | {% endif %}{{ site.name }}">
|
||||||
<meta name="og:title" content="{% if title %}{{ title }} | {% endif %}{{ site.name }}">
|
<meta name="og:title" content="{% if title %}{{ title }} | {% endif %}{{ site.name }}">
|
||||||
<meta name="twitter:description" content="{{ site.instance_tagline }}">
|
<meta name="twitter:description" content="{{ site.instance_tagline }}">
|
||||||
<meta name="og:description" content="{{ site.instance_tagline }}">
|
<meta name="og:description" content="{{ site.instance_tagline }}">
|
||||||
|
|
||||||
<meta name="twitter:image" content="{% if site.logo %}/images/{{ site.logo }}{% else %}/static/images/logo.png{% endif %}">
|
{% block opengraph_images %}
|
||||||
<meta name="og:image" content="{% if site.logo %}/images/{{ site.logo }}{% else %}/static/images/logo.png{% endif %}">
|
{% include 'snippets/opengraph_images.html' %}
|
||||||
|
{% endblock %}
|
||||||
<meta name="twitter:image:alt" content="BookWyrm Logo">
|
<meta name="twitter:image:alt" content="BookWyrm Logo">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -25,7 +30,7 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="navbar-brand">
|
<div class="navbar-brand">
|
||||||
<a class="navbar-item" href="/">
|
<a class="navbar-item" href="/">
|
||||||
<img class="image logo" src="{% if site.logo_small %}/images/{{ site.logo_small }}{% else %}/static/images/logo-small.png{% endif %}" alt="Home page">
|
<img class="image logo" src="{% if site.logo_small %}{{ media_url }}{{ site.logo_small }}{% else %}/static/images/logo-small.png{% endif %}" alt="Home page">
|
||||||
</a>
|
</a>
|
||||||
<form class="navbar-item column" action="/search/">
|
<form class="navbar-item column" action="/search/">
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
|
|
12
bookwyrm/templates/snippets/opengraph_images.html
Normal file
12
bookwyrm/templates/snippets/opengraph_images.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{% if preview_images_enabled is True %}
|
||||||
|
{% if image %}
|
||||||
|
<meta name="twitter:image" content="{{ request.scheme }}://{{ media_path }}{{ image }}">
|
||||||
|
<meta name="og:image" content="{{ request.scheme }}://{{ media_path }}{{ image }}">
|
||||||
|
{% else %}
|
||||||
|
<meta name="twitter:image" content="{{ request.scheme }}://{{ media_path }}{{ site.preview_image }}">
|
||||||
|
<meta name="og:image" content="{{ request.scheme }}://{{ media_path }}{{ site.preview_image }}">
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<meta name="twitter:image" content="{{ request.scheme }}://{% if site.logo %}{{ media_path }}{{ site.logo }}{% else %}{{ static_path }}/images/logo.png{% endif %}">
|
||||||
|
<meta name="og:image" content="{{ request.scheme }}://{% if site.logo %}{{ media_path }}{{ site.logo }}{% else %}{{ static_path }}/images/logo.png{% endif %}">
|
||||||
|
{% endif %}
|
|
@ -3,9 +3,14 @@
|
||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
{% load utilities %}
|
{% load utilities %}
|
||||||
{% load markdown %}
|
{% load markdown %}
|
||||||
|
{% load layout %}
|
||||||
|
|
||||||
{% block title %}{{ user.display_name }}{% endblock %}
|
{% block title %}{{ user.display_name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block opengraph_images %}
|
||||||
|
{% include 'snippets/opengraph_images.html' with image=user.preview_image %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<header class="block">
|
<header class="block">
|
||||||
{% block header %}
|
{% block header %}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
""" template filters used for creating the layout"""
|
""" template filters used for creating the layout"""
|
||||||
from django import template, utils
|
from django import template, utils
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
|
||||||
|
|
||||||
class Author(TestCase):
|
class Author(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
)
|
remote_id="https://example.com/book/1",
|
||||||
|
)
|
||||||
self.author = models.Author.objects.create(
|
self.author = models.Author.objects.create(
|
||||||
name="Author fullname",
|
name="Author fullname",
|
||||||
aliases=["One", "Two"],
|
aliases=["One", "Two"],
|
||||||
|
|
|
@ -25,24 +25,25 @@ class BaseActivity(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we're probably going to re-use this so why copy/paste"""
|
"""we're probably going to re-use this so why copy/paste"""
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
self.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)
|
self.user.remote_id = "http://example.com/a/b"
|
||||||
|
self.user.save(broadcast=False)
|
||||||
|
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||||
self.userdata = json.loads(datafile.read_bytes())
|
self.userdata = json.loads(datafile.read_bytes())
|
||||||
# don't try to load the user icon
|
# don't try to load the user icon
|
||||||
del self.userdata["icon"]
|
del self.userdata["icon"]
|
||||||
|
|
||||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||||
"../../static/images/default_avi.jpg"
|
"../../static/images/default_avi.jpg"
|
||||||
)
|
)
|
||||||
image = Image.open(image_file)
|
image = Image.open(image_file)
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
image.save(output, format=image.format)
|
image.save(output, format=image.format)
|
||||||
self.image_data = output.getvalue()
|
self.image_data = output.getvalue()
|
||||||
|
|
||||||
def test_init(self, _):
|
def test_init(self, _):
|
||||||
"""simple successfuly init"""
|
"""simple successfuly init"""
|
||||||
|
@ -97,10 +98,11 @@ class BaseActivity(TestCase):
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
result = resolve_remote_id(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"https://example.com/user/mouse", model=models.User
|
result = resolve_remote_id(
|
||||||
)
|
"https://example.com/user/mouse", model=models.User
|
||||||
|
)
|
||||||
self.assertIsInstance(result, models.User)
|
self.assertIsInstance(result, models.User)
|
||||||
self.assertEqual(result.remote_id, "https://example.com/user/mouse")
|
self.assertEqual(result.remote_id, "https://example.com/user/mouse")
|
||||||
self.assertEqual(result.name, "MOUSE?? MOUSE!!")
|
self.assertEqual(result.name, "MOUSE?? MOUSE!!")
|
||||||
|
@ -139,8 +141,9 @@ class BaseActivity(TestCase):
|
||||||
self.user.avatar.file # pylint: disable=pointless-statement
|
self.user.avatar.file # pylint: disable=pointless-statement
|
||||||
|
|
||||||
# this would trigger a broadcast because it's a local user
|
# this would trigger a broadcast because it's a local user
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
activity.to_model(model=models.User, instance=self.user)
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
activity.to_model(model=models.User, instance=self.user)
|
||||||
self.assertIsNotNone(self.user.avatar.file)
|
self.assertIsNotNone(self.user.avatar.file)
|
||||||
self.assertEqual(self.user.name, "New Name")
|
self.assertEqual(self.user.name, "New Name")
|
||||||
self.assertEqual(self.user.key_pair.public_key, "hi")
|
self.assertEqual(self.user.key_pair.public_key, "hi")
|
||||||
|
@ -152,9 +155,10 @@ class BaseActivity(TestCase):
|
||||||
content="test status",
|
content="test status",
|
||||||
user=self.user,
|
user=self.user,
|
||||||
)
|
)
|
||||||
book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Edition", remote_id="http://book.com/book"
|
book = models.Edition.objects.create(
|
||||||
)
|
title="Test Edition", remote_id="http://book.com/book"
|
||||||
|
)
|
||||||
update_data = activitypub.Note(
|
update_data = activitypub.Note(
|
||||||
id=status.remote_id,
|
id=status.remote_id,
|
||||||
content=status.content,
|
content=status.content,
|
||||||
|
|
|
@ -20,8 +20,9 @@ class Person(TestCase):
|
||||||
|
|
||||||
def test_user_to_model(self):
|
def test_user_to_model(self):
|
||||||
activity = activitypub.Person(**self.user_data)
|
activity = activitypub.Person(**self.user_data)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
user = activity.to_model(model=models.User)
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
user = activity.to_model(model=models.User)
|
||||||
self.assertEqual(user.username, "mouse@example.com")
|
self.assertEqual(user.username, "mouse@example.com")
|
||||||
self.assertEqual(user.remote_id, "https://example.com/user/mouse")
|
self.assertEqual(user.remote_id, "https://example.com/user/mouse")
|
||||||
self.assertFalse(user.local)
|
self.assertFalse(user.local)
|
||||||
|
|
|
@ -12,20 +12,22 @@ class Quotation(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""model objects we'll need"""
|
"""model objects we'll need"""
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"mouse",
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse",
|
||||||
"mouseword",
|
"mouse@mouse.mouse",
|
||||||
local=False,
|
"mouseword",
|
||||||
inbox="https://example.com/user/mouse/inbox",
|
local=False,
|
||||||
outbox="https://example.com/user/mouse/outbox",
|
inbox="https://example.com/user/mouse/inbox",
|
||||||
remote_id="https://example.com/user/mouse",
|
outbox="https://example.com/user/mouse/outbox",
|
||||||
|
remote_id="https://example.com/user/mouse",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(
|
||||||
|
title="Example Edition",
|
||||||
|
remote_id="https://example.com/book/1",
|
||||||
)
|
)
|
||||||
self.book = models.Edition.objects.create(
|
|
||||||
title="Example Edition",
|
|
||||||
remote_id="https://example.com/book/1",
|
|
||||||
)
|
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_quotation.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_quotation.json")
|
||||||
self.status_data = json.loads(datafile.read_bytes())
|
self.status_data = json.loads(datafile.read_bytes())
|
||||||
|
|
||||||
|
|
|
@ -74,11 +74,12 @@ class AbstractConnector(TestCase):
|
||||||
Mapping("openlibraryKey"),
|
Mapping("openlibraryKey"),
|
||||||
]
|
]
|
||||||
|
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Book",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1234",
|
title="Test Book",
|
||||||
openlibrary_key="OL1234M",
|
remote_id="https://example.com/book/1234",
|
||||||
)
|
openlibrary_key="OL1234M",
|
||||||
|
)
|
||||||
|
|
||||||
def test_abstract_connector_init(self):
|
def test_abstract_connector_init(self):
|
||||||
"""barebones connector for search with defaults"""
|
"""barebones connector for search with defaults"""
|
||||||
|
@ -110,8 +111,11 @@ class AbstractConnector(TestCase):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET, "https://example.com/book/abcd", json=self.edition_data
|
responses.GET, "https://example.com/book/abcd", json=self.edition_data
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
result = self.connector.get_or_create_book("https://example.com/book/abcd")
|
with patch("bookwyrm.connectors.abstract_connector.load_more_data.delay"):
|
||||||
|
result = self.connector.get_or_create_book(
|
||||||
|
"https://example.com/book/abcd"
|
||||||
|
)
|
||||||
self.assertEqual(result, self.book)
|
self.assertEqual(result, self.book)
|
||||||
self.assertEqual(models.Edition.objects.count(), 1)
|
self.assertEqual(models.Edition.objects.count(), 1)
|
||||||
self.assertEqual(models.Edition.objects.count(), 1)
|
self.assertEqual(models.Edition.objects.count(), 1)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" testing book data connectors """
|
""" testing book data connectors """
|
||||||
|
from unittest.mock import patch
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -25,8 +26,9 @@ class BookWyrmConnector(TestCase):
|
||||||
|
|
||||||
def test_get_or_create_book_existing(self):
|
def test_get_or_create_book_existing(self):
|
||||||
"""load book activity"""
|
"""load book activity"""
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
book = models.Edition.objects.create(title="Test Edition", parent_work=work)
|
work = models.Work.objects.create(title="Test Work")
|
||||||
|
book = models.Edition.objects.create(title="Test Edition", parent_work=work)
|
||||||
result = self.connector.get_or_create_book(book.remote_id)
|
result = self.connector.get_or_create_book(book.remote_id)
|
||||||
self.assertEqual(book, result)
|
self.assertEqual(book, result)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" interface between the app and various connectors """
|
""" interface between the app and various connectors """
|
||||||
|
from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
import responses
|
import responses
|
||||||
|
|
||||||
|
@ -13,14 +14,15 @@ class ConnectorManager(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we'll need some books and a connector info entry"""
|
"""we'll need some books and a connector info entry"""
|
||||||
self.work = models.Work.objects.create(title="Example Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.work = models.Work.objects.create(title="Example Work")
|
||||||
|
|
||||||
self.edition = models.Edition.objects.create(
|
self.edition = models.Edition.objects.create(
|
||||||
title="Example Edition", parent_work=self.work, isbn_10="0000000000"
|
title="Example Edition", parent_work=self.work, isbn_10="0000000000"
|
||||||
)
|
)
|
||||||
self.edition = models.Edition.objects.create(
|
self.edition = models.Edition.objects.create(
|
||||||
title="Another Edition", parent_work=self.work, isbn_10="1111111111"
|
title="Another Edition", parent_work=self.work, isbn_10="1111111111"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.connector = models.Connector.objects.create(
|
self.connector = models.Connector.objects.create(
|
||||||
identifier="test_connector",
|
identifier="test_connector",
|
||||||
|
|
|
@ -178,20 +178,26 @@ class Openlibrary(TestCase):
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_expand_book_data(self):
|
def test_expand_book_data(self):
|
||||||
"""given a book, get more editions"""
|
"""given a book, get more editions"""
|
||||||
work = models.Work.objects.create(title="Test Work", openlibrary_key="OL1234W")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
edition = models.Edition.objects.create(title="Test Edition", parent_work=work)
|
work = models.Work.objects.create(
|
||||||
|
title="Test Work", openlibrary_key="OL1234W"
|
||||||
|
)
|
||||||
|
edition = models.Edition.objects.create(
|
||||||
|
title="Test Edition", parent_work=work
|
||||||
|
)
|
||||||
|
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET,
|
responses.GET,
|
||||||
"https://openlibrary.org/works/OL1234W/editions",
|
"https://openlibrary.org/works/OL1234W/editions",
|
||||||
json={"entries": []},
|
json={"entries": []},
|
||||||
)
|
)
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"bookwyrm.connectors.abstract_connector.AbstractConnector."
|
with patch(
|
||||||
"create_edition_from_data"
|
"bookwyrm.connectors.abstract_connector.AbstractConnector."
|
||||||
):
|
"create_edition_from_data"
|
||||||
self.connector.expand_book_data(edition)
|
):
|
||||||
self.connector.expand_book_data(work)
|
self.connector.expand_book_data(edition)
|
||||||
|
self.connector.expand_book_data(work)
|
||||||
|
|
||||||
def test_get_description(self):
|
def test_get_description(self):
|
||||||
"""should do some cleanup on the description data"""
|
"""should do some cleanup on the description data"""
|
||||||
|
@ -224,11 +230,14 @@ class Openlibrary(TestCase):
|
||||||
json={"hi": "there"},
|
json={"hi": "there"},
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
with patch(
|
||||||
) as mock:
|
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
||||||
mock.return_value = []
|
) as mock:
|
||||||
result = self.connector.create_edition_from_data(work, self.edition_data)
|
mock.return_value = []
|
||||||
|
result = self.connector.create_edition_from_data(
|
||||||
|
work, self.edition_data
|
||||||
|
)
|
||||||
self.assertEqual(result.parent_work, work)
|
self.assertEqual(result.parent_work, work)
|
||||||
self.assertEqual(result.title, "Sabriel")
|
self.assertEqual(result.title, "Sabriel")
|
||||||
self.assertEqual(result.isbn_10, "0060273224")
|
self.assertEqual(result.isbn_10, "0060273224")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" testing book data connectors """
|
""" testing book data connectors """
|
||||||
|
from unittest.mock import patch
|
||||||
import datetime
|
import datetime
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -29,12 +30,13 @@ class SelfConnector(TestCase):
|
||||||
def test_format_search_result(self):
|
def test_format_search_result(self):
|
||||||
"""create a SearchResult"""
|
"""create a SearchResult"""
|
||||||
author = models.Author.objects.create(name="Anonymous")
|
author = models.Author.objects.create(name="Anonymous")
|
||||||
edition = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Edition of Example Work",
|
edition = models.Edition.objects.create(
|
||||||
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
title="Edition of Example Work",
|
||||||
)
|
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
||||||
edition.authors.add(author)
|
)
|
||||||
result = self.connector.search("Edition of Example")[0]
|
edition.authors.add(author)
|
||||||
|
result = self.connector.search("Edition of Example")[0]
|
||||||
self.assertEqual(result.title, "Edition of Example Work")
|
self.assertEqual(result.title, "Edition of Example Work")
|
||||||
self.assertEqual(result.key, edition.remote_id)
|
self.assertEqual(result.key, edition.remote_id)
|
||||||
self.assertEqual(result.author, "Anonymous")
|
self.assertEqual(result.author, "Anonymous")
|
||||||
|
@ -44,34 +46,35 @@ class SelfConnector(TestCase):
|
||||||
def test_search_rank(self):
|
def test_search_rank(self):
|
||||||
"""prioritize certain results"""
|
"""prioritize certain results"""
|
||||||
author = models.Author.objects.create(name="Anonymous")
|
author = models.Author.objects.create(name="Anonymous")
|
||||||
edition = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Edition of Example Work",
|
edition = models.Edition.objects.create(
|
||||||
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
title="Edition of Example Work",
|
||||||
parent_work=models.Work.objects.create(title=""),
|
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
||||||
)
|
parent_work=models.Work.objects.create(title=""),
|
||||||
# author text is rank C
|
)
|
||||||
edition.authors.add(author)
|
# author text is rank C
|
||||||
|
edition.authors.add(author)
|
||||||
|
|
||||||
# series is rank D
|
# series is rank D
|
||||||
models.Edition.objects.create(
|
models.Edition.objects.create(
|
||||||
title="Another Edition",
|
title="Another Edition",
|
||||||
series="Anonymous",
|
series="Anonymous",
|
||||||
parent_work=models.Work.objects.create(title=""),
|
parent_work=models.Work.objects.create(title=""),
|
||||||
)
|
)
|
||||||
# subtitle is rank B
|
# subtitle is rank B
|
||||||
models.Edition.objects.create(
|
models.Edition.objects.create(
|
||||||
title="More Editions",
|
title="More Editions",
|
||||||
subtitle="The Anonymous Edition",
|
subtitle="The Anonymous Edition",
|
||||||
parent_work=models.Work.objects.create(title=""),
|
parent_work=models.Work.objects.create(title=""),
|
||||||
)
|
)
|
||||||
# title is rank A
|
# title is rank A
|
||||||
models.Edition.objects.create(title="Anonymous")
|
models.Edition.objects.create(title="Anonymous")
|
||||||
# doesn't rank in this search
|
# doesn't rank in this search
|
||||||
edition = models.Edition.objects.create(
|
edition = models.Edition.objects.create(
|
||||||
title="An Edition", parent_work=models.Work.objects.create(title="")
|
title="An Edition", parent_work=models.Work.objects.create(title="")
|
||||||
)
|
)
|
||||||
|
|
||||||
results = self.connector.search("Anonymous")
|
results = self.connector.search("Anonymous")
|
||||||
self.assertEqual(len(results), 3)
|
self.assertEqual(len(results), 3)
|
||||||
self.assertEqual(results[0].title, "Anonymous")
|
self.assertEqual(results[0].title, "Anonymous")
|
||||||
self.assertEqual(results[1].title, "More Editions")
|
self.assertEqual(results[1].title, "More Editions")
|
||||||
|
@ -79,28 +82,29 @@ class SelfConnector(TestCase):
|
||||||
|
|
||||||
def test_search_multiple_editions(self):
|
def test_search_multiple_editions(self):
|
||||||
"""it should get rid of duplicate editions for the same work"""
|
"""it should get rid of duplicate editions for the same work"""
|
||||||
work = models.Work.objects.create(title="Work Title")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
edition_1 = models.Edition.objects.create(
|
work = models.Work.objects.create(title="Work Title")
|
||||||
title="Edition 1 Title", parent_work=work
|
edition_1 = models.Edition.objects.create(
|
||||||
)
|
title="Edition 1 Title", parent_work=work
|
||||||
edition_2 = models.Edition.objects.create(
|
)
|
||||||
title="Edition 2 Title",
|
edition_2 = models.Edition.objects.create(
|
||||||
parent_work=work,
|
title="Edition 2 Title",
|
||||||
edition_rank=20, # that's default babey
|
parent_work=work,
|
||||||
)
|
edition_rank=20, # that's default babey
|
||||||
edition_3 = models.Edition.objects.create(title="Fish", parent_work=work)
|
)
|
||||||
|
edition_3 = models.Edition.objects.create(title="Fish", parent_work=work)
|
||||||
|
|
||||||
# pick the best edition
|
# pick the best edition
|
||||||
results = self.connector.search("Edition 1 Title")
|
results = self.connector.search("Edition 1 Title")
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0].key, edition_1.remote_id)
|
self.assertEqual(results[0].key, edition_1.remote_id)
|
||||||
|
|
||||||
# pick the default edition when no match is best
|
# pick the default edition when no match is best
|
||||||
results = self.connector.search("Edition Title")
|
results = self.connector.search("Edition Title")
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0].key, edition_2.remote_id)
|
self.assertEqual(results[0].key, edition_2.remote_id)
|
||||||
|
|
||||||
# only matches one edition, so no deduplication takes place
|
# only matches one edition, so no deduplication takes place
|
||||||
results = self.connector.search("Fish")
|
results = self.connector.search("Fish")
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
self.assertEqual(results[0].key, edition_3.remote_id)
|
self.assertEqual(results[0].key, edition_3.remote_id)
|
||||||
|
|
|
@ -21,9 +21,10 @@ class GoodreadsImport(TestCase):
|
||||||
self.importer = GoodreadsImporter()
|
self.importer = GoodreadsImporter()
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
datafile = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv")
|
||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
self.user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||||
|
)
|
||||||
|
|
||||||
models.Connector.objects.create(
|
models.Connector.objects.create(
|
||||||
identifier=DOMAIN,
|
identifier=DOMAIN,
|
||||||
|
@ -36,12 +37,13 @@ class GoodreadsImport(TestCase):
|
||||||
search_url="https://%s/search?q=" % DOMAIN,
|
search_url="https://%s/search?q=" % DOMAIN,
|
||||||
priority=1,
|
priority=1,
|
||||||
)
|
)
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=work,
|
||||||
|
)
|
||||||
|
|
||||||
def test_create_job(self):
|
def test_create_job(self):
|
||||||
"""creates the import job entry and checks csv"""
|
"""creates the import job entry and checks csv"""
|
||||||
|
@ -92,7 +94,8 @@ class GoodreadsImport(TestCase):
|
||||||
def test_import_data(self):
|
def test_import_data(self):
|
||||||
"""resolve entry"""
|
"""resolve entry"""
|
||||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||||
book = models.Edition.objects.create(title="Test Book")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
book = models.Edition.objects.create(title="Test Book")
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
||||||
|
@ -119,10 +122,11 @@ class GoodreadsImport(TestCase):
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
|
)
|
||||||
|
|
||||||
shelf.refresh_from_db()
|
shelf.refresh_from_db()
|
||||||
self.assertEqual(shelf.books.first(), self.book)
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
@ -183,13 +187,14 @@ class GoodreadsImport(TestCase):
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
handle_imported_book(
|
)
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
|
)
|
||||||
|
|
||||||
shelf.refresh_from_db()
|
shelf.refresh_from_db()
|
||||||
self.assertEqual(shelf.books.first(), self.book)
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
@ -216,10 +221,11 @@ class GoodreadsImport(TestCase):
|
||||||
job_id=import_job.id, index=0, data=entry, book=self.book
|
job_id=import_job.id, index=0, data=entry, book=self.book
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, True, "unlisted"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, True, "unlisted"
|
||||||
|
)
|
||||||
review = models.Review.objects.get(book=self.book, user=self.user)
|
review = models.Review.objects.get(book=self.book, user=self.user)
|
||||||
self.assertEqual(review.content, "mixed feelings")
|
self.assertEqual(review.content, "mixed feelings")
|
||||||
self.assertEqual(review.rating, 2)
|
self.assertEqual(review.rating, 2)
|
||||||
|
@ -242,10 +248,11 @@ class GoodreadsImport(TestCase):
|
||||||
job_id=import_job.id, index=0, data=entry, book=self.book
|
job_id=import_job.id, index=0, data=entry, book=self.book
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, True, "unlisted"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, True, "unlisted"
|
||||||
|
)
|
||||||
review = models.ReviewRating.objects.get(book=self.book, user=self.user)
|
review = models.ReviewRating.objects.get(book=self.book, user=self.user)
|
||||||
self.assertIsInstance(review, models.ReviewRating)
|
self.assertIsInstance(review, models.ReviewRating)
|
||||||
self.assertEqual(review.rating, 2)
|
self.assertEqual(review.rating, 2)
|
||||||
|
@ -265,10 +272,11 @@ class GoodreadsImport(TestCase):
|
||||||
job_id=import_job.id, index=0, data=entry, book=self.book
|
job_id=import_job.id, index=0, data=entry, book=self.book
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "unlisted"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "unlisted"
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
models.Review.objects.filter(book=self.book, user=self.user).exists()
|
models.Review.objects.filter(book=self.book, user=self.user).exists()
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,9 +22,10 @@ class LibrarythingImport(TestCase):
|
||||||
|
|
||||||
# Librarything generates latin encoded exports...
|
# Librarything generates latin encoded exports...
|
||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mmai", "mmai@mmai.mmai", "password", local=True
|
self.user = models.User.objects.create_user(
|
||||||
)
|
"mmai", "mmai@mmai.mmai", "password", local=True
|
||||||
|
)
|
||||||
|
|
||||||
models.Connector.objects.create(
|
models.Connector.objects.create(
|
||||||
identifier=DOMAIN,
|
identifier=DOMAIN,
|
||||||
|
@ -37,12 +38,13 @@ class LibrarythingImport(TestCase):
|
||||||
search_url="https://%s/search?q=" % DOMAIN,
|
search_url="https://%s/search?q=" % DOMAIN,
|
||||||
priority=1,
|
priority=1,
|
||||||
)
|
)
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=work,
|
||||||
|
)
|
||||||
|
|
||||||
def test_create_job(self):
|
def test_create_job(self):
|
||||||
"""creates the import job entry and checks csv"""
|
"""creates the import job entry and checks csv"""
|
||||||
|
@ -82,7 +84,8 @@ class LibrarythingImport(TestCase):
|
||||||
def test_import_data(self):
|
def test_import_data(self):
|
||||||
"""resolve entry"""
|
"""resolve entry"""
|
||||||
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
import_job = self.importer.create_job(self.user, self.csv, False, "unlisted")
|
||||||
book = models.Edition.objects.create(title="Test Book")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
book = models.Edition.objects.create(title="Test Book")
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
"bookwyrm.models.import_job.ImportItem.get_book_from_isbn"
|
||||||
|
@ -111,10 +114,11 @@ class LibrarythingImport(TestCase):
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
|
)
|
||||||
|
|
||||||
shelf.refresh_from_db()
|
shelf.refresh_from_db()
|
||||||
self.assertEqual(shelf.books.first(), self.book)
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
@ -147,10 +151,11 @@ class LibrarythingImport(TestCase):
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
|
)
|
||||||
|
|
||||||
shelf.refresh_from_db()
|
shelf.refresh_from_db()
|
||||||
self.assertEqual(shelf.books.first(), self.book)
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
@ -179,13 +184,14 @@ class LibrarythingImport(TestCase):
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
handle_imported_book(
|
)
|
||||||
self.importer.service, self.user, import_item, False, "public"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "public"
|
||||||
|
)
|
||||||
|
|
||||||
shelf.refresh_from_db()
|
shelf.refresh_from_db()
|
||||||
self.assertEqual(shelf.books.first(), self.book)
|
self.assertEqual(shelf.books.first(), self.book)
|
||||||
|
@ -212,10 +218,11 @@ class LibrarythingImport(TestCase):
|
||||||
job_id=import_job.id, index=0, data=entry, book=self.book
|
job_id=import_job.id, index=0, data=entry, book=self.book
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, True, "unlisted"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, True, "unlisted"
|
||||||
|
)
|
||||||
review = models.Review.objects.get(book=self.book, user=self.user)
|
review = models.Review.objects.get(book=self.book, user=self.user)
|
||||||
self.assertEqual(review.content, "chef d'oeuvre")
|
self.assertEqual(review.content, "chef d'oeuvre")
|
||||||
self.assertEqual(review.rating, 5)
|
self.assertEqual(review.rating, 5)
|
||||||
|
@ -235,10 +242,11 @@ class LibrarythingImport(TestCase):
|
||||||
job_id=import_job.id, index=0, data=entry, book=self.book
|
job_id=import_job.id, index=0, data=entry, book=self.book
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
handle_imported_book(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.importer.service, self.user, import_item, False, "unlisted"
|
handle_imported_book(
|
||||||
)
|
self.importer.service, self.user, import_item, False, "unlisted"
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
models.Review.objects.filter(book=self.book, user=self.user).exists()
|
models.Review.objects.filter(book=self.book, user=self.user).exists()
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,23 +12,29 @@ class Activitystreams(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need some stuff"""
|
"""we need some stuff"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
self.another_user = models.User.objects.create_user(
|
|
||||||
"nutria", "nutria@nutria.nutria", "password", local=True, localname="nutria"
|
|
||||||
)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
self.book = models.Edition.objects.create(title="test book")
|
self.another_user = models.User.objects.create_user(
|
||||||
|
"nutria",
|
||||||
|
"nutria@nutria.nutria",
|
||||||
|
"password",
|
||||||
|
local=True,
|
||||||
|
localname="nutria",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="test book")
|
||||||
|
|
||||||
def test_populate_streams(self, _):
|
def test_populate_streams(self, _):
|
||||||
"""make sure the function on the redis manager gets called"""
|
"""make sure the function on the redis manager gets called"""
|
||||||
|
|
|
@ -19,21 +19,22 @@ class ActivitypubMixins(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""shared data"""
|
"""shared data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||||
self.local_user.remote_id = "http://example.com/a/b"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
self.local_user.remote_id = "http://example.com/a/b"
|
||||||
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
self.object_mock = {
|
self.object_mock = {
|
||||||
"to": "to field",
|
"to": "to field",
|
||||||
|
@ -70,9 +71,10 @@ class ActivitypubMixins(TestCase):
|
||||||
"""attempt to match a remote id to an object in the db"""
|
"""attempt to match a remote id to an object in the db"""
|
||||||
# uses a different remote id scheme
|
# uses a different remote id scheme
|
||||||
# this isn't really part of this test directly but it's helpful to state
|
# this isn't really part of this test directly but it's helpful to state
|
||||||
book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Edition", remote_id="http://book.com/book"
|
book = models.Edition.objects.create(
|
||||||
)
|
title="Test Edition", remote_id="http://book.com/book"
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(book.origin_id, "http://book.com/book")
|
self.assertEqual(book.origin_id, "http://book.com/book")
|
||||||
self.assertNotEqual(book.remote_id, "http://book.com/book")
|
self.assertNotEqual(book.remote_id, "http://book.com/book")
|
||||||
|
@ -101,10 +103,11 @@ class ActivitypubMixins(TestCase):
|
||||||
|
|
||||||
def test_find_existing(self, _):
|
def test_find_existing(self, _):
|
||||||
"""match a blob of data to a model"""
|
"""match a blob of data to a model"""
|
||||||
book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test edition",
|
book = models.Edition.objects.create(
|
||||||
openlibrary_key="OL1234",
|
title="Test edition",
|
||||||
)
|
openlibrary_key="OL1234",
|
||||||
|
)
|
||||||
|
|
||||||
result = models.Edition.find_existing({"openlibraryKey": "OL1234"})
|
result = models.Edition.find_existing({"openlibraryKey": "OL1234"})
|
||||||
self.assertEqual(result, book)
|
self.assertEqual(result, book)
|
||||||
|
@ -140,16 +143,17 @@ class ActivitypubMixins(TestCase):
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||||
mock_self = MockSelf("public", self.local_user)
|
mock_self = MockSelf("public", self.local_user)
|
||||||
self.local_user.followers.add(self.remote_user)
|
self.local_user.followers.add(self.remote_user)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
another_remote_user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"nutria",
|
another_remote_user = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
local=False,
|
"nutriaword",
|
||||||
remote_id="https://example.com/users/nutria",
|
local=False,
|
||||||
inbox="https://example.com/users/nutria/inbox",
|
remote_id="https://example.com/users/nutria",
|
||||||
outbox="https://example.com/users/nutria/outbox",
|
inbox="https://example.com/users/nutria/inbox",
|
||||||
)
|
outbox="https://example.com/users/nutria/outbox",
|
||||||
|
)
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user", "recipients"))
|
MockSelf = namedtuple("Self", ("privacy", "user", "recipients"))
|
||||||
mock_self = MockSelf("public", self.local_user, [another_remote_user])
|
mock_self = MockSelf("public", self.local_user, [another_remote_user])
|
||||||
|
|
||||||
|
@ -163,16 +167,17 @@ class ActivitypubMixins(TestCase):
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||||
mock_self = MockSelf("public", self.local_user)
|
mock_self = MockSelf("public", self.local_user)
|
||||||
self.local_user.followers.add(self.remote_user)
|
self.local_user.followers.add(self.remote_user)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
another_remote_user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"nutria",
|
another_remote_user = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
local=False,
|
"nutriaword",
|
||||||
remote_id="https://example.com/users/nutria",
|
local=False,
|
||||||
inbox="https://example.com/users/nutria/inbox",
|
remote_id="https://example.com/users/nutria",
|
||||||
outbox="https://example.com/users/nutria/outbox",
|
inbox="https://example.com/users/nutria/inbox",
|
||||||
)
|
outbox="https://example.com/users/nutria/outbox",
|
||||||
|
)
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user", "recipients"))
|
MockSelf = namedtuple("Self", ("privacy", "user", "recipients"))
|
||||||
mock_self = MockSelf("direct", self.local_user, [another_remote_user])
|
mock_self = MockSelf("direct", self.local_user, [another_remote_user])
|
||||||
|
|
||||||
|
@ -184,17 +189,18 @@ class ActivitypubMixins(TestCase):
|
||||||
"""should combine users with the same shared_inbox"""
|
"""should combine users with the same shared_inbox"""
|
||||||
self.remote_user.shared_inbox = "http://example.com/inbox"
|
self.remote_user.shared_inbox = "http://example.com/inbox"
|
||||||
self.remote_user.save(broadcast=False)
|
self.remote_user.save(broadcast=False)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
another_remote_user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"nutria",
|
another_remote_user = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
local=False,
|
"nutriaword",
|
||||||
remote_id="https://example.com/users/nutria",
|
local=False,
|
||||||
inbox="https://example.com/users/nutria/inbox",
|
remote_id="https://example.com/users/nutria",
|
||||||
shared_inbox="http://example.com/inbox",
|
inbox="https://example.com/users/nutria/inbox",
|
||||||
outbox="https://example.com/users/nutria/outbox",
|
shared_inbox="http://example.com/inbox",
|
||||||
)
|
outbox="https://example.com/users/nutria/outbox",
|
||||||
|
)
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||||
mock_self = MockSelf("public", self.local_user)
|
mock_self = MockSelf("public", self.local_user)
|
||||||
self.local_user.followers.add(self.remote_user)
|
self.local_user.followers.add(self.remote_user)
|
||||||
|
@ -206,17 +212,18 @@ class ActivitypubMixins(TestCase):
|
||||||
|
|
||||||
def test_get_recipients_software(self, _):
|
def test_get_recipients_software(self, _):
|
||||||
"""should differentiate between bookwyrm and other remote users"""
|
"""should differentiate between bookwyrm and other remote users"""
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
another_remote_user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"nutria",
|
another_remote_user = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
local=False,
|
"nutriaword",
|
||||||
remote_id="https://example.com/users/nutria",
|
local=False,
|
||||||
inbox="https://example.com/users/nutria/inbox",
|
remote_id="https://example.com/users/nutria",
|
||||||
outbox="https://example.com/users/nutria/outbox",
|
inbox="https://example.com/users/nutria/inbox",
|
||||||
bookwyrm_user=False,
|
outbox="https://example.com/users/nutria/outbox",
|
||||||
)
|
bookwyrm_user=False,
|
||||||
|
)
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||||
mock_self = MockSelf("public", self.local_user)
|
mock_self = MockSelf("public", self.local_user)
|
||||||
self.local_user.followers.add(self.remote_user)
|
self.local_user.followers.add(self.remote_user)
|
||||||
|
|
|
@ -12,19 +12,20 @@ class BaseModel(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""shared data"""
|
"""shared data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
class BookWyrmTestModel(base_model.BookWyrmModel):
|
class BookWyrmTestModel(base_model.BookWyrmModel):
|
||||||
"""just making it not abstract"""
|
"""just making it not abstract"""
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from bookwyrm import models, settings
|
from bookwyrm import models, settings
|
||||||
from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10
|
from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10
|
||||||
|
@ -12,17 +13,18 @@ class Book(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we'll need some books"""
|
"""we'll need some books"""
|
||||||
self.work = models.Work.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Work", remote_id="https://example.com/book/1"
|
self.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",
|
self.first_edition = models.Edition.objects.create(
|
||||||
parent_work=self.work,
|
title="Example Edition",
|
||||||
)
|
parent_work=self.work,
|
||||||
self.second_edition = models.Edition.objects.create(
|
)
|
||||||
title="Another Example Edition",
|
self.second_edition = models.Edition.objects.create(
|
||||||
parent_work=self.work,
|
title="Another Example Edition",
|
||||||
)
|
parent_work=self.work,
|
||||||
|
)
|
||||||
|
|
||||||
def test_remote_id(self):
|
def test_remote_id(self):
|
||||||
"""fanciness with remote/origin ids"""
|
"""fanciness with remote/origin ids"""
|
||||||
|
@ -56,7 +58,8 @@ class Book(TestCase):
|
||||||
|
|
||||||
def test_get_edition_info(self):
|
def test_get_edition_info(self):
|
||||||
"""text slug about an edition"""
|
"""text slug about an edition"""
|
||||||
book = models.Edition.objects.create(title="Test Edition")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
book = models.Edition.objects.create(title="Test Edition")
|
||||||
self.assertEqual(book.edition_info, "")
|
self.assertEqual(book.edition_info, "")
|
||||||
|
|
||||||
book.physical_format = "worm"
|
book.physical_format = "worm"
|
||||||
|
|
|
@ -11,29 +11,30 @@ class FederatedServer(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we'll need a user"""
|
"""we'll need a user"""
|
||||||
self.server = models.FederatedServer.objects.create(server_name="test.server")
|
self.server = models.FederatedServer.objects.create(server_name="test.server")
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
self.remote_user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"rat",
|
self.remote_user = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
federated_server=self.server,
|
"ratword",
|
||||||
local=False,
|
federated_server=self.server,
|
||||||
remote_id="https://example.com/users/rat",
|
local=False,
|
||||||
inbox="https://example.com/users/rat/inbox",
|
remote_id="https://example.com/users/rat",
|
||||||
outbox="https://example.com/users/rat/outbox",
|
inbox="https://example.com/users/rat/inbox",
|
||||||
)
|
outbox="https://example.com/users/rat/outbox",
|
||||||
self.inactive_remote_user = models.User.objects.create_user(
|
)
|
||||||
"nutria",
|
self.inactive_remote_user = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
federated_server=self.server,
|
"nutriaword",
|
||||||
local=False,
|
federated_server=self.server,
|
||||||
remote_id="https://example.com/users/nutria",
|
local=False,
|
||||||
inbox="https://example.com/users/nutria/inbox",
|
remote_id="https://example.com/users/nutria",
|
||||||
outbox="https://example.com/users/nutria/outbox",
|
inbox="https://example.com/users/nutria/inbox",
|
||||||
is_active=False,
|
outbox="https://example.com/users/nutria/outbox",
|
||||||
deactivation_reason="self_deletion",
|
is_active=False,
|
||||||
)
|
deactivation_reason="self_deletion",
|
||||||
|
)
|
||||||
|
|
||||||
def test_block_unblock(self):
|
def test_block_unblock(self):
|
||||||
"""block a server and all users on it"""
|
"""block a server and all users on it"""
|
||||||
|
|
|
@ -188,9 +188,10 @@ class ActivitypubFields(TestCase):
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
def test_privacy_field_set_activity_from_field(self, *_):
|
def test_privacy_field_set_activity_from_field(self, *_):
|
||||||
"""translate between to/cc fields and privacy"""
|
"""translate between to/cc fields and privacy"""
|
||||||
user = User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
user = User.objects.create_user(
|
||||||
)
|
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||||
|
)
|
||||||
public = "https://www.w3.org/ns/activitystreams#Public"
|
public = "https://www.w3.org/ns/activitystreams#Public"
|
||||||
followers = "%s/followers" % user.remote_id
|
followers = "%s/followers" % user.remote_id
|
||||||
|
|
||||||
|
@ -248,16 +249,20 @@ class ActivitypubFields(TestCase):
|
||||||
del userdata["icon"]
|
del userdata["icon"]
|
||||||
|
|
||||||
# it shouldn't match with this unrelated user:
|
# it shouldn't match with this unrelated user:
|
||||||
unrelated_user = User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
unrelated_user = User.objects.create_user(
|
||||||
)
|
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||||
|
)
|
||||||
|
|
||||||
# test receiving an unknown remote id and loading data
|
# test receiving an unknown remote id and loading data
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET, "https://example.com/user/mouse", json=userdata, status=200
|
responses.GET,
|
||||||
)
|
"https://example.com/user/mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
json=userdata,
|
||||||
value = instance.field_from_activity("https://example.com/user/mouse")
|
status=200,
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
value = instance.field_from_activity("https://example.com/user/mouse")
|
||||||
self.assertIsInstance(value, User)
|
self.assertIsInstance(value, User)
|
||||||
self.assertNotEqual(value, unrelated_user)
|
self.assertNotEqual(value, unrelated_user)
|
||||||
self.assertEqual(value.remote_id, "https://example.com/user/mouse")
|
self.assertEqual(value.remote_id, "https://example.com/user/mouse")
|
||||||
|
@ -272,11 +277,12 @@ class ActivitypubFields(TestCase):
|
||||||
del userdata["icon"]
|
del userdata["icon"]
|
||||||
|
|
||||||
# it shouldn't match with this unrelated user:
|
# it shouldn't match with this unrelated user:
|
||||||
unrelated_user = User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
unrelated_user = User.objects.create_user(
|
||||||
)
|
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
)
|
||||||
value = instance.field_from_activity(activitypub.Person(**userdata))
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
value = instance.field_from_activity(activitypub.Person(**userdata))
|
||||||
self.assertIsInstance(value, User)
|
self.assertIsInstance(value, User)
|
||||||
self.assertNotEqual(value, unrelated_user)
|
self.assertNotEqual(value, unrelated_user)
|
||||||
self.assertEqual(value.remote_id, "https://example.com/user/mouse")
|
self.assertEqual(value.remote_id, "https://example.com/user/mouse")
|
||||||
|
@ -288,28 +294,31 @@ class ActivitypubFields(TestCase):
|
||||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||||
userdata = json.loads(datafile.read_bytes())
|
userdata = json.loads(datafile.read_bytes())
|
||||||
user = User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
user = User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
user.remote_id = "https://example.com/user/mouse"
|
)
|
||||||
user.save(broadcast=False)
|
user.remote_id = "https://example.com/user/mouse"
|
||||||
User.objects.create_user(
|
user.save(broadcast=False)
|
||||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast"):
|
User.objects.create_user(
|
||||||
value = instance.field_from_activity(activitypub.Person(**userdata))
|
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast"):
|
||||||
|
value = instance.field_from_activity(activitypub.Person(**userdata))
|
||||||
self.assertEqual(value, user)
|
self.assertEqual(value, user)
|
||||||
|
|
||||||
def test_foreign_key_from_activity_str_existing(self):
|
def test_foreign_key_from_activity_str_existing(self):
|
||||||
"""test receiving a remote id of an existing object in the db"""
|
"""test receiving a remote id of an existing object in the db"""
|
||||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
user = User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
user = User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
User.objects.create_user(
|
)
|
||||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
User.objects.create_user(
|
||||||
)
|
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||||
|
)
|
||||||
|
|
||||||
value = instance.field_from_activity(user.remote_id)
|
value = instance.field_from_activity(user.remote_id)
|
||||||
self.assertEqual(value, user)
|
self.assertEqual(value, user)
|
||||||
|
@ -351,10 +360,11 @@ class ActivitypubFields(TestCase):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET, "https://example.com/user/mouse", json=userdata, status=200
|
responses.GET, "https://example.com/user/mouse", json=userdata, status=200
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
value = instance.field_from_activity(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
["https://example.com/user/mouse", "bleh"]
|
value = instance.field_from_activity(
|
||||||
)
|
["https://example.com/user/mouse", "bleh"]
|
||||||
|
)
|
||||||
self.assertIsInstance(value, list)
|
self.assertIsInstance(value, list)
|
||||||
self.assertEqual(len(value), 1)
|
self.assertEqual(len(value), 1)
|
||||||
self.assertIsInstance(value[0], User)
|
self.assertIsInstance(value[0], User)
|
||||||
|
@ -386,16 +396,17 @@ class ActivitypubFields(TestCase):
|
||||||
@patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast")
|
@patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast")
|
||||||
def test_image_field(self, _):
|
def test_image_field(self, _):
|
||||||
"""storing images"""
|
"""storing images"""
|
||||||
user = User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
user = User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
)
|
||||||
"../../static/images/default_avi.jpg"
|
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||||
)
|
"../../static/images/default_avi.jpg"
|
||||||
image = Image.open(image_file)
|
)
|
||||||
output = BytesIO()
|
image = Image.open(image_file)
|
||||||
image.save(output, format=image.format)
|
output = BytesIO()
|
||||||
user.avatar.save("test.jpg", ContentFile(output.getvalue()))
|
image.save(output, format=image.format)
|
||||||
|
user.avatar.save("test.jpg", ContentFile(output.getvalue()))
|
||||||
|
|
||||||
output = fields.image_serializer(user.avatar, alt="alt text")
|
output = fields.image_serializer(user.avatar, alt="alt text")
|
||||||
self.assertIsNotNone(
|
self.assertIsNotNone(
|
||||||
|
|
|
@ -59,9 +59,10 @@ class ImportJob(TestCase):
|
||||||
unknown_read_data["Exclusive Shelf"] = "read"
|
unknown_read_data["Exclusive Shelf"] = "read"
|
||||||
unknown_read_data["Date Read"] = ""
|
unknown_read_data["Date Read"] = ""
|
||||||
|
|
||||||
user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
|
)
|
||||||
job = models.ImportJob.objects.create(user=user)
|
job = models.ImportJob.objects.create(user=user)
|
||||||
self.item_1 = models.ImportItem.objects.create(
|
self.item_1 = models.ImportItem.objects.create(
|
||||||
job=job, index=1, data=currently_reading_data
|
job=job, index=1, data=currently_reading_data
|
||||||
|
@ -174,6 +175,9 @@ class ImportJob(TestCase):
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
"bookwyrm.connectors.openlibrary.Connector." "get_authors_from_data"
|
||||||
):
|
):
|
||||||
book = self.item_1.get_book_from_isbn()
|
with patch(
|
||||||
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
|
):
|
||||||
|
book = self.item_1.get_book_from_isbn()
|
||||||
|
|
||||||
self.assertEqual(book.title, "Sabriel")
|
self.assertEqual(book.title, "Sabriel")
|
||||||
|
|
|
@ -11,11 +11,13 @@ class List(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""look, a list"""
|
"""look, a list"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
work = models.Work.objects.create(title="hello")
|
)
|
||||||
self.book = models.Edition.objects.create(title="hi", parent_work=work)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
work = models.Work.objects.create(title="hello")
|
||||||
|
self.book = models.Edition.objects.create(title="hi", parent_work=work)
|
||||||
|
|
||||||
def test_remote_id(self, _):
|
def test_remote_id(self, _):
|
||||||
"""shelves use custom remote ids"""
|
"""shelves use custom remote ids"""
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
""" testing models """
|
""" testing models """
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
|
||||||
|
@ -10,15 +11,16 @@ class ReadThrough(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""look, a shelf"""
|
"""look, a shelf"""
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
self.user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
|
)
|
||||||
|
|
||||||
self.work = models.Work.objects.create(title="Example Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.work = models.Work.objects.create(title="Example Work")
|
||||||
self.edition = models.Edition.objects.create(
|
self.edition = models.Edition.objects.create(
|
||||||
title="Example Edition", parent_work=self.work
|
title="Example Edition", parent_work=self.work
|
||||||
)
|
)
|
||||||
|
|
||||||
self.readthrough = models.ReadThrough.objects.create(
|
self.readthrough = models.ReadThrough.objects.create(
|
||||||
user=self.user, book=self.edition
|
user=self.user, book=self.edition
|
||||||
|
|
|
@ -10,21 +10,22 @@ class Relationship(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need some users for this"""
|
"""we need some users for this"""
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
self.remote_user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"rat",
|
self.remote_user = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=False,
|
"ratword",
|
||||||
remote_id="https://example.com/users/rat",
|
local=False,
|
||||||
inbox="https://example.com/users/rat/inbox",
|
remote_id="https://example.com/users/rat",
|
||||||
outbox="https://example.com/users/rat/outbox",
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
self.local_user = models.User.objects.create_user(
|
||||||
|
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user.remote_id = "http://local.com/user/mouse"
|
||||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
self.local_user.save(broadcast=False)
|
||||||
)
|
|
||||||
self.local_user.remote_id = "http://local.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
|
|
||||||
def test_user_follows_from_request(self):
|
def test_user_follows_from_request(self):
|
||||||
"""convert a follow request into a follow"""
|
"""convert a follow request into a follow"""
|
||||||
|
|
|
@ -12,11 +12,15 @@ class Shelf(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""look, a shelf"""
|
"""look, a shelf"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
work = models.Work.objects.create(title="Test Work")
|
)
|
||||||
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
work = models.Work.objects.create(title="Test Work")
|
||||||
|
self.book = models.Edition.objects.create(
|
||||||
|
title="test book", parent_work=work
|
||||||
|
)
|
||||||
|
|
||||||
def test_remote_id(self):
|
def test_remote_id(self):
|
||||||
"""shelves use custom remote ids"""
|
"""shelves use custom remote ids"""
|
||||||
|
|
|
@ -22,29 +22,31 @@ class Status(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""useful things for creating a status"""
|
"""useful things for creating a status"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
self.book = models.Edition.objects.create(title="Test Edition")
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="Test Edition")
|
||||||
|
|
||||||
image_file = pathlib.Path(__file__).parent.joinpath(
|
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||||
"../../static/images/default_avi.jpg"
|
"../../static/images/default_avi.jpg"
|
||||||
)
|
)
|
||||||
image = Image.open(image_file)
|
image = Image.open(image_file)
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
with patch("bookwyrm.models.Status.broadcast"):
|
with patch("bookwyrm.models.Status.broadcast"):
|
||||||
image.save(output, format=image.format)
|
image.save(output, format=image.format)
|
||||||
self.book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
self.book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||||
|
|
||||||
def test_status_generated_fields(self, *_):
|
def test_status_generated_fields(self, *_):
|
||||||
"""setting remote id"""
|
"""setting remote id"""
|
||||||
|
@ -59,9 +61,10 @@ class Status(TestCase):
|
||||||
child = models.Status.objects.create(
|
child = models.Status.objects.create(
|
||||||
content="hello", reply_parent=parent, user=self.local_user
|
content="hello", reply_parent=parent, user=self.local_user
|
||||||
)
|
)
|
||||||
models.Review.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
content="hey", reply_parent=parent, user=self.local_user, book=self.book
|
models.Review.objects.create(
|
||||||
)
|
content="hey", reply_parent=parent, user=self.local_user, book=self.book
|
||||||
|
)
|
||||||
models.Status.objects.create(
|
models.Status.objects.create(
|
||||||
content="hi hello", reply_parent=child, user=self.local_user
|
content="hi hello", reply_parent=child, user=self.local_user
|
||||||
)
|
)
|
||||||
|
@ -93,9 +96,10 @@ class Status(TestCase):
|
||||||
child = models.Status.objects.create(
|
child = models.Status.objects.create(
|
||||||
content="hello", reply_parent=parent, user=self.local_user
|
content="hello", reply_parent=parent, user=self.local_user
|
||||||
)
|
)
|
||||||
models.Review.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
content="hey", reply_parent=parent, user=self.local_user, book=self.book
|
models.Review.objects.create(
|
||||||
)
|
content="hey", reply_parent=parent, user=self.local_user, book=self.book
|
||||||
|
)
|
||||||
models.Status.objects.create(
|
models.Status.objects.create(
|
||||||
content="hi hello", reply_parent=child, user=self.local_user
|
content="hi hello", reply_parent=child, user=self.local_user
|
||||||
)
|
)
|
||||||
|
@ -252,14 +256,15 @@ class Status(TestCase):
|
||||||
|
|
||||||
def test_review_to_activity(self, *_):
|
def test_review_to_activity(self, *_):
|
||||||
"""subclass of the base model version with a "pure" serializer"""
|
"""subclass of the base model version with a "pure" serializer"""
|
||||||
status = models.Review.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
name="Review name",
|
status = models.Review.objects.create(
|
||||||
content="test content",
|
name="Review name",
|
||||||
rating=3.0,
|
content="test content",
|
||||||
user=self.local_user,
|
rating=3.0,
|
||||||
book=self.book,
|
user=self.local_user,
|
||||||
)
|
book=self.book,
|
||||||
activity = status.to_activity()
|
)
|
||||||
|
activity = status.to_activity()
|
||||||
self.assertEqual(activity["id"], status.remote_id)
|
self.assertEqual(activity["id"], status.remote_id)
|
||||||
self.assertEqual(activity["type"], "Review")
|
self.assertEqual(activity["type"], "Review")
|
||||||
self.assertEqual(activity["rating"], 3)
|
self.assertEqual(activity["rating"], 3)
|
||||||
|
@ -269,14 +274,15 @@ class Status(TestCase):
|
||||||
|
|
||||||
def test_review_to_pure_activity(self, *_):
|
def test_review_to_pure_activity(self, *_):
|
||||||
"""subclass of the base model version with a "pure" serializer"""
|
"""subclass of the base model version with a "pure" serializer"""
|
||||||
status = models.Review.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
name="Review's name",
|
status = models.Review.objects.create(
|
||||||
content="test content",
|
name="Review's name",
|
||||||
rating=3.0,
|
content="test content",
|
||||||
user=self.local_user,
|
rating=3.0,
|
||||||
book=self.book,
|
user=self.local_user,
|
||||||
)
|
book=self.book,
|
||||||
activity = status.to_activity(pure=True)
|
)
|
||||||
|
activity = status.to_activity(pure=True)
|
||||||
self.assertEqual(activity["id"], status.remote_id)
|
self.assertEqual(activity["id"], status.remote_id)
|
||||||
self.assertEqual(activity["type"], "Article")
|
self.assertEqual(activity["type"], "Article")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -293,13 +299,14 @@ class Status(TestCase):
|
||||||
|
|
||||||
def test_review_to_pure_activity_no_rating(self, *_):
|
def test_review_to_pure_activity_no_rating(self, *_):
|
||||||
"""subclass of the base model version with a "pure" serializer"""
|
"""subclass of the base model version with a "pure" serializer"""
|
||||||
status = models.Review.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
name="Review name",
|
status = models.Review.objects.create(
|
||||||
content="test content",
|
name="Review name",
|
||||||
user=self.local_user,
|
content="test content",
|
||||||
book=self.book,
|
user=self.local_user,
|
||||||
)
|
book=self.book,
|
||||||
activity = status.to_activity(pure=True)
|
)
|
||||||
|
activity = status.to_activity(pure=True)
|
||||||
self.assertEqual(activity["id"], status.remote_id)
|
self.assertEqual(activity["id"], status.remote_id)
|
||||||
self.assertEqual(activity["type"], "Article")
|
self.assertEqual(activity["type"], "Article")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -315,12 +322,13 @@ class Status(TestCase):
|
||||||
|
|
||||||
def test_reviewrating_to_pure_activity(self, *_):
|
def test_reviewrating_to_pure_activity(self, *_):
|
||||||
"""subclass of the base model version with a "pure" serializer"""
|
"""subclass of the base model version with a "pure" serializer"""
|
||||||
status = models.ReviewRating.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
rating=3.0,
|
status = models.ReviewRating.objects.create(
|
||||||
user=self.local_user,
|
rating=3.0,
|
||||||
book=self.book,
|
user=self.local_user,
|
||||||
)
|
book=self.book,
|
||||||
activity = status.to_activity(pure=True)
|
)
|
||||||
|
activity = status.to_activity(pure=True)
|
||||||
self.assertEqual(activity["id"], status.remote_id)
|
self.assertEqual(activity["id"], status.remote_id)
|
||||||
self.assertEqual(activity["type"], "Note")
|
self.assertEqual(activity["type"], "Note")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -349,11 +357,12 @@ class Status(TestCase):
|
||||||
status = models.Status.objects.create(
|
status = models.Status.objects.create(
|
||||||
content="test content", user=self.local_user
|
content="test content", user=self.local_user
|
||||||
)
|
)
|
||||||
fav = models.Favorite.objects.create(status=status, user=self.local_user)
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
|
fav = models.Favorite.objects.create(status=status, user=self.local_user)
|
||||||
|
|
||||||
# can't fav a status twice
|
# can't fav a status twice
|
||||||
with self.assertRaises(IntegrityError):
|
with self.assertRaises(IntegrityError):
|
||||||
models.Favorite.objects.create(status=status, user=self.local_user)
|
models.Favorite.objects.create(status=status, user=self.local_user)
|
||||||
|
|
||||||
activity = fav.to_activity()
|
activity = fav.to_activity()
|
||||||
self.assertEqual(activity["type"], "Like")
|
self.assertEqual(activity["type"], "Like")
|
||||||
|
|
|
@ -11,15 +11,16 @@ from bookwyrm.settings import DOMAIN
|
||||||
# pylint: disable=missing-function-docstring
|
# pylint: disable=missing-function-docstring
|
||||||
class User(TestCase):
|
class User(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@%s" % DOMAIN,
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@%s" % DOMAIN,
|
||||||
"mouseword",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
name="hi",
|
localname="mouse",
|
||||||
bookwyrm_user=False,
|
name="hi",
|
||||||
)
|
bookwyrm_user=False,
|
||||||
|
)
|
||||||
|
|
||||||
def test_computed_fields(self):
|
def test_computed_fields(self):
|
||||||
"""username instead of id here"""
|
"""username instead of id here"""
|
||||||
|
@ -34,15 +35,16 @@ class User(TestCase):
|
||||||
self.assertIsNotNone(self.user.key_pair.public_key)
|
self.assertIsNotNone(self.user.key_pair.public_key)
|
||||||
|
|
||||||
def test_remote_user(self):
|
def test_remote_user(self):
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
user = models.User.objects.create_user(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
"rat",
|
user = models.User.objects.create_user(
|
||||||
"rat@rat.rat",
|
"rat",
|
||||||
"ratword",
|
"rat@rat.rat",
|
||||||
local=False,
|
"ratword",
|
||||||
remote_id="https://example.com/dfjkg",
|
local=False,
|
||||||
bookwyrm_user=False,
|
remote_id="https://example.com/dfjkg",
|
||||||
)
|
bookwyrm_user=False,
|
||||||
|
)
|
||||||
self.assertEqual(user.username, "rat@example.com")
|
self.assertEqual(user.username, "rat@example.com")
|
||||||
|
|
||||||
def test_user_shelves(self):
|
def test_user_shelves(self):
|
||||||
|
|
|
@ -11,23 +11,29 @@ class Activitystreams(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
self.local_user = models.User.objects.create_user(
|
||||||
)
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
self.another_user = models.User.objects.create_user(
|
|
||||||
"nutria", "nutria@nutria.nutria", "password", local=True, localname="nutria"
|
|
||||||
)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
self.book = models.Edition.objects.create(title="test book")
|
self.another_user = models.User.objects.create_user(
|
||||||
|
"nutria",
|
||||||
|
"nutria@nutria.nutria",
|
||||||
|
"password",
|
||||||
|
local=True,
|
||||||
|
localname="nutria",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="test book")
|
||||||
|
|
||||||
class TestStream(activitystreams.ActivityStream):
|
class TestStream(activitystreams.ActivityStream):
|
||||||
"""test stream, don't have to do anything here"""
|
"""test stream, don't have to do anything here"""
|
||||||
|
|
|
@ -15,14 +15,16 @@ class Emailing(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_invite_email(self, email_mock):
|
def test_invite_email(self, email_mock):
|
||||||
"""load the invite email"""
|
"""load the invite email"""
|
||||||
|
|
119
bookwyrm/tests/test_preview_images.py
Normal file
119
bookwyrm/tests/test_preview_images.py
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
""" test generating preview images """
|
||||||
|
import pathlib
|
||||||
|
from unittest.mock import patch
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.test.client import RequestFactory
|
||||||
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
|
from django.db.models.fields.files import ImageFieldFile
|
||||||
|
|
||||||
|
from bookwyrm import models, settings
|
||||||
|
|
||||||
|
from bookwyrm.preview_images import (
|
||||||
|
generate_site_preview_image_task,
|
||||||
|
generate_edition_preview_image_task,
|
||||||
|
generate_user_preview_image_task,
|
||||||
|
generate_preview_image,
|
||||||
|
save_and_cleanup,
|
||||||
|
)
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
|
avatar_file = pathlib.Path(__file__).parent.joinpath(
|
||||||
|
"../static/images/no_cover.jpg"
|
||||||
|
)
|
||||||
|
self.local_user = models.User.objects.create_user(
|
||||||
|
"possum@local.com",
|
||||||
|
"possum@possum.possum",
|
||||||
|
"password",
|
||||||
|
local=True,
|
||||||
|
localname="possum",
|
||||||
|
avatar=SimpleUploadedFile(
|
||||||
|
avatar_file,
|
||||||
|
open(avatar_file, "rb").read(),
|
||||||
|
content_type="image/jpeg",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
|
self.edition = models.Edition.objects.create(
|
||||||
|
title="Example Edition",
|
||||||
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=self.work,
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
self.site = models.SiteSettings.objects.create()
|
||||||
|
|
||||||
|
def test_generate_preview_image(self, *args, **kwargs):
|
||||||
|
image_file = pathlib.Path(__file__).parent.joinpath(
|
||||||
|
"../static/images/no_cover.jpg"
|
||||||
|
)
|
||||||
|
|
||||||
|
texts = {
|
||||||
|
"text_one": "Awesome Possum",
|
||||||
|
"text_three": "@possum@local.com",
|
||||||
|
}
|
||||||
|
|
||||||
|
result = generate_preview_image(texts=texts, picture=image_file, rating=5)
|
||||||
|
self.assertIsInstance(result, Image.Image)
|
||||||
|
self.assertEqual(
|
||||||
|
result.size, (settings.PREVIEW_IMG_WIDTH, settings.PREVIEW_IMG_HEIGHT)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_store_preview_image(self, *args, **kwargs):
|
||||||
|
image = Image.new("RGB", (200, 200), color="#F00")
|
||||||
|
|
||||||
|
result = save_and_cleanup(image, instance=self.local_user)
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
self.local_user.refresh_from_db()
|
||||||
|
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
|
||||||
|
self.assertIsNotNone(self.local_user.preview_image)
|
||||||
|
self.assertEqual(self.local_user.preview_image.width, 200)
|
||||||
|
self.assertEqual(self.local_user.preview_image.height, 200)
|
||||||
|
|
||||||
|
def test_site_preview(self, *args, **kwargs):
|
||||||
|
"""generate site preview"""
|
||||||
|
generate_site_preview_image_task()
|
||||||
|
|
||||||
|
self.site.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertIsInstance(self.site.preview_image, ImageFieldFile)
|
||||||
|
self.assertIsNotNone(self.site.preview_image)
|
||||||
|
self.assertEqual(self.site.preview_image.width, settings.PREVIEW_IMG_WIDTH)
|
||||||
|
self.assertEqual(self.site.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||||
|
|
||||||
|
def test_edition_preview(self, *args, **kwargs):
|
||||||
|
"""generate edition preview"""
|
||||||
|
generate_edition_preview_image_task(self.edition.id)
|
||||||
|
|
||||||
|
self.edition.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertIsInstance(self.edition.preview_image, ImageFieldFile)
|
||||||
|
self.assertIsNotNone(self.edition.preview_image)
|
||||||
|
self.assertEqual(self.edition.preview_image.width, settings.PREVIEW_IMG_WIDTH)
|
||||||
|
self.assertEqual(self.edition.preview_image.height, settings.PREVIEW_IMG_HEIGHT)
|
||||||
|
|
||||||
|
def test_user_preview(self, *args, **kwargs):
|
||||||
|
"""generate user preview"""
|
||||||
|
generate_user_preview_image_task(self.local_user.id)
|
||||||
|
|
||||||
|
self.local_user.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertIsInstance(self.local_user.preview_image, ImageFieldFile)
|
||||||
|
self.assertIsNotNone(self.local_user.preview_image)
|
||||||
|
self.assertEqual(
|
||||||
|
self.local_user.preview_image.width, settings.PREVIEW_IMG_WIDTH
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.local_user.preview_image.height, settings.PREVIEW_IMG_HEIGHT
|
||||||
|
)
|
|
@ -37,15 +37,20 @@ class Signature(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""create users and test data"""
|
"""create users and test data"""
|
||||||
self.mouse = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@%s" % DOMAIN, "mouse@example.com", "", local=True, localname="mouse"
|
self.mouse = models.User.objects.create_user(
|
||||||
)
|
"mouse@%s" % DOMAIN,
|
||||||
self.rat = models.User.objects.create_user(
|
"mouse@example.com",
|
||||||
"rat@%s" % DOMAIN, "rat@example.com", "", local=True, localname="rat"
|
"",
|
||||||
)
|
local=True,
|
||||||
self.cat = models.User.objects.create_user(
|
localname="mouse",
|
||||||
"cat@%s" % DOMAIN, "cat@example.com", "", local=True, localname="cat"
|
)
|
||||||
)
|
self.rat = models.User.objects.create_user(
|
||||||
|
"rat@%s" % DOMAIN, "rat@example.com", "", local=True, localname="rat"
|
||||||
|
)
|
||||||
|
self.cat = models.User.objects.create_user(
|
||||||
|
"cat@%s" % DOMAIN, "cat@example.com", "", local=True, localname="cat"
|
||||||
|
)
|
||||||
|
|
||||||
private_key, public_key = create_key_pair()
|
private_key, public_key = create_key_pair()
|
||||||
|
|
||||||
|
@ -53,7 +58,8 @@ class Signature(TestCase):
|
||||||
"http://localhost/user/remote", KeyPair(private_key, public_key)
|
"http://localhost/user/remote", KeyPair(private_key, public_key)
|
||||||
)
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def send(self, signature, now, data, digest):
|
def send(self, signature, now, data, digest):
|
||||||
"""test request"""
|
"""test request"""
|
||||||
|
@ -113,9 +119,10 @@ class Signature(TestCase):
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.user.get_remote_reviews.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
response = self.send_test_request(sender=self.fake_remote)
|
with patch("bookwyrm.models.user.get_remote_reviews.delay"):
|
||||||
self.assertEqual(response.status_code, 200)
|
response = self.send_test_request(sender=self.fake_remote)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_key_needs_refresh(self):
|
def test_key_needs_refresh(self):
|
||||||
|
@ -136,22 +143,23 @@ class Signature(TestCase):
|
||||||
data["publicKey"]["publicKeyPem"] = key_pair.public_key
|
data["publicKey"]["publicKeyPem"] = key_pair.public_key
|
||||||
responses.add(responses.GET, self.fake_remote.remote_id, json=data, status=200)
|
responses.add(responses.GET, self.fake_remote.remote_id, json=data, status=200)
|
||||||
|
|
||||||
with patch("bookwyrm.models.user.get_remote_reviews.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
# Key correct:
|
with patch("bookwyrm.models.user.get_remote_reviews.delay"):
|
||||||
response = self.send_test_request(sender=self.fake_remote)
|
# Key correct:
|
||||||
self.assertEqual(response.status_code, 200)
|
response = self.send_test_request(sender=self.fake_remote)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
# Old key is cached, so still works:
|
# Old key is cached, so still works:
|
||||||
response = self.send_test_request(sender=self.fake_remote)
|
response = self.send_test_request(sender=self.fake_remote)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
# Try with new key:
|
# Try with new key:
|
||||||
response = self.send_test_request(sender=new_sender)
|
response = self.send_test_request(sender=new_sender)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
# Now the old key will fail:
|
# Now the old key will fail:
|
||||||
response = self.send_test_request(sender=self.fake_remote)
|
response = self.send_test_request(sender=self.fake_remote)
|
||||||
self.assertEqual(response.status_code, 401)
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_nonexistent_signer(self):
|
def test_nonexistent_signer(self):
|
||||||
|
|
|
@ -22,27 +22,30 @@ class TemplateTags(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""create some filler objects"""
|
"""create some filler objects"""
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.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")
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.rat",
|
||||||
|
"ratword",
|
||||||
|
remote_id="http://example.com/rat",
|
||||||
|
local=False,
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="Test Book")
|
||||||
|
|
||||||
def test_get_user_rating(self, *_):
|
def test_get_user_rating(self, *_):
|
||||||
"""get a user's most recent rating of a book"""
|
"""get a user's most recent rating of a book"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
models.Review.objects.create(user=self.user, book=self.book, rating=3)
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
models.Review.objects.create(user=self.user, book=self.book, rating=3)
|
||||||
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3)
|
self.assertEqual(bookwyrm_tags.get_user_rating(self.book, self.user), 3)
|
||||||
|
|
||||||
def test_get_user_rating_doesnt_exist(self, *_):
|
def test_get_user_rating_doesnt_exist(self, *_):
|
||||||
|
@ -63,9 +66,12 @@ class TemplateTags(TestCase):
|
||||||
def test_get_replies(self, *_):
|
def test_get_replies(self, *_):
|
||||||
"""direct replies to a status"""
|
"""direct replies to a status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
parent = models.Review.objects.create(
|
with patch(
|
||||||
user=self.user, book=self.book, content="hi"
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
)
|
):
|
||||||
|
parent = models.Review.objects.create(
|
||||||
|
user=self.user, book=self.book, content="hi"
|
||||||
|
)
|
||||||
first_child = models.Status.objects.create(
|
first_child = models.Status.objects.create(
|
||||||
reply_parent=parent, user=self.user, content="hi"
|
reply_parent=parent, user=self.user, content="hi"
|
||||||
)
|
)
|
||||||
|
@ -91,9 +97,12 @@ class TemplateTags(TestCase):
|
||||||
def test_get_parent(self, *_):
|
def test_get_parent(self, *_):
|
||||||
"""get the reply parent of a status"""
|
"""get the reply parent of a status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
parent = models.Review.objects.create(
|
with patch(
|
||||||
user=self.user, book=self.book, content="hi"
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
)
|
):
|
||||||
|
parent = models.Review.objects.create(
|
||||||
|
user=self.user, book=self.book, content="hi"
|
||||||
|
)
|
||||||
child = models.Status.objects.create(
|
child = models.Status.objects.create(
|
||||||
reply_parent=parent, user=self.user, content="hi"
|
reply_parent=parent, user=self.user, content="hi"
|
||||||
)
|
)
|
||||||
|
@ -104,7 +113,8 @@ class TemplateTags(TestCase):
|
||||||
|
|
||||||
def test_get_user_liked(self, *_):
|
def test_get_user_liked(self, *_):
|
||||||
"""did a user like a status"""
|
"""did a user like a status"""
|
||||||
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
||||||
|
|
||||||
self.assertFalse(interaction.get_user_liked(self.user, status))
|
self.assertFalse(interaction.get_user_liked(self.user, status))
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
@ -113,7 +123,8 @@ class TemplateTags(TestCase):
|
||||||
|
|
||||||
def test_get_user_boosted(self, *_):
|
def test_get_user_boosted(self, *_):
|
||||||
"""did a user boost a status"""
|
"""did a user boost a status"""
|
||||||
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
||||||
|
|
||||||
self.assertFalse(interaction.get_user_boosted(self.user, status))
|
self.assertFalse(interaction.get_user_boosted(self.user, status))
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
@ -122,28 +133,34 @@ class TemplateTags(TestCase):
|
||||||
|
|
||||||
def test_get_boosted(self, *_):
|
def test_get_boosted(self, *_):
|
||||||
"""load a boosted status"""
|
"""load a boosted status"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
status = models.Review.objects.create(user=self.remote_user, book=self.book)
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
boost = models.Boost.objects.create(user=self.user, boosted_status=status)
|
status = models.Review.objects.create(
|
||||||
|
user=self.remote_user, book=self.book
|
||||||
|
)
|
||||||
|
boost = models.Boost.objects.create(
|
||||||
|
user=self.user, boosted_status=status
|
||||||
|
)
|
||||||
boosted = status_display.get_boosted(boost)
|
boosted = status_display.get_boosted(boost)
|
||||||
self.assertIsInstance(boosted, models.Review)
|
self.assertIsInstance(boosted, models.Review)
|
||||||
self.assertEqual(boosted, status)
|
self.assertEqual(boosted, status)
|
||||||
|
|
||||||
def test_get_book_description(self, *_):
|
def test_get_book_description(self, *_):
|
||||||
"""grab it from the edition or the parent"""
|
"""grab it from the edition or the parent"""
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book.parent_work = work
|
work = models.Work.objects.create(title="Test Work")
|
||||||
self.book.save()
|
self.book.parent_work = work
|
||||||
|
self.book.save()
|
||||||
|
|
||||||
self.assertIsNone(bookwyrm_tags.get_book_description(self.book))
|
self.assertIsNone(bookwyrm_tags.get_book_description(self.book))
|
||||||
|
|
||||||
work.description = "hi"
|
work.description = "hi"
|
||||||
work.save()
|
work.save()
|
||||||
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hi")
|
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hi")
|
||||||
|
|
||||||
self.book.description = "hello"
|
self.book.description = "hello"
|
||||||
self.book.save()
|
self.book.save()
|
||||||
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello")
|
self.assertEqual(bookwyrm_tags.get_book_description(self.book), "hello")
|
||||||
|
|
||||||
def test_get_uuid(self, *_):
|
def test_get_uuid(self, *_):
|
||||||
"""uuid functionality"""
|
"""uuid functionality"""
|
||||||
|
|
|
@ -18,25 +18,27 @@ class Inbox(TestCase):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.client = Client()
|
self.client = Client()
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
local_user = models.User.objects.create_user(
|
|
||||||
"mouse@example.com",
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@mouse.com",
|
local_user = models.User.objects.create_user(
|
||||||
"mouseword",
|
"mouse@example.com",
|
||||||
local=True,
|
"mouse@mouse.com",
|
||||||
localname="mouse",
|
"mouseword",
|
||||||
)
|
local=True,
|
||||||
local_user.remote_id = "https://example.com/user/mouse"
|
localname="mouse",
|
||||||
local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
local_user.remote_id = "https://example.com/user/mouse"
|
||||||
|
local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
self.create_json = {
|
self.create_json = {
|
||||||
"id": "hi",
|
"id": "hi",
|
||||||
"type": "Create",
|
"type": "Create",
|
||||||
|
@ -45,7 +47,8 @@ class Inbox(TestCase):
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
"object": {},
|
"object": {},
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_inbox_invalid_get(self):
|
def test_inbox_invalid_get(self):
|
||||||
"""shouldn't try to handle if the user is not found"""
|
"""shouldn't try to handle if the user is not found"""
|
||||||
|
|
|
@ -13,33 +13,35 @@ class InboxAdd(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
work = models.Work.objects.create(title="work title")
|
local_user.remote_id = "https://example.com/user/mouse"
|
||||||
self.book = models.Edition.objects.create(
|
local_user.save(broadcast=False)
|
||||||
title="Test",
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
remote_id="https://example.com/book/37292",
|
self.remote_user = models.User.objects.create_user(
|
||||||
parent_work=work,
|
"rat",
|
||||||
)
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
models.SiteSettings.objects.create()
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
work = models.Work.objects.create(title="work title")
|
||||||
|
self.book = models.Edition.objects.create(
|
||||||
|
title="Test",
|
||||||
|
remote_id="https://example.com/book/37292",
|
||||||
|
parent_work=work,
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_handle_add_book_to_shelf(self):
|
def test_handle_add_book_to_shelf(self):
|
||||||
|
|
|
@ -13,32 +13,34 @@ class InboxActivities(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
self.local_user.save(broadcast=False)
|
||||||
self.status = models.Status.objects.create(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
user=self.local_user,
|
self.remote_user = models.User.objects.create_user(
|
||||||
content="Test status",
|
"rat",
|
||||||
remote_id="https://example.com/status/1",
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
|
self.status = models.Status.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
content="Test status",
|
||||||
|
remote_id="https://example.com/status/1",
|
||||||
|
)
|
||||||
|
|
||||||
self.create_json = {
|
self.create_json = {
|
||||||
"id": "hi",
|
"id": "hi",
|
||||||
|
@ -48,7 +50,8 @@ class InboxActivities(TestCase):
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
"object": {},
|
"object": {},
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
|
@ -85,12 +88,13 @@ class InboxActivities(TestCase):
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores")
|
||||||
def test_boost_remote_status(self, redis_mock, _):
|
def test_boost_remote_status(self, redis_mock, _):
|
||||||
"""boost a status from a remote server"""
|
"""boost a status from a remote server"""
|
||||||
work = models.Work.objects.create(title="work title")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
book = models.Edition.objects.create(
|
work = models.Work.objects.create(title="work title")
|
||||||
title="Test",
|
book = models.Edition.objects.create(
|
||||||
remote_id="https://bookwyrm.social/book/37292",
|
title="Test",
|
||||||
parent_work=work,
|
remote_id="https://bookwyrm.social/book/37292",
|
||||||
)
|
parent_work=work,
|
||||||
|
)
|
||||||
self.assertEqual(models.Notification.objects.count(), 0)
|
self.assertEqual(models.Notification.objects.count(), 0)
|
||||||
activity = {
|
activity = {
|
||||||
"type": "Announce",
|
"type": "Announce",
|
||||||
|
|
|
@ -12,27 +12,28 @@ class InboxBlock(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
models.SiteSettings.objects.create()
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_blocks(self):
|
def test_handle_blocks(self):
|
||||||
"""create a "block" database entry from an activity"""
|
"""create a "block" database entry from an activity"""
|
||||||
|
|
|
@ -15,15 +15,26 @@ class InboxCreate(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
)
|
||||||
self.local_user.save(broadcast=False)
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
self.status = models.Status.objects.create(
|
self.status = models.Status.objects.create(
|
||||||
|
@ -31,16 +42,6 @@ class InboxCreate(TestCase):
|
||||||
content="Test status",
|
content="Test status",
|
||||||
remote_id="https://example.com/status/1",
|
remote_id="https://example.com/status/1",
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
|
||||||
|
|
||||||
self.create_json = {
|
self.create_json = {
|
||||||
"id": "hi",
|
"id": "hi",
|
||||||
|
@ -50,7 +51,8 @@ class InboxCreate(TestCase):
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
"object": {},
|
"object": {},
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_create_status(self):
|
def test_create_status(self):
|
||||||
"""the "it justs works" mode"""
|
"""the "it justs works" mode"""
|
||||||
|
@ -60,9 +62,11 @@ class InboxCreate(TestCase):
|
||||||
"../../data/ap_quotation.json"
|
"../../data/ap_quotation.json"
|
||||||
)
|
)
|
||||||
status_data = json.loads(datafile.read_bytes())
|
status_data = json.loads(datafile.read_bytes())
|
||||||
models.Edition.objects.create(
|
|
||||||
title="Test Book", remote_id="https://example.com/book/1"
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
)
|
models.Edition.objects.create(
|
||||||
|
title="Test Book", remote_id="https://example.com/book/1"
|
||||||
|
)
|
||||||
activity = self.create_json
|
activity = self.create_json
|
||||||
activity["object"] = status_data
|
activity["object"] = status_data
|
||||||
|
|
||||||
|
@ -129,9 +133,10 @@ class InboxCreate(TestCase):
|
||||||
|
|
||||||
def test_create_rating(self):
|
def test_create_rating(self):
|
||||||
"""a remote rating activity"""
|
"""a remote rating activity"""
|
||||||
book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Book", remote_id="https://example.com/book/1"
|
book = models.Edition.objects.create(
|
||||||
)
|
title="Test Book", remote_id="https://example.com/book/1"
|
||||||
|
)
|
||||||
activity = self.create_json
|
activity = self.create_json
|
||||||
activity["object"] = {
|
activity["object"] = {
|
||||||
"id": "https://example.com/user/mouse/reviewrating/12",
|
"id": "https://example.com/user/mouse/reviewrating/12",
|
||||||
|
@ -157,9 +162,12 @@ class InboxCreate(TestCase):
|
||||||
"rating": 3,
|
"rating": 3,
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
}
|
}
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status") as redis_mock:
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
views.inbox.activity_task(activity)
|
with patch(
|
||||||
self.assertTrue(redis_mock.called)
|
"bookwyrm.activitystreams.ActivityStream.add_status"
|
||||||
|
) as redis_mock:
|
||||||
|
views.inbox.activity_task(activity)
|
||||||
|
self.assertTrue(redis_mock.called)
|
||||||
rating = models.ReviewRating.objects.first()
|
rating = models.ReviewRating.objects.first()
|
||||||
self.assertEqual(rating.book, book)
|
self.assertEqual(rating.book, book)
|
||||||
self.assertEqual(rating.rating, 3.0)
|
self.assertEqual(rating.rating, 3.0)
|
||||||
|
|
|
@ -13,25 +13,26 @@ class InboxActivities(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
self.status = models.Status.objects.create(
|
self.status = models.Status.objects.create(
|
||||||
user=self.remote_user,
|
user=self.remote_user,
|
||||||
|
@ -47,7 +48,8 @@ class InboxActivities(TestCase):
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
"object": {},
|
"object": {},
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_delete_status(self):
|
def test_delete_status(self):
|
||||||
"""remove a status"""
|
"""remove a status"""
|
||||||
|
@ -117,7 +119,8 @@ class InboxActivities(TestCase):
|
||||||
"object": self.remote_user.remote_id,
|
"object": self.remote_user.remote_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
views.inbox.activity_task(activity)
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
|
views.inbox.activity_task(activity)
|
||||||
self.assertFalse(models.User.objects.get(username="rat@example.com").is_active)
|
self.assertFalse(models.User.objects.get(username="rat@example.com").is_active)
|
||||||
|
|
||||||
def test_delete_user_unknown(self):
|
def test_delete_user_unknown(self):
|
||||||
|
|
|
@ -13,27 +13,29 @@ class InboxRelationships(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_follow(self):
|
def test_follow(self):
|
||||||
"""remote user wants to follow local user"""
|
"""remote user wants to follow local user"""
|
||||||
|
|
|
@ -12,25 +12,27 @@ class InboxActivities(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
self.status = models.Status.objects.create(
|
self.status = models.Status.objects.create(
|
||||||
|
@ -47,7 +49,9 @@ class InboxActivities(TestCase):
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
"object": {},
|
"object": {},
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_favorite(self):
|
def test_handle_favorite(self):
|
||||||
"""fav a status"""
|
"""fav a status"""
|
||||||
|
|
|
@ -12,33 +12,37 @@ class InboxRemove(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
self.work = models.Work.objects.create(title="work title")
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
self.book = models.Edition.objects.create(
|
self.local_user.save(broadcast=False)
|
||||||
title="Test",
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
remote_id="https://bookwyrm.social/book/37292",
|
self.remote_user = models.User.objects.create_user(
|
||||||
parent_work=self.work,
|
"rat",
|
||||||
)
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.work = models.Work.objects.create(title="work title")
|
||||||
|
self.book = models.Edition.objects.create(
|
||||||
|
title="Test",
|
||||||
|
remote_id="https://bookwyrm.social/book/37292",
|
||||||
|
parent_work=self.work,
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_unshelve_book(self):
|
def test_handle_unshelve_book(self):
|
||||||
"""remove a book from a shelf"""
|
"""remove a book from a shelf"""
|
||||||
|
|
|
@ -14,25 +14,26 @@ class InboxUpdate(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@example.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@example.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
|
||||||
self.local_user.save(broadcast=False)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
self.create_json = {
|
self.create_json = {
|
||||||
"id": "hi",
|
"id": "hi",
|
||||||
|
@ -42,7 +43,8 @@ class InboxUpdate(TestCase):
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
"object": {},
|
"object": {},
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_update_list(self):
|
def test_update_list(self):
|
||||||
"""a new list"""
|
"""a new list"""
|
||||||
|
@ -96,16 +98,18 @@ class InboxUpdate(TestCase):
|
||||||
del userdata["icon"]
|
del userdata["icon"]
|
||||||
self.assertIsNone(self.remote_user.name)
|
self.assertIsNone(self.remote_user.name)
|
||||||
self.assertFalse(self.remote_user.discoverable)
|
self.assertFalse(self.remote_user.discoverable)
|
||||||
views.inbox.activity_task(
|
|
||||||
{
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"type": "Update",
|
views.inbox.activity_task(
|
||||||
"to": [],
|
{
|
||||||
"cc": [],
|
"type": "Update",
|
||||||
"actor": "hi",
|
"to": [],
|
||||||
"id": "sdkjf",
|
"cc": [],
|
||||||
"object": userdata,
|
"actor": "hi",
|
||||||
}
|
"id": "sdkjf",
|
||||||
)
|
"object": userdata,
|
||||||
|
}
|
||||||
|
)
|
||||||
user = models.User.objects.get(id=self.remote_user.id)
|
user = models.User.objects.get(id=self.remote_user.id)
|
||||||
self.assertEqual(user.name, "RAT???")
|
self.assertEqual(user.name, "RAT???")
|
||||||
self.assertEqual(user.username, "rat@example.com")
|
self.assertEqual(user.username, "rat@example.com")
|
||||||
|
@ -120,27 +124,28 @@ class InboxUpdate(TestCase):
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
|
||||||
bookdata = json.loads(datafile.read_bytes())
|
bookdata = json.loads(datafile.read_bytes())
|
||||||
|
|
||||||
models.Work.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Work", remote_id="https://bookwyrm.social/book/5988"
|
models.Work.objects.create(
|
||||||
)
|
title="Test Work", remote_id="https://bookwyrm.social/book/5988"
|
||||||
book = models.Edition.objects.create(
|
|
||||||
title="Test Book", remote_id="https://bookwyrm.social/book/5989"
|
|
||||||
)
|
|
||||||
|
|
||||||
del bookdata["authors"]
|
|
||||||
self.assertEqual(book.title, "Test Book")
|
|
||||||
|
|
||||||
with patch("bookwyrm.activitypub.base_activity.set_related_field.delay"):
|
|
||||||
views.inbox.activity_task(
|
|
||||||
{
|
|
||||||
"type": "Update",
|
|
||||||
"to": [],
|
|
||||||
"cc": [],
|
|
||||||
"actor": "hi",
|
|
||||||
"id": "sdkjf",
|
|
||||||
"object": bookdata,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
book = models.Edition.objects.create(
|
||||||
|
title="Test Book", remote_id="https://bookwyrm.social/book/5989"
|
||||||
|
)
|
||||||
|
|
||||||
|
del bookdata["authors"]
|
||||||
|
self.assertEqual(book.title, "Test Book")
|
||||||
|
|
||||||
|
with patch("bookwyrm.activitypub.base_activity.set_related_field.delay"):
|
||||||
|
views.inbox.activity_task(
|
||||||
|
{
|
||||||
|
"type": "Update",
|
||||||
|
"to": [],
|
||||||
|
"cc": [],
|
||||||
|
"actor": "hi",
|
||||||
|
"id": "sdkjf",
|
||||||
|
"object": bookdata,
|
||||||
|
}
|
||||||
|
)
|
||||||
book = models.Edition.objects.get(id=book.id)
|
book = models.Edition.objects.get(id=book.id)
|
||||||
self.assertEqual(book.title, "Piranesi")
|
self.assertEqual(book.title, "Piranesi")
|
||||||
self.assertEqual(book.last_edited_by, self.remote_user)
|
self.assertEqual(book.last_edited_by, self.remote_user)
|
||||||
|
@ -150,9 +155,10 @@ class InboxUpdate(TestCase):
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
||||||
bookdata = json.loads(datafile.read_bytes())
|
bookdata = json.loads(datafile.read_bytes())
|
||||||
|
|
||||||
book = models.Work.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Book", remote_id="https://bookwyrm.social/book/5988"
|
book = models.Work.objects.create(
|
||||||
)
|
title="Test Book", remote_id="https://bookwyrm.social/book/5988"
|
||||||
|
)
|
||||||
|
|
||||||
del bookdata["authors"]
|
del bookdata["authors"]
|
||||||
self.assertEqual(book.title, "Test Book")
|
self.assertEqual(book.title, "Test Book")
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from bookwyrm import forms, models, views
|
from bookwyrm import forms, models, views
|
||||||
|
|
||||||
|
@ -12,14 +13,16 @@ class AnnouncementViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_announcements_page(self):
|
def test_announcements_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -19,16 +19,18 @@ class AuthenticationViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
self.settings = models.SiteSettings.objects.create(id=1)
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
self.settings = models.SiteSettings.objects.create(id=1)
|
||||||
|
|
||||||
def test_login_get(self):
|
def test_login_get(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
@ -58,8 +60,9 @@ class AuthenticationViews(TestCase):
|
||||||
"email": "aa@bb.cccc",
|
"email": "aa@bb.cccc",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.views.authentication.login"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
response = view(request)
|
with patch("bookwyrm.views.authentication.login"):
|
||||||
|
response = view(request)
|
||||||
self.assertEqual(models.User.objects.count(), 2)
|
self.assertEqual(models.User.objects.count(), 2)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
nutria = models.User.objects.last()
|
nutria = models.User.objects.last()
|
||||||
|
@ -74,8 +77,9 @@ class AuthenticationViews(TestCase):
|
||||||
"register/",
|
"register/",
|
||||||
{"localname": "nutria ", "password": "mouseword", "email": "aa@bb.ccc"},
|
{"localname": "nutria ", "password": "mouseword", "email": "aa@bb.ccc"},
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.views.authentication.login"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
response = view(request)
|
with patch("bookwyrm.views.authentication.login"):
|
||||||
|
response = view(request)
|
||||||
self.assertEqual(models.User.objects.count(), 2)
|
self.assertEqual(models.User.objects.count(), 2)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
nutria = models.User.objects.last()
|
nutria = models.User.objects.last()
|
||||||
|
@ -153,8 +157,9 @@ class AuthenticationViews(TestCase):
|
||||||
"invite_code": "testcode",
|
"invite_code": "testcode",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.views.authentication.login"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
response = view(request)
|
with patch("bookwyrm.views.authentication.login"):
|
||||||
|
response = view(request)
|
||||||
self.assertEqual(models.User.objects.count(), 2)
|
self.assertEqual(models.User.objects.count(), 2)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
self.assertEqual(models.SiteInvite.objects.get().times_used, 1)
|
self.assertEqual(models.SiteInvite.objects.get().times_used, 1)
|
||||||
|
|
|
@ -17,14 +17,15 @@ class AuthorViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
|
)
|
||||||
self.group = Group.objects.create(name="editor")
|
self.group = Group.objects.create(name="editor")
|
||||||
self.group.permissions.add(
|
self.group.permissions.add(
|
||||||
Permission.objects.create(
|
Permission.objects.create(
|
||||||
|
@ -33,13 +34,15 @@ class AuthorViews(TestCase):
|
||||||
content_type=ContentType.objects.get_for_model(models.User),
|
content_type=ContentType.objects.get_for_model(models.User),
|
||||||
).id
|
).id
|
||||||
)
|
)
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=self.work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=self.work,
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_author_page(self):
|
def test_author_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -14,24 +14,26 @@ class BlockViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_block_get(self, _):
|
def test_block_get(self, _):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -23,14 +23,15 @@ class BookViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
|
)
|
||||||
self.group = Group.objects.create(name="editor")
|
self.group = Group.objects.create(name="editor")
|
||||||
self.group.permissions.add(
|
self.group.permissions.add(
|
||||||
Permission.objects.create(
|
Permission.objects.create(
|
||||||
|
@ -39,13 +40,15 @@ class BookViews(TestCase):
|
||||||
content_type=ContentType.objects.get_for_model(models.User),
|
content_type=ContentType.objects.get_for_model(models.User),
|
||||||
).id
|
).id
|
||||||
)
|
)
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=self.work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=self.work,
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_book_page(self):
|
def test_book_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
@ -71,7 +74,8 @@ class BookViews(TestCase):
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
request.user.is_superuser = True
|
request.user.is_superuser = True
|
||||||
result = view(request, self.book.id)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
result = view(request, self.book.id)
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
result.render()
|
result.render()
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
@ -85,8 +89,11 @@ class BookViews(TestCase):
|
||||||
form.data["last_edited_by"] = self.local_user.id
|
form.data["last_edited_by"] = self.local_user.id
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
|
||||||
view(request, self.book.id)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
view(request, self.book.id)
|
||||||
|
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
self.assertEqual(self.book.title, "New Title")
|
self.assertEqual(self.book.title, "New Title")
|
||||||
|
|
||||||
|
@ -101,8 +108,9 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
result = view(request, self.book.id)
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
result.render()
|
result = view(request, self.book.id)
|
||||||
|
result.render()
|
||||||
|
|
||||||
# the changes haven't been saved yet
|
# the changes haven't been saved yet
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
|
@ -120,8 +128,9 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
view(request, self.book.id)
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
view(request, self.book.id)
|
||||||
|
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
self.assertEqual(self.book.title, "New Title")
|
self.assertEqual(self.book.title, "New Title")
|
||||||
|
@ -141,8 +150,9 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
view(request, self.book.id)
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
view(request, self.book.id)
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
self.assertEqual(self.book.title, "New Title")
|
self.assertEqual(self.book.title, "New Title")
|
||||||
self.assertFalse(self.book.authors.exists())
|
self.assertFalse(self.book.authors.exists())
|
||||||
|
@ -157,7 +167,8 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
view(request)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
view(request)
|
||||||
book = models.Edition.objects.get(title="New Title")
|
book = models.Edition.objects.get(title="New Title")
|
||||||
self.assertEqual(book.parent_work.title, "New Title")
|
self.assertEqual(book.parent_work.title, "New Title")
|
||||||
|
|
||||||
|
@ -172,7 +183,8 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
view(request)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
view(request)
|
||||||
book = models.Edition.objects.get(title="New Title")
|
book = models.Edition.objects.get(title="New Title")
|
||||||
self.assertEqual(book.parent_work, self.work)
|
self.assertEqual(book.parent_work, self.work)
|
||||||
|
|
||||||
|
@ -188,7 +200,8 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
view(request)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
view(request)
|
||||||
book = models.Edition.objects.get(title="New Title")
|
book = models.Edition.objects.get(title="New Title")
|
||||||
self.assertEqual(book.parent_work.title, "New Title")
|
self.assertEqual(book.parent_work.title, "New Title")
|
||||||
self.assertEqual(book.authors.first().name, "Sappho")
|
self.assertEqual(book.authors.first().name, "Sappho")
|
||||||
|
@ -197,8 +210,11 @@ class BookViews(TestCase):
|
||||||
def test_switch_edition(self):
|
def test_switch_edition(self):
|
||||||
"""updates user's relationships to a book"""
|
"""updates user's relationships to a book"""
|
||||||
work = models.Work.objects.create(title="test work")
|
work = models.Work.objects.create(title="test work")
|
||||||
edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
edition2 = models.Edition.objects.create(title="second ed", parent_work=work)
|
edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
|
||||||
|
edition2 = models.Edition.objects.create(
|
||||||
|
title="second ed", parent_work=work
|
||||||
|
)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user)
|
shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user)
|
||||||
models.ShelfBook.objects.create(
|
models.ShelfBook.objects.create(
|
||||||
|
@ -251,11 +267,12 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
views.upload_cover(request, self.book.id)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
views.upload_cover(request, self.book.id)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
|
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
self.assertTrue(self.book.cover)
|
self.assertTrue(self.book.cover)
|
||||||
|
@ -283,11 +300,12 @@ class BookViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
views.upload_cover(request, self.book.id)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
views.upload_cover(request, self.book.id)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
|
|
||||||
self.book.refresh_from_db()
|
self.book.refresh_from_db()
|
||||||
self.assertTrue(self.book.cover)
|
self.assertTrue(self.book.cover)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from bookwyrm import models, views
|
from bookwyrm import models, views
|
||||||
|
|
||||||
|
@ -12,24 +13,26 @@ class DirectoryViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com",
|
self.rat = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat@local.com",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=True,
|
"ratword",
|
||||||
localname="rat",
|
local=True,
|
||||||
remote_id="https://example.com/users/rat",
|
localname="rat",
|
||||||
discoverable=True,
|
remote_id="https://example.com/users/rat",
|
||||||
)
|
discoverable=True,
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_directory_page(self):
|
def test_directory_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -21,25 +21,29 @@ class EditUserViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
self.rat = models.User.objects.create_user(
|
||||||
)
|
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
||||||
self.book = models.Edition.objects.create(title="test")
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
|
||||||
models.ShelfBook.objects.create(
|
|
||||||
book=self.book,
|
|
||||||
user=self.local_user,
|
|
||||||
shelf=self.local_user.shelf_set.first(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="test")
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
book=self.book,
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
|
||||||
|
@ -64,11 +68,12 @@ class EditUserViews(TestCase):
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
self.assertIsNone(self.local_user.name)
|
self.assertIsNone(self.local_user.name)
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
view(request)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
view(request)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
self.assertEqual(self.local_user.name, "New Name")
|
self.assertEqual(self.local_user.name, "New Name")
|
||||||
self.assertEqual(self.local_user.email, "wow@email.com")
|
self.assertEqual(self.local_user.email, "wow@email.com")
|
||||||
|
|
||||||
|
@ -88,11 +93,12 @@ class EditUserViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
view(request)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
view(request)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
self.assertEqual(self.local_user.name, "New Name")
|
self.assertEqual(self.local_user.name, "New Name")
|
||||||
self.assertEqual(self.local_user.email, "wow@email.com")
|
self.assertEqual(self.local_user.email, "wow@email.com")
|
||||||
self.assertIsNotNone(self.local_user.avatar)
|
self.assertIsNotNone(self.local_user.avatar)
|
||||||
|
|
|
@ -15,24 +15,26 @@ class FederationViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_federation_page(self):
|
def test_federation_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -22,19 +22,22 @@ class FeedViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.book = models.Edition.objects.create(
|
)
|
||||||
parent_work=models.Work.objects.create(title="hi"),
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
parent_work=models.Work.objects.create(title="hi"),
|
||||||
)
|
title="Example Edition",
|
||||||
models.SiteSettings.objects.create()
|
remote_id="https://example.com/book/1",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_feed(self, *_):
|
def test_feed(self, *_):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
@ -89,11 +92,14 @@ class FeedViews(TestCase):
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
image.save(output, format=image.format)
|
image.save(output, format=image.format)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
status = models.Review.objects.create(
|
with patch(
|
||||||
content="hi",
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
user=self.local_user,
|
):
|
||||||
book=self.book,
|
status = models.Review.objects.create(
|
||||||
)
|
content="hi",
|
||||||
|
user=self.local_user,
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
attachment = models.Image.objects.create(
|
attachment = models.Image.objects.create(
|
||||||
status=status, caption="alt text here"
|
status=status, caption="alt text here"
|
||||||
)
|
)
|
||||||
|
@ -146,12 +152,13 @@ class FeedViews(TestCase):
|
||||||
|
|
||||||
def test_get_suggested_book(self, *_):
|
def test_get_suggested_book(self, *_):
|
||||||
"""gets books the ~*~ algorithm ~*~ thinks you want to post about"""
|
"""gets books the ~*~ algorithm ~*~ thinks you want to post about"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
models.ShelfBook.objects.create(
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
book=self.book,
|
models.ShelfBook.objects.create(
|
||||||
user=self.local_user,
|
book=self.book,
|
||||||
shelf=self.local_user.shelf_set.get(identifier="reading"),
|
user=self.local_user,
|
||||||
)
|
shelf=self.local_user.shelf_set.get(identifier="reading"),
|
||||||
|
)
|
||||||
suggestions = views.feed.get_suggested_books(self.local_user)
|
suggestions = views.feed.get_suggested_books(self.local_user)
|
||||||
self.assertEqual(suggestions[0]["name"], "Currently Reading")
|
self.assertEqual(suggestions[0]["name"], "Currently Reading")
|
||||||
self.assertEqual(suggestions[0]["books"][0], self.book)
|
self.assertEqual(suggestions[0]["books"][0], self.book)
|
||||||
|
|
|
@ -16,24 +16,25 @@ class BookViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@email.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@email.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
self.group = Group.objects.create(name="editor")
|
self.group = Group.objects.create(name="editor")
|
||||||
self.group.permissions.add(
|
self.group.permissions.add(
|
||||||
Permission.objects.create(
|
Permission.objects.create(
|
||||||
|
@ -42,12 +43,13 @@ class BookViews(TestCase):
|
||||||
content_type=ContentType.objects.get_for_model(models.User),
|
content_type=ContentType.objects.get_for_model(models.User),
|
||||||
).id
|
).id
|
||||||
)
|
)
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=self.work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=self.work,
|
||||||
|
)
|
||||||
|
|
||||||
def test_handle_follow_remote(self):
|
def test_handle_follow_remote(self):
|
||||||
"""send a follow request"""
|
"""send a follow request"""
|
||||||
|
@ -66,15 +68,16 @@ class BookViews(TestCase):
|
||||||
|
|
||||||
def test_handle_follow_local_manually_approves(self):
|
def test_handle_follow_local_manually_approves(self):
|
||||||
"""send a follow request"""
|
"""send a follow request"""
|
||||||
rat = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat@local.com",
|
rat = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat@local.com",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=True,
|
"ratword",
|
||||||
localname="rat",
|
local=True,
|
||||||
remote_id="https://example.com/users/rat",
|
localname="rat",
|
||||||
manually_approves_followers=True,
|
remote_id="https://example.com/users/rat",
|
||||||
)
|
manually_approves_followers=True,
|
||||||
|
)
|
||||||
request = self.factory.post("", {"user": rat})
|
request = self.factory.post("", {"user": rat})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
||||||
|
@ -89,14 +92,15 @@ class BookViews(TestCase):
|
||||||
|
|
||||||
def test_handle_follow_local(self):
|
def test_handle_follow_local(self):
|
||||||
"""send a follow request"""
|
"""send a follow request"""
|
||||||
rat = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat@local.com",
|
rat = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat@local.com",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=True,
|
"ratword",
|
||||||
localname="rat",
|
local=True,
|
||||||
remote_id="https://example.com/users/rat",
|
localname="rat",
|
||||||
)
|
remote_id="https://example.com/users/rat",
|
||||||
|
)
|
||||||
request = self.factory.post("", {"user": rat})
|
request = self.factory.post("", {"user": rat})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
|
||||||
|
|
|
@ -13,22 +13,25 @@ class GetStartedViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.book = models.Edition.objects.create(
|
)
|
||||||
parent_work=models.Work.objects.create(title="hi"),
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
parent_work=models.Work.objects.create(title="hi"),
|
||||||
)
|
title="Example Edition",
|
||||||
|
remote_id="https://example.com/book/1",
|
||||||
|
)
|
||||||
models.Connector.objects.create(
|
models.Connector.objects.create(
|
||||||
identifier="self", connector_file="self_connector", local=True
|
identifier="self", connector_file="self_connector", local=True
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_profile_view(self):
|
def test_profile_view(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
@ -52,11 +55,12 @@ class GetStartedViews(TestCase):
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
self.assertIsNone(self.local_user.name)
|
self.assertIsNone(self.local_user.name)
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
view(request)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
view(request)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
self.assertEqual(self.local_user.name, "New Name")
|
self.assertEqual(self.local_user.name, "New Name")
|
||||||
self.assertTrue(self.local_user.discoverable)
|
self.assertTrue(self.local_user.discoverable)
|
||||||
|
|
||||||
|
|
|
@ -16,29 +16,32 @@ class GoalViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com",
|
self.rat = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat@local.com",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=True,
|
"ratword",
|
||||||
localname="rat",
|
local=True,
|
||||||
remote_id="https://example.com/users/rat",
|
localname="rat",
|
||||||
)
|
remote_id="https://example.com/users/rat",
|
||||||
self.book = models.Edition.objects.create(
|
)
|
||||||
title="Example Edition",
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
remote_id="https://example.com/book/1",
|
self.book = models.Edition.objects.create(
|
||||||
)
|
title="Example Edition",
|
||||||
|
remote_id="https://example.com/book/1",
|
||||||
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_goal_page_no_goal(self):
|
def test_goal_page_no_goal(self):
|
||||||
"""view a reading goal page for another's unset goal"""
|
"""view a reading goal page for another's unset goal"""
|
||||||
|
|
|
@ -19,31 +19,33 @@ class ViewsHelpers(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
discoverable=True,
|
local=True,
|
||||||
localname="mouse",
|
|
||||||
remote_id="https://example.com/users/mouse",
|
|
||||||
)
|
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
|
||||||
self.book = models.Edition.objects.create(
|
|
||||||
title="Test Book",
|
|
||||||
remote_id="https://example.com/book/1",
|
|
||||||
parent_work=self.work,
|
|
||||||
)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@rat.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
discoverable=True,
|
discoverable=True,
|
||||||
inbox="https://example.com/users/rat/inbox",
|
localname="mouse",
|
||||||
outbox="https://example.com/users/rat/outbox",
|
remote_id="https://example.com/users/mouse",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
discoverable=True,
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
|
self.book = models.Edition.objects.create(
|
||||||
|
title="Test Book",
|
||||||
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=self.work,
|
||||||
)
|
)
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||||
self.userdata = json.loads(datafile.read_bytes())
|
self.userdata = json.loads(datafile.read_bytes())
|
||||||
|
@ -142,10 +144,11 @@ class ViewsHelpers(TestCase):
|
||||||
json=self.userdata,
|
json=self.userdata,
|
||||||
status=200,
|
status=200,
|
||||||
)
|
)
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
result = views.helpers.handle_remote_webfinger("@mouse@example.com")
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
self.assertIsInstance(result, models.User)
|
result = views.helpers.handle_remote_webfinger("@mouse@example.com")
|
||||||
self.assertEqual(result.username, "mouse@example.com")
|
self.assertIsInstance(result, models.User)
|
||||||
|
self.assertEqual(result.username, "mouse@example.com")
|
||||||
|
|
||||||
def test_user_on_blocked_server(self, _):
|
def test_user_on_blocked_server(self, _):
|
||||||
"""find a remote user using webfinger"""
|
"""find a remote user using webfinger"""
|
||||||
|
@ -202,21 +205,22 @@ class ViewsHelpers(TestCase):
|
||||||
|
|
||||||
def test_get_annotated_users(self, _):
|
def test_get_annotated_users(self, _):
|
||||||
"""list of people you might know"""
|
"""list of people you might know"""
|
||||||
user_1 = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"nutria@local.com",
|
user_1 = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria@local.com",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
local=True,
|
"nutriaword",
|
||||||
localname="nutria",
|
local=True,
|
||||||
discoverable=True,
|
localname="nutria",
|
||||||
)
|
discoverable=True,
|
||||||
user_2 = models.User.objects.create_user(
|
)
|
||||||
"fish@local.com",
|
user_2 = models.User.objects.create_user(
|
||||||
"fish@fish.com",
|
"fish@local.com",
|
||||||
"fishword",
|
"fish@fish.com",
|
||||||
local=True,
|
"fishword",
|
||||||
localname="fish",
|
local=True,
|
||||||
)
|
localname="fish",
|
||||||
|
)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
# 1 shared follow
|
# 1 shared follow
|
||||||
self.local_user.following.add(user_2)
|
self.local_user.following.add(user_2)
|
||||||
|
@ -249,39 +253,42 @@ class ViewsHelpers(TestCase):
|
||||||
|
|
||||||
def test_get_annotated_users_counts(self, _):
|
def test_get_annotated_users_counts(self, _):
|
||||||
"""correct counting for multiple shared attributed"""
|
"""correct counting for multiple shared attributed"""
|
||||||
user_1 = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"nutria@local.com",
|
user_1 = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria@local.com",
|
||||||
"nutriaword",
|
"nutria@nutria.com",
|
||||||
local=True,
|
"nutriaword",
|
||||||
localname="nutria",
|
|
||||||
discoverable=True,
|
|
||||||
)
|
|
||||||
for i in range(3):
|
|
||||||
user = models.User.objects.create_user(
|
|
||||||
"{:d}@local.com".format(i),
|
|
||||||
"{:d}@nutria.com".format(i),
|
|
||||||
"password",
|
|
||||||
local=True,
|
local=True,
|
||||||
localname=i,
|
localname="nutria",
|
||||||
|
discoverable=True,
|
||||||
)
|
)
|
||||||
user.following.add(user_1)
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
user.followers.add(self.local_user)
|
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
book = models.Edition.objects.create(
|
user = models.User.objects.create_user(
|
||||||
title=i,
|
"{:d}@local.com".format(i),
|
||||||
parent_work=models.Work.objects.create(title=i),
|
"{:d}@nutria.com".format(i),
|
||||||
)
|
"password",
|
||||||
models.ShelfBook.objects.create(
|
local=True,
|
||||||
user=self.local_user,
|
localname=i,
|
||||||
book=book,
|
|
||||||
shelf=self.local_user.shelf_set.first(),
|
|
||||||
)
|
|
||||||
models.ShelfBook.objects.create(
|
|
||||||
user=user_1, book=book, shelf=user_1.shelf_set.first()
|
|
||||||
)
|
)
|
||||||
|
user.following.add(user_1)
|
||||||
|
user.followers.add(self.local_user)
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
for i in range(3):
|
||||||
|
book = models.Edition.objects.create(
|
||||||
|
title=i,
|
||||||
|
parent_work=models.Work.objects.create(title=i),
|
||||||
|
)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
book=book,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=user_1, book=book, shelf=user_1.shelf_set.first()
|
||||||
|
)
|
||||||
|
|
||||||
result = views.helpers.get_annotated_users(
|
result = views.helpers.get_annotated_users(
|
||||||
self.local_user,
|
self.local_user,
|
||||||
|
|
|
@ -14,14 +14,16 @@ class ImportViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_import_page(self):
|
def test_import_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -15,31 +15,33 @@ class InteractionViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@email.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@email.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=work,
|
||||||
|
)
|
||||||
|
|
||||||
def test_favorite(self, *_):
|
def test_favorite(self, *_):
|
||||||
"""create and broadcast faving a status"""
|
"""create and broadcast faving a status"""
|
||||||
|
|
|
@ -16,14 +16,16 @@ class InviteViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_invite_page(self):
|
def test_invite_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -16,25 +16,28 @@ class IsbnViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Book",
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
isbn_13="1234567890123",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Test Book",
|
||||||
parent_work=self.work,
|
isbn_13="1234567890123",
|
||||||
)
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=self.work,
|
||||||
|
)
|
||||||
models.Connector.objects.create(
|
models.Connector.objects.create(
|
||||||
identifier="self", connector_file="self_connector", local=True
|
identifier="self", connector_file="self_connector", local=True
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_isbn_json_response(self):
|
def test_isbn_json_response(self):
|
||||||
"""searches local data only and returns book data in json format"""
|
"""searches local data only and returns book data in json format"""
|
||||||
|
|
|
@ -15,16 +15,18 @@ class LandingViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_home_page(self):
|
def test_home_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -17,46 +17,48 @@ class ListViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com",
|
self.rat = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat@local.com",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=True,
|
"ratword",
|
||||||
localname="rat",
|
local=True,
|
||||||
remote_id="https://example.com/users/rat",
|
localname="rat",
|
||||||
)
|
remote_id="https://example.com/users/rat",
|
||||||
work = models.Work.objects.create(title="Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Edition",
|
work = models.Work.objects.create(title="Work")
|
||||||
remote_id="https://example.com/book/1",
|
self.book = models.Edition.objects.create(
|
||||||
parent_work=work,
|
title="Example Edition",
|
||||||
)
|
remote_id="https://example.com/book/1",
|
||||||
work_two = models.Work.objects.create(title="Labori")
|
parent_work=work,
|
||||||
self.book_two = models.Edition.objects.create(
|
)
|
||||||
title="Example Edition 2",
|
work_two = models.Work.objects.create(title="Labori")
|
||||||
remote_id="https://example.com/book/2",
|
self.book_two = models.Edition.objects.create(
|
||||||
parent_work=work_two,
|
title="Example Edition 2",
|
||||||
)
|
remote_id="https://example.com/book/2",
|
||||||
work_three = models.Work.objects.create(title="Trabajar")
|
parent_work=work_two,
|
||||||
self.book_three = models.Edition.objects.create(
|
)
|
||||||
title="Example Edition 3",
|
work_three = models.Work.objects.create(title="Trabajar")
|
||||||
remote_id="https://example.com/book/3",
|
self.book_three = models.Edition.objects.create(
|
||||||
parent_work=work_three,
|
title="Example Edition 3",
|
||||||
)
|
remote_id="https://example.com/book/3",
|
||||||
work_four = models.Work.objects.create(title="Travailler")
|
parent_work=work_three,
|
||||||
self.book_four = models.Edition.objects.create(
|
)
|
||||||
title="Example Edition 4",
|
work_four = models.Work.objects.create(title="Travailler")
|
||||||
remote_id="https://example.com/book/4",
|
self.book_four = models.Edition.objects.create(
|
||||||
parent_work=work_four,
|
title="Example Edition 4",
|
||||||
)
|
remote_id="https://example.com/book/4",
|
||||||
|
parent_work=work_four,
|
||||||
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.list = models.List.objects.create(
|
self.list = models.List.objects.create(
|
||||||
|
@ -64,7 +66,8 @@ class ListViews(TestCase):
|
||||||
)
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_lists_page(self):
|
def test_lists_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -15,46 +15,49 @@ class ListActionViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com",
|
self.rat = models.User.objects.create_user(
|
||||||
"rat@rat.com",
|
"rat@local.com",
|
||||||
"ratword",
|
"rat@rat.com",
|
||||||
local=True,
|
"ratword",
|
||||||
localname="rat",
|
local=True,
|
||||||
remote_id="https://example.com/users/rat",
|
localname="rat",
|
||||||
)
|
remote_id="https://example.com/users/rat",
|
||||||
work = models.Work.objects.create(title="Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
|
||||||
title="Example Edition",
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
remote_id="https://example.com/book/1",
|
work = models.Work.objects.create(title="Work")
|
||||||
parent_work=work,
|
self.book = models.Edition.objects.create(
|
||||||
)
|
title="Example Edition",
|
||||||
work_two = models.Work.objects.create(title="Labori")
|
remote_id="https://example.com/book/1",
|
||||||
self.book_two = models.Edition.objects.create(
|
parent_work=work,
|
||||||
title="Example Edition 2",
|
)
|
||||||
remote_id="https://example.com/book/2",
|
work_two = models.Work.objects.create(title="Labori")
|
||||||
parent_work=work_two,
|
self.book_two = models.Edition.objects.create(
|
||||||
)
|
title="Example Edition 2",
|
||||||
work_three = models.Work.objects.create(title="Trabajar")
|
remote_id="https://example.com/book/2",
|
||||||
self.book_three = models.Edition.objects.create(
|
parent_work=work_two,
|
||||||
title="Example Edition 3",
|
)
|
||||||
remote_id="https://example.com/book/3",
|
work_three = models.Work.objects.create(title="Trabajar")
|
||||||
parent_work=work_three,
|
self.book_three = models.Edition.objects.create(
|
||||||
)
|
title="Example Edition 3",
|
||||||
work_four = models.Work.objects.create(title="Travailler")
|
remote_id="https://example.com/book/3",
|
||||||
self.book_four = models.Edition.objects.create(
|
parent_work=work_three,
|
||||||
title="Example Edition 4",
|
)
|
||||||
remote_id="https://example.com/book/4",
|
work_four = models.Work.objects.create(title="Travailler")
|
||||||
parent_work=work_four,
|
self.book_four = models.Edition.objects.create(
|
||||||
)
|
title="Example Edition 4",
|
||||||
|
remote_id="https://example.com/book/4",
|
||||||
|
parent_work=work_four,
|
||||||
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.list = models.List.objects.create(
|
self.list = models.List.objects.create(
|
||||||
|
@ -62,7 +65,8 @@ class ListActionViews(TestCase):
|
||||||
)
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_curate_approve(self):
|
def test_curate_approve(self):
|
||||||
"""approve a pending item"""
|
"""approve a pending item"""
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
from bookwyrm import views
|
from bookwyrm import views
|
||||||
|
@ -13,14 +14,16 @@ class NotificationViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_notifications_page(self):
|
def test_notifications_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -18,20 +18,22 @@ class OutboxView(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we'll need some data"""
|
"""we'll need some data"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
work = models.Work.objects.create(title="Test Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Edition",
|
work = models.Work.objects.create(title="Test Work")
|
||||||
remote_id="https://example.com/book/1",
|
self.book = models.Edition.objects.create(
|
||||||
parent_work=work,
|
title="Example Edition",
|
||||||
)
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=work,
|
||||||
|
)
|
||||||
|
|
||||||
def test_outbox(self, _):
|
def test_outbox(self, _):
|
||||||
"""returns user's statuses"""
|
"""returns user's statuses"""
|
||||||
|
@ -79,13 +81,16 @@ class OutboxView(TestCase):
|
||||||
def test_outbox_filter(self, _):
|
def test_outbox_filter(self, _):
|
||||||
"""if we only care about reviews, only get reviews"""
|
"""if we only care about reviews, only get reviews"""
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
models.Review.objects.create(
|
with patch(
|
||||||
content="look at this",
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
name="hi",
|
):
|
||||||
rating=1,
|
models.Review.objects.create(
|
||||||
book=self.book,
|
content="look at this",
|
||||||
user=self.local_user,
|
name="hi",
|
||||||
)
|
rating=1,
|
||||||
|
book=self.book,
|
||||||
|
user=self.local_user,
|
||||||
|
)
|
||||||
models.Status.objects.create(content="look at this", user=self.local_user)
|
models.Status.objects.create(content="look at this", user=self.local_user)
|
||||||
|
|
||||||
request = self.factory.get("", {"type": "bleh"})
|
request = self.factory.get("", {"type": "bleh"})
|
||||||
|
@ -105,13 +110,16 @@ class OutboxView(TestCase):
|
||||||
def test_outbox_bookwyrm_request_true(self, _):
|
def test_outbox_bookwyrm_request_true(self, _):
|
||||||
"""should differentiate between bookwyrm and outside requests"""
|
"""should differentiate between bookwyrm and outside requests"""
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
models.Review.objects.create(
|
with patch(
|
||||||
name="hi",
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
content="look at this",
|
):
|
||||||
user=self.local_user,
|
models.Review.objects.create(
|
||||||
book=self.book,
|
name="hi",
|
||||||
privacy="public",
|
content="look at this",
|
||||||
)
|
user=self.local_user,
|
||||||
|
book=self.book,
|
||||||
|
privacy="public",
|
||||||
|
)
|
||||||
|
|
||||||
request = self.factory.get("", {"page": 1}, HTTP_USER_AGENT=USER_AGENT)
|
request = self.factory.get("", {"page": 1}, HTTP_USER_AGENT=USER_AGENT)
|
||||||
result = views.Outbox.as_view()(request, "mouse")
|
result = views.Outbox.as_view()(request, "mouse")
|
||||||
|
@ -123,13 +131,16 @@ class OutboxView(TestCase):
|
||||||
def test_outbox_bookwyrm_request_false(self, _):
|
def test_outbox_bookwyrm_request_false(self, _):
|
||||||
"""should differentiate between bookwyrm and outside requests"""
|
"""should differentiate between bookwyrm and outside requests"""
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
models.Review.objects.create(
|
with patch(
|
||||||
name="hi",
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
content="look at this",
|
):
|
||||||
user=self.local_user,
|
models.Review.objects.create(
|
||||||
book=self.book,
|
name="hi",
|
||||||
privacy="public",
|
content="look at this",
|
||||||
)
|
user=self.local_user,
|
||||||
|
book=self.book,
|
||||||
|
privacy="public",
|
||||||
|
)
|
||||||
|
|
||||||
request = self.factory.get("", {"page": 1})
|
request = self.factory.get("", {"page": 1})
|
||||||
result = views.Outbox.as_view()(request, "mouse")
|
result = views.Outbox.as_view()(request, "mouse")
|
||||||
|
|
|
@ -15,16 +15,18 @@ class PasswordViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
models.SiteSettings.objects.create(id=1)
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create(id=1)
|
||||||
|
|
||||||
def test_password_reset_request(self):
|
def test_password_reset_request(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -15,29 +15,31 @@ class ReadingViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
title="Test Book",
|
self.remote_user = models.User.objects.create_user(
|
||||||
remote_id="https://example.com/book/1",
|
"rat",
|
||||||
parent_work=self.work,
|
"rat@rat.com",
|
||||||
)
|
"ratword",
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
local=False,
|
||||||
self.remote_user = models.User.objects.create_user(
|
remote_id="https://example.com/users/rat",
|
||||||
"rat",
|
inbox="https://example.com/users/rat/inbox",
|
||||||
"rat@rat.com",
|
outbox="https://example.com/users/rat/outbox",
|
||||||
"ratword",
|
)
|
||||||
local=False,
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
remote_id="https://example.com/users/rat",
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
inbox="https://example.com/users/rat/inbox",
|
self.book = models.Edition.objects.create(
|
||||||
outbox="https://example.com/users/rat/outbox",
|
title="Test Book",
|
||||||
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=self.work,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_start_reading(self, _):
|
def test_start_reading(self, _):
|
||||||
|
|
|
@ -15,15 +15,17 @@ class ReadThrough(TestCase):
|
||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
self.client = Client()
|
self.client = Client()
|
||||||
|
|
||||||
self.work = models.Work.objects.create(title="Example Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.work = models.Work.objects.create(title="Example Work")
|
||||||
|
|
||||||
self.edition = models.Edition.objects.create(
|
self.edition = models.Edition.objects.create(
|
||||||
title="Example Edition", parent_work=self.work
|
title="Example Edition", parent_work=self.work
|
||||||
)
|
)
|
||||||
|
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
|
self.user = models.User.objects.create_user(
|
||||||
)
|
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
|
||||||
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from bookwyrm import forms, models, views
|
from bookwyrm import forms, models, views
|
||||||
|
|
||||||
|
@ -12,21 +13,23 @@ class ReportViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com",
|
self.rat = models.User.objects.create_user(
|
||||||
"rat@mouse.mouse",
|
"rat@local.com",
|
||||||
"password",
|
"rat@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="rat",
|
local=True,
|
||||||
)
|
localname="rat",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_reports_page(self):
|
def test_reports_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -12,39 +12,45 @@ class RssFeedView(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""test data"""
|
"""test data"""
|
||||||
self.site = models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
self.site = models.SiteSettings.objects.create()
|
||||||
|
|
||||||
self.user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rss_user", "rss@test.rss", "password", local=True
|
self.user = models.User.objects.create_user(
|
||||||
)
|
"rss_user", "rss@test.rss", "password", local=True
|
||||||
|
)
|
||||||
|
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=work,
|
||||||
|
)
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
self.review = models.Review.objects.create(
|
with patch(
|
||||||
name="Review name",
|
"bookwyrm.preview_images.generate_edition_preview_image_task.delay"
|
||||||
content="test content",
|
):
|
||||||
rating=3,
|
self.review = models.Review.objects.create(
|
||||||
user=self.user,
|
name="Review name",
|
||||||
book=self.book,
|
content="test content",
|
||||||
)
|
rating=3,
|
||||||
|
user=self.user,
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
|
||||||
self.quote = models.Quotation.objects.create(
|
self.quote = models.Quotation.objects.create(
|
||||||
quote="a sickening sense",
|
quote="a sickening sense",
|
||||||
content="test content",
|
content="test content",
|
||||||
user=self.user,
|
user=self.user,
|
||||||
book=self.book,
|
book=self.book,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.generatednote = models.GeneratedNote.objects.create(
|
self.generatednote = models.GeneratedNote.objects.create(
|
||||||
content="test content", user=self.user
|
content="test content", user=self.user
|
||||||
)
|
)
|
||||||
|
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
|
|
|
@ -19,24 +19,27 @@ class Views(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Test Book",
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
remote_id="https://example.com/book/1",
|
self.book = models.Edition.objects.create(
|
||||||
parent_work=self.work,
|
title="Test Book",
|
||||||
)
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=self.work,
|
||||||
|
)
|
||||||
models.Connector.objects.create(
|
models.Connector.objects.create(
|
||||||
identifier="self", connector_file="self_connector", local=True
|
identifier="self", connector_file="self_connector", local=True
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_search_json_response(self):
|
def test_search_json_response(self):
|
||||||
"""searches local data only and returns book data in json format"""
|
"""searches local data only and returns book data in json format"""
|
||||||
|
|
|
@ -16,25 +16,28 @@ class ShelfViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
self.work = models.Work.objects.create(title="Test Work")
|
)
|
||||||
self.book = models.Edition.objects.create(
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
title="Example Edition",
|
self.work = models.Work.objects.create(title="Test Work")
|
||||||
remote_id="https://example.com/book/1",
|
self.book = models.Edition.objects.create(
|
||||||
parent_work=self.work,
|
title="Example Edition",
|
||||||
)
|
remote_id="https://example.com/book/1",
|
||||||
|
parent_work=self.work,
|
||||||
|
)
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
self.shelf = models.Shelf.objects.create(
|
self.shelf = models.Shelf.objects.create(
|
||||||
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_shelf_page(self, _):
|
def test_shelf_page(self, _):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -15,32 +15,35 @@ class StatusViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.com",
|
"mouse@local.com",
|
||||||
"mouseword",
|
"mouse@mouse.com",
|
||||||
local=True,
|
"mouseword",
|
||||||
localname="mouse",
|
local=True,
|
||||||
remote_id="https://example.com/users/mouse",
|
localname="mouse",
|
||||||
)
|
remote_id="https://example.com/users/mouse",
|
||||||
with patch("bookwyrm.models.user.set_remote_server"):
|
|
||||||
self.remote_user = models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@email.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@email.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
work = models.Work.objects.create(title="Test Work")
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
self.book = models.Edition.objects.create(
|
work = models.Work.objects.create(title="Test Work")
|
||||||
title="Example Edition",
|
self.book = models.Edition.objects.create(
|
||||||
remote_id="https://example.com/book/1",
|
title="Example Edition",
|
||||||
parent_work=work,
|
remote_id="https://example.com/book/1",
|
||||||
)
|
parent_work=work,
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_status(self, _):
|
def test_handle_status(self, _):
|
||||||
"""create a status"""
|
"""create a status"""
|
||||||
|
@ -68,9 +71,10 @@ class StatusViews(TestCase):
|
||||||
def test_handle_status_reply(self, _):
|
def test_handle_status_reply(self, _):
|
||||||
"""create a status in reply to an existing status"""
|
"""create a status in reply to an existing status"""
|
||||||
view = views.CreateStatus.as_view()
|
view = views.CreateStatus.as_view()
|
||||||
user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat", "rat@rat.com", "password", local=True
|
user = models.User.objects.create_user(
|
||||||
)
|
"rat", "rat@rat.com", "password", local=True
|
||||||
|
)
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
parent = models.Status.objects.create(
|
parent = models.Status.objects.create(
|
||||||
content="parent status", user=self.local_user
|
content="parent status", user=self.local_user
|
||||||
|
@ -98,9 +102,14 @@ class StatusViews(TestCase):
|
||||||
def test_handle_status_mentions(self, _):
|
def test_handle_status_mentions(self, _):
|
||||||
"""@mention a user in a post"""
|
"""@mention a user in a post"""
|
||||||
view = views.CreateStatus.as_view()
|
view = views.CreateStatus.as_view()
|
||||||
user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat@%s" % DOMAIN, "rat@rat.com", "password", local=True, localname="rat"
|
user = models.User.objects.create_user(
|
||||||
)
|
"rat@%s" % DOMAIN,
|
||||||
|
"rat@rat.com",
|
||||||
|
"password",
|
||||||
|
local=True,
|
||||||
|
localname="rat",
|
||||||
|
)
|
||||||
form = forms.CommentForm(
|
form = forms.CommentForm(
|
||||||
{
|
{
|
||||||
"content": "hi @rat",
|
"content": "hi @rat",
|
||||||
|
@ -126,9 +135,10 @@ class StatusViews(TestCase):
|
||||||
def test_handle_status_reply_with_mentions(self, _):
|
def test_handle_status_reply_with_mentions(self, _):
|
||||||
"""reply to a post with an @mention'ed user"""
|
"""reply to a post with an @mention'ed user"""
|
||||||
view = views.CreateStatus.as_view()
|
view = views.CreateStatus.as_view()
|
||||||
user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"rat", "rat@rat.com", "password", local=True, localname="rat"
|
user = models.User.objects.create_user(
|
||||||
)
|
"rat", "rat@rat.com", "password", local=True, localname="rat"
|
||||||
|
)
|
||||||
form = forms.CommentForm(
|
form = forms.CommentForm(
|
||||||
{
|
{
|
||||||
"content": "hi @rat@example.com",
|
"content": "hi @rat@example.com",
|
||||||
|
@ -193,10 +203,11 @@ class StatusViews(TestCase):
|
||||||
view = views.DeleteAndRedraft.as_view()
|
view = views.DeleteAndRedraft.as_view()
|
||||||
request = self.factory.post("")
|
request = self.factory.post("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
status = models.ReviewRating.objects.create(
|
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
|
||||||
book=self.book, rating=2.0, user=self.local_user
|
status = models.ReviewRating.objects.create(
|
||||||
)
|
book=self.book, rating=2.0, user=self.local_user
|
||||||
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||||
|
@ -230,13 +241,14 @@ class StatusViews(TestCase):
|
||||||
|
|
||||||
def test_find_mentions(self, _):
|
def test_find_mentions(self, _):
|
||||||
"""detect and look up @ mentions of users"""
|
"""detect and look up @ mentions of users"""
|
||||||
user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"nutria@%s" % DOMAIN,
|
user = models.User.objects.create_user(
|
||||||
"nutria@nutria.com",
|
"nutria@%s" % DOMAIN,
|
||||||
"password",
|
"nutria@nutria.com",
|
||||||
local=True,
|
"password",
|
||||||
localname="nutria",
|
local=True,
|
||||||
)
|
localname="nutria",
|
||||||
|
)
|
||||||
self.assertEqual(user.username, "nutria@%s" % DOMAIN)
|
self.assertEqual(user.username, "nutria@%s" % DOMAIN)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
|
@ -14,15 +14,17 @@ class UpdateViews(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.factory = RequestFactory()
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_get_notification_count(self):
|
def test_get_notification_count(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -16,18 +16,20 @@ class UserViews(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.factory = RequestFactory()
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
self.rat = models.User.objects.create_user(
|
||||||
)
|
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
||||||
self.book = models.Edition.objects.create(title="test")
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="test")
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
models.ShelfBook.objects.create(
|
models.ShelfBook.objects.create(
|
||||||
book=self.book,
|
book=self.book,
|
||||||
|
@ -35,7 +37,8 @@ class UserViews(TestCase):
|
||||||
shelf=self.local_user.shelf_set.first(),
|
shelf=self.local_user.shelf_set.first(),
|
||||||
)
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,16 @@ class UserAdminViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.SiteSettings.objects.create()
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_user_admin_list_page(self):
|
def test_user_admin_list_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
|
|
@ -15,28 +15,30 @@ class UserViews(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.factory = RequestFactory()
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
models.User.objects.create_user(
|
|
||||||
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
|
||||||
)
|
|
||||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
||||||
models.User.objects.create_user(
|
|
||||||
"rat",
|
|
||||||
"rat@remote.com",
|
|
||||||
"ratword",
|
|
||||||
local=False,
|
|
||||||
remote_id="https://example.com/users/rat",
|
|
||||||
inbox="https://example.com/users/rat/inbox",
|
|
||||||
outbox="https://example.com/users/rat/outbox",
|
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
models.User.objects.create_user(
|
||||||
|
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@remote.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
|
||||||
|
|
5
bw-dev
5
bw-dev
|
@ -107,7 +107,10 @@ case "$CMD" in
|
||||||
populate_streams)
|
populate_streams)
|
||||||
runweb python manage.py populate_streams
|
runweb python manage.py populate_streams
|
||||||
;;
|
;;
|
||||||
|
generate_preview_images)
|
||||||
|
runweb python manage.py generate_preview_images $@
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unrecognised command. Try: build, clean, up, initdb, resetdb, makemigrations, migrate, bash, shell, dbshell, restart_celery, test, pytest, test_report, black, populate_feeds"
|
echo "Unrecognised command. Try: build, clean, up, initdb, resetdb, makemigrations, migrate, bash, shell, dbshell, restart_celery, test, pytest, test_report, black, populate_feeds, generate_preview_images"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -24,5 +24,6 @@ app.autodiscover_tasks(["bookwyrm"], related_name="broadcast")
|
||||||
app.autodiscover_tasks(["bookwyrm"], related_name="connectors.abstract_connector")
|
app.autodiscover_tasks(["bookwyrm"], related_name="connectors.abstract_connector")
|
||||||
app.autodiscover_tasks(["bookwyrm"], related_name="emailing")
|
app.autodiscover_tasks(["bookwyrm"], related_name="emailing")
|
||||||
app.autodiscover_tasks(["bookwyrm"], related_name="goodreads_import")
|
app.autodiscover_tasks(["bookwyrm"], related_name="goodreads_import")
|
||||||
|
app.autodiscover_tasks(["bookwyrm"], related_name="preview_images")
|
||||||
app.autodiscover_tasks(["bookwyrm"], related_name="models.user")
|
app.autodiscover_tasks(["bookwyrm"], related_name="models.user")
|
||||||
app.autodiscover_tasks(["bookwyrm"], related_name="views.inbox")
|
app.autodiscover_tasks(["bookwyrm"], related_name="views.inbox")
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue