Skip to content

Commit

Permalink
Merge branch 'production' into dependabot/pip/configobj-5.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rechner authored Dec 31, 2024
2 parents 8e74ac4 + 9ca03d2 commit 7dbd676
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 13 additions & 2 deletions registration/tests/test_printing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from unittest import TestCase
from unittest.mock import patch

from registration import printing

Expand Down Expand Up @@ -74,11 +75,21 @@ def test_nametag(self) -> None:
"level": "Top Dog",
"title": "",
}
pdf = self.printing.nametag(**tag)
with patch("subprocess.check_call", return_value=0) as patched:
pdf = self.printing.nametag(**tag)
self.assertTrue(os.path.isfile(pdf))
self.assertEqual(patched.call_count, 1)
args = patched.call_args[0][0]
# Last argument is always the filename with path
self.assertEqual(args[-1], pdf)
self.printing.cleanup()

def test_nametags(self) -> None:
pdf = self.printing.nametags(TAGS)
with patch("subprocess.check_call", return_value=0) as patched:
pdf = self.printing.nametags(TAGS)
self.assertTrue(os.path.isfile(pdf))
self.assertEqual(patched.call_count, 1)
args = patched.call_args[0][0]
# Last argument is always the filename with path
self.assertEqual(args[-1], pdf)
self.printing.cleanup()
12 changes: 11 additions & 1 deletion registration/tests/test_registration_printing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import timedelta
from pathlib import Path
from unittest.mock import patch
from urllib.parse import urlparse

from django.conf import settings
from django.contrib.auth.models import User
Expand Down Expand Up @@ -89,7 +92,14 @@ def _badge_generates_pdf(self) -> dict:

def test_print_wkhtmltopdf(self):
settings.PRINT_RENDERER = "wkhtmltopdf"
data = self._badge_generates_pdf()
with patch("subprocess.check_call", return_value=0) as patched:
data = self._badge_generates_pdf()
self.assertEqual(patched.call_count, 1)
args = patched.call_args[0][0]
# Last argument is always the filename with path
arg_filename = Path(args[-1]).name
response_filename = urlparse(data["file"]).query.removeprefix("file=")
self.assertEqual(arg_filename, response_filename)
# wkhtmltopdf responses return a direct path to the file
self.assertIn("?file=", data["file"])

Expand Down

0 comments on commit 7dbd676

Please sign in to comment.