forked from mirrors/bookwyrm
Merge branch 'main' into suggestions-redis
This commit is contained in:
commit
62befa9295
6 changed files with 36 additions and 4 deletions
|
@ -13,6 +13,7 @@ from django.db import models
|
||||||
from django.forms import ClearableFileInput, ImageField as DjangoImageField
|
from django.forms import ClearableFileInput, ImageField as DjangoImageField
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
from bookwyrm.connectors import get_image
|
from bookwyrm.connectors import get_image
|
||||||
from bookwyrm.sanitize_html import InputHtmlParser
|
from bookwyrm.sanitize_html import InputHtmlParser
|
||||||
|
@ -354,7 +355,8 @@ def image_serializer(value, alt):
|
||||||
url = value.url
|
url = value.url
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
url = "https://%s%s" % (DOMAIN, url)
|
if not url[:4] == "http":
|
||||||
|
url = "https://{:s}{:s}".format(DOMAIN, url)
|
||||||
return activitypub.Document(url=url, name=alt)
|
return activitypub.Document(url=url, name=alt)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -426,6 +426,15 @@ class ActivitypubFields(TestCase):
|
||||||
self.assertIsInstance(loaded_image, list)
|
self.assertIsInstance(loaded_image, list)
|
||||||
self.assertIsInstance(loaded_image[1], ContentFile)
|
self.assertIsInstance(loaded_image[1], ContentFile)
|
||||||
|
|
||||||
|
def test_image_serialize(self):
|
||||||
|
"""make sure we're creating sensible image paths"""
|
||||||
|
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://your.domain.here/images/fish.jpg")
|
||||||
|
self.assertEqual(result.name, "hello")
|
||||||
|
|
||||||
def test_datetime_field(self):
|
def test_datetime_field(self):
|
||||||
"""this one is pretty simple, it just has to use isoformat"""
|
"""this one is pretty simple, it just has to use isoformat"""
|
||||||
instance = fields.DateTimeField()
|
instance = fields.DateTimeField()
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Announcements(View):
|
||||||
form = forms.AnnouncementForm()
|
form = forms.AnnouncementForm()
|
||||||
data = {
|
data = {
|
||||||
"announcements": Paginator(
|
"announcements": Paginator(
|
||||||
models.Announcement.objects.all(), PAGE_LENGTH
|
models.Announcement.objects.order_by("-created_date"), PAGE_LENGTH
|
||||||
).get_page(request.GET.get("page")),
|
).get_page(request.GET.get("page")),
|
||||||
"form": form,
|
"form": form,
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,9 @@ class Followers(View):
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
return ActivitypubResponse(user.to_followers_activity(**request.GET))
|
return ActivitypubResponse(user.to_followers_activity(**request.GET))
|
||||||
|
|
||||||
paginated = Paginator(user.followers.all(), PAGE_LENGTH)
|
paginated = Paginator(
|
||||||
|
user.followers.order_by("-created_date").all(), PAGE_LENGTH
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
"user": user,
|
"user": user,
|
||||||
"is_self": request.user.id == user.id,
|
"is_self": request.user.id == user.id,
|
||||||
|
@ -107,7 +109,9 @@ class Following(View):
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
return ActivitypubResponse(user.to_following_activity(**request.GET))
|
return ActivitypubResponse(user.to_following_activity(**request.GET))
|
||||||
|
|
||||||
paginated = Paginator(user.following.all(), PAGE_LENGTH)
|
paginated = Paginator(
|
||||||
|
user.following.order_by("-created_date").all(), PAGE_LENGTH
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
"user": user,
|
"user": user,
|
||||||
"is_self": request.user.id == user.id,
|
"is_self": request.user.id == user.id,
|
||||||
|
|
16
pytest.ini
16
pytest.ini
|
@ -4,3 +4,19 @@ python_files = tests.py test_*.py *_tests.py
|
||||||
addopts = --cov=bookwyrm --cov-config=.coveragerc
|
addopts = --cov=bookwyrm --cov-config=.coveragerc
|
||||||
markers =
|
markers =
|
||||||
integration: marks tests as requiring external resources (deselect with '-m "not integration"')
|
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
|
||||||
|
|
|
@ -23,4 +23,5 @@ coverage==5.1
|
||||||
pytest-django==4.1.0
|
pytest-django==4.1.0
|
||||||
pytest==6.1.2
|
pytest==6.1.2
|
||||||
pytest-cov==2.10.1
|
pytest-cov==2.10.1
|
||||||
|
pytest-env==0.6.2
|
||||||
pytest-xdist==2.3.0
|
pytest-xdist==2.3.0
|
||||||
|
|
Loading…
Reference in a new issue