mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Bump weasyprint (#5885)
* bumped weasyprint * factored reused section out (reduce DB access) * added pdf-context testing Co-authored-by: miggland <miggland@users.noreply.github.com> * switched to pdfminer.six * make test more resilient --------- Co-authored-by: miggland <miggland@users.noreply.github.com>
This commit is contained in:
parent
a0841088ae
commit
d30ff8a291
@ -7,6 +7,7 @@ from unittest import mock
|
||||
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
|
||||
@ -138,6 +139,7 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
||||
|
||||
# Lookup references
|
||||
part = Part.objects.first()
|
||||
parts = Part.objects.all()[:2]
|
||||
plugin_ref = 'samplelabelprinter'
|
||||
label = PartLabel.objects.first()
|
||||
|
||||
@ -158,13 +160,13 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
||||
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)
|
||||
@ -177,9 +179,9 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
||||
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'))
|
||||
@ -193,24 +195,25 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
||||
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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -311,7 +311,7 @@ urllib3==2.0.7
|
||||
# dulwich
|
||||
# requests
|
||||
# sentry-sdk
|
||||
weasyprint==54.3
|
||||
weasyprint==60.1
|
||||
# via
|
||||
# -r requirements.in
|
||||
# django-weasyprint
|
||||
|
Loading…
Reference in New Issue
Block a user