Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gotenberg server optional in tests #344

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion registration/tests/test_registration_printing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import contextmanager
from datetime import timedelta
from pathlib import Path
from unittest.mock import patch
Expand All @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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"])
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
rechner marked this conversation as resolved.
Show resolved Hide resolved
sentry-sdk
squareup==22.0.0.20220921
qrcode~=7.4.2
Expand Down