diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 2849f00cb..11854dff7 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -18,6 +18,7 @@ from django.utils.translation import gettext_lazy as _ from bookwyrm import activitypub from bookwyrm.connectors import get_image from bookwyrm.sanitize_html import InputHtmlParser +from bookwyrm.settings import DOMAIN def validate_remote_id(value): @@ -356,6 +357,8 @@ def image_serializer(value, alt): else: return None url = static(url) + if not url[:4] == "http": + url = "https://{:s}{:s}".format(DOMAIN, url) return activitypub.Document(url=url, name=alt) diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index bf907bf40..65f9a1cc2 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -17,7 +17,7 @@ from django.db import models from django.test import TestCase from django.utils import timezone -from bookwyrm import activitypub +from bookwyrm import activitypub, settings from bookwyrm.activitypub.base_activity import ActivityObject from bookwyrm.models import fields, User, Status from bookwyrm.models.base_model import BookWyrmModel @@ -428,13 +428,11 @@ class ActivitypubFields(TestCase): def test_image_serialize(self): """make sure we're creating sensible image paths""" - ValueMock = namedtuple( - "ValueMock", ("url") - ) + ValueMock = namedtuple("ValueMock", ("url")) value_mock = ValueMock("images/fish.jpg") result = fields.image_serializer(value_mock, "hello") self.assertEqual(result.type, "Document") - self.assertEqual(result.url, "https://test.com/images/fish.jpg") + self.assertEqual(result.url, "https://your.domain.here/static/images/fish.jpg") self.assertEqual(result.name, "hello") def test_datetime_field(self): diff --git a/pytest.ini b/pytest.ini index fa9dbc59f..8539d1167 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,3 +4,19 @@ python_files = tests.py test_*.py *_tests.py addopts = --cov=bookwyrm --cov-config=.coveragerc markers = integration: marks tests as requiring external resources (deselect with '-m "not integration"') + +env = + DEBUG = false + DOMAIN = your.domain.here + BOOKWYRM_DATABASE_BACKEND = postgres + MEDIA_ROOT = images/ + CELERY_BROKER = "" + REDIS_BROKER_PORT = 6379 + FLOWER_PORT = 8888 + EMAIL_HOST = "smtp.mailgun.org" + EMAIL_PORT = 587 + EMAIL_HOST_USER = "" + EMAIL_HOST_PASSWORD = "" + EMAIL_USE_TLS = true + ENABLE_PREVIEW_IMAGES = false + USE_S3 = false diff --git a/requirements.txt b/requirements.txt index 4a8c15aa1..ec0eb1a81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,4 +23,5 @@ coverage==5.1 pytest-django==4.1.0 pytest==6.1.2 pytest-cov==2.10.1 +pytest-env==0.6.2 pytest-xdist==2.3.0