diff --git a/Dockerfile b/Dockerfile index 63a7bad..ee94439 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/furthemore/apis:apis-base-cb35d5b +FROM ghcr.io/furthemore/apis:apis-base-3d1a81a LABEL org.opencontainers.image.source="https://github.com/furthemore/APIS" diff --git a/registration/tests/test_registration_printing.py b/registration/tests/test_registration_printing.py index 36f1250..04d6b85 100644 --- a/registration/tests/test_registration_printing.py +++ b/registration/tests/test_registration_printing.py @@ -1,3 +1,4 @@ +from contextlib import contextmanager from datetime import timedelta from pathlib import Path from unittest.mock import patch @@ -6,8 +7,11 @@ from django.conf import settings from django.contrib.auth.models import User from django.test import Client, TestCase +from django.test.utils import override_settings from django.urls import reverse from django.utils import timezone +import httpx +import respx from registration.models import ( Attendee, @@ -24,6 +28,28 @@ ten_days = timedelta(days=10) +@contextmanager +def patch_gotenberg(have_gotenberg_host): + if have_gotenberg_host: + yield + return + + patcher = override_settings(GOTENBERG_HOST="https://localhost:9125") + patcher.enable() + + try: + with respx.mock: + convert_route = respx.post( + "https://localhost:9125/forms/chromium/convert/html" + ).mock(return_value=httpx.Response(204)) + + yield + + assert convert_route.called + finally: + patcher.disable() + + class TestRegistrationPrinting(TestCase): def setUp(self): self.admin_user = User.objects.create_superuser("admin", "admin@host", "admin") @@ -105,6 +131,7 @@ def test_print_wkhtmltopdf(self): def test_print_gotenberg(self): settings.PRINT_RENDERER = "gotenberg" - data = self._badge_generates_pdf() + with patch_gotenberg(hasattr(settings, "GOTENBERG_HOST")): + data = self._badge_generates_pdf() # gotenberg responses return a signed data parameter with badge IDs self.assertIn("?data=", data["file"]) diff --git a/requirements.txt b/requirements.txt index a56ef38..e9cd190 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ paho-mqtt==1.6.1 Pillow>=5.3 psycopg2-binary==2.9.9 PyJWT~=2.8.0 +respx==0.22.0 sentry-sdk squareup==22.0.0.20220921 qrcode~=7.4.2