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

Bump weasyprint #5885

Merged
merged 8 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 12 additions & 9 deletions InvenTree/plugin/base/label/test_label_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.apps import apps
from django.urls import reverse

from pdfminer.high_level import extract_text
from PIL import Image

from InvenTree.unit_test import InvenTreeAPITestCase
Expand Down Expand Up @@ -138,6 +139,7 @@ def test_printing_process(self):

# Lookup references
part = Part.objects.first()
parts = Part.objects.all()[:2]
plugin_ref = 'samplelabelprinter'
label = PartLabel.objects.first()

Expand All @@ -158,13 +160,13 @@ def test_printing_process(self):
self.get(url, expected_code=200)

# Print multiple parts
self.get(self.do_url(Part.objects.all()[:2], plugin_ref, label), expected_code=200)
self.get(self.do_url(parts, plugin_ref, label), expected_code=200)

# Print multiple parts without a plugin
self.get(self.do_url(Part.objects.all()[:2], None, label), expected_code=200)
self.get(self.do_url(parts, None, label), expected_code=200)

# Print multiple parts without a plugin in debug mode
response = self.get(self.do_url(Part.objects.all()[:2], None, label), expected_code=200)
response = self.get(self.do_url(parts, None, label), expected_code=200)

data = json.loads(response.content)
self.assertIn('file', data)
Expand All @@ -177,9 +179,9 @@ def test_printing_process(self):
self.assertTrue(os.path.exists('label.pdf'))

# Read the raw .pdf data - ensure it contains some sensible information
with open('label.pdf', 'rb') as f:
pdf_data = str(f.read())
self.assertIn('WeasyPrint', pdf_data)
filetext = extract_text('label.pdf')
matched = [part.name in filetext for part in parts]
self.assertIn(True, matched)

# Check that the .png file has already been created
self.assertTrue(os.path.exists('label.png'))
Expand All @@ -193,24 +195,25 @@ def test_printing_options(self):
apps.get_app_config('label').create_labels()

# Lookup references
parts = Part.objects.all()[:2]
plugin_ref = 'samplelabelprinter'
label = PartLabel.objects.first()

self.do_activate_plugin()

# test options response
options = self.options(self.do_url(Part.objects.all()[:2], plugin_ref, label), expected_code=200).json()
options = self.options(self.do_url(parts, plugin_ref, label), expected_code=200).json()
self.assertTrue("amount" in options["actions"]["POST"])

plg = registry.get_plugin(plugin_ref)
with mock.patch.object(plg, "print_label") as print_label:
# wrong value type
res = self.post(self.do_url(Part.objects.all()[:2], plugin_ref, label), data={"amount": "-no-valid-int-"}, expected_code=400).json()
res = self.post(self.do_url(parts, plugin_ref, label), data={"amount": "-no-valid-int-"}, expected_code=400).json()
self.assertTrue("amount" in res)
print_label.assert_not_called()

# correct value type
self.post(self.do_url(Part.objects.all()[:2], plugin_ref, label), data={"amount": 13}, expected_code=200).json()
self.post(self.do_url(parts, plugin_ref, label), data={"amount": 13}, expected_code=200).json()
self.assertEqual(print_label.call_args.kwargs["printing_options"], {"amount": 13})

def test_printing_endpoints(self):
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pep8-naming # PEP naming convention extension
pip-tools # Compile pip requirements
pre-commit # Git pre-commit
setuptools # Standard dependency
pdfminer.six # PDF validation
15 changes: 15 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ certifi==2023.7.22
# via
# -c requirements.txt
# requests
cffi==1.16.0
# via
# -c requirements.txt
# cryptography
cfgv==3.4.0
# via pre-commit
charset-normalizer==3.3.2
# via
# -c requirements.txt
# pdfminer-six
# requests
click==8.1.7
# via pip-tools
Expand All @@ -28,6 +33,10 @@ coverage==5.5
# coveralls
coveralls==2.1.2
# via -r requirements-dev.in
cryptography==41.0.5
# via
# -c requirements.txt
# pdfminer-six
distlib==0.3.7
# via virtualenv
django==3.2.23
Expand Down Expand Up @@ -72,6 +81,8 @@ packaging==23.2
# via
# -c requirements.txt
# build
pdfminer-six==20221105
# via -r requirements-dev.in
pep8-naming==0.13.3
# via -r requirements-dev.in
pip-tools==7.3.0
Expand All @@ -82,6 +93,10 @@ pre-commit==3.5.0
# via -r requirements-dev.in
pycodestyle==2.11.1
# via flake8
pycparser==2.21
# via
# -c requirements.txt
# cffi
pydocstyle==6.3.0
# via flake8-docstrings
pyflakes==3.1.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ regex # Advanced regular expressions
sentry-sdk # Error reporting (optional)
setuptools # Standard dependency
tablib[xls,xlsx,yaml] # Support for XLS and XLSX formats
weasyprint==54.3 # PDF generation
weasyprint # PDF generation
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ requests==2.31.0
# requests-oauthlib
requests-oauthlib==1.3.1
# via django-allauth
rpds-py==0.10.6
rpds-py==0.12.0
# via
# jsonschema
# referencing
Expand Down Expand Up @@ -311,7 +311,7 @@ urllib3==2.0.7
# dulwich
# requests
# sentry-sdk
weasyprint==54.3
weasyprint==60.1
# via
# -r requirements.in
# django-weasyprint
Expand Down