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.apps import apps
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from pdfminer.high_level import extract_text
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from InvenTree.unit_test import InvenTreeAPITestCase
|
from InvenTree.unit_test import InvenTreeAPITestCase
|
||||||
@ -138,6 +139,7 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
|||||||
|
|
||||||
# Lookup references
|
# Lookup references
|
||||||
part = Part.objects.first()
|
part = Part.objects.first()
|
||||||
|
parts = Part.objects.all()[:2]
|
||||||
plugin_ref = 'samplelabelprinter'
|
plugin_ref = 'samplelabelprinter'
|
||||||
label = PartLabel.objects.first()
|
label = PartLabel.objects.first()
|
||||||
|
|
||||||
@ -158,13 +160,13 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
|||||||
self.get(url, expected_code=200)
|
self.get(url, expected_code=200)
|
||||||
|
|
||||||
# Print multiple parts
|
# 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
|
# 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
|
# 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)
|
data = json.loads(response.content)
|
||||||
self.assertIn('file', data)
|
self.assertIn('file', data)
|
||||||
@ -177,9 +179,9 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
|||||||
self.assertTrue(os.path.exists('label.pdf'))
|
self.assertTrue(os.path.exists('label.pdf'))
|
||||||
|
|
||||||
# Read the raw .pdf data - ensure it contains some sensible information
|
# Read the raw .pdf data - ensure it contains some sensible information
|
||||||
with open('label.pdf', 'rb') as f:
|
filetext = extract_text('label.pdf')
|
||||||
pdf_data = str(f.read())
|
matched = [part.name in filetext for part in parts]
|
||||||
self.assertIn('WeasyPrint', pdf_data)
|
self.assertIn(True, matched)
|
||||||
|
|
||||||
# Check that the .png file has already been created
|
# Check that the .png file has already been created
|
||||||
self.assertTrue(os.path.exists('label.png'))
|
self.assertTrue(os.path.exists('label.png'))
|
||||||
@ -193,24 +195,25 @@ class LabelMixinTests(InvenTreeAPITestCase):
|
|||||||
apps.get_app_config('label').create_labels()
|
apps.get_app_config('label').create_labels()
|
||||||
|
|
||||||
# Lookup references
|
# Lookup references
|
||||||
|
parts = Part.objects.all()[:2]
|
||||||
plugin_ref = 'samplelabelprinter'
|
plugin_ref = 'samplelabelprinter'
|
||||||
label = PartLabel.objects.first()
|
label = PartLabel.objects.first()
|
||||||
|
|
||||||
self.do_activate_plugin()
|
self.do_activate_plugin()
|
||||||
|
|
||||||
# test options response
|
# 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"])
|
self.assertTrue("amount" in options["actions"]["POST"])
|
||||||
|
|
||||||
plg = registry.get_plugin(plugin_ref)
|
plg = registry.get_plugin(plugin_ref)
|
||||||
with mock.patch.object(plg, "print_label") as print_label:
|
with mock.patch.object(plg, "print_label") as print_label:
|
||||||
# wrong value type
|
# 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)
|
self.assertTrue("amount" in res)
|
||||||
print_label.assert_not_called()
|
print_label.assert_not_called()
|
||||||
|
|
||||||
# correct value type
|
# 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})
|
self.assertEqual(print_label.call_args.kwargs["printing_options"], {"amount": 13})
|
||||||
|
|
||||||
def test_printing_endpoints(self):
|
def test_printing_endpoints(self):
|
||||||
|
@ -12,3 +12,4 @@ pep8-naming # PEP naming convention extension
|
|||||||
pip-tools # Compile pip requirements
|
pip-tools # Compile pip requirements
|
||||||
pre-commit # Git pre-commit
|
pre-commit # Git pre-commit
|
||||||
setuptools # Standard dependency
|
setuptools # Standard dependency
|
||||||
|
pdfminer.six # PDF validation
|
||||||
|
@ -14,11 +14,16 @@ certifi==2023.7.22
|
|||||||
# via
|
# via
|
||||||
# -c requirements.txt
|
# -c requirements.txt
|
||||||
# requests
|
# requests
|
||||||
|
cffi==1.16.0
|
||||||
|
# via
|
||||||
|
# -c requirements.txt
|
||||||
|
# cryptography
|
||||||
cfgv==3.4.0
|
cfgv==3.4.0
|
||||||
# via pre-commit
|
# via pre-commit
|
||||||
charset-normalizer==3.3.2
|
charset-normalizer==3.3.2
|
||||||
# via
|
# via
|
||||||
# -c requirements.txt
|
# -c requirements.txt
|
||||||
|
# pdfminer-six
|
||||||
# requests
|
# requests
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
# via pip-tools
|
# via pip-tools
|
||||||
@ -28,6 +33,10 @@ coverage==5.5
|
|||||||
# coveralls
|
# coveralls
|
||||||
coveralls==2.1.2
|
coveralls==2.1.2
|
||||||
# via -r requirements-dev.in
|
# via -r requirements-dev.in
|
||||||
|
cryptography==41.0.5
|
||||||
|
# via
|
||||||
|
# -c requirements.txt
|
||||||
|
# pdfminer-six
|
||||||
distlib==0.3.7
|
distlib==0.3.7
|
||||||
# via virtualenv
|
# via virtualenv
|
||||||
django==3.2.23
|
django==3.2.23
|
||||||
@ -72,6 +81,8 @@ packaging==23.2
|
|||||||
# via
|
# via
|
||||||
# -c requirements.txt
|
# -c requirements.txt
|
||||||
# build
|
# build
|
||||||
|
pdfminer-six==20221105
|
||||||
|
# via -r requirements-dev.in
|
||||||
pep8-naming==0.13.3
|
pep8-naming==0.13.3
|
||||||
# via -r requirements-dev.in
|
# via -r requirements-dev.in
|
||||||
pip-tools==7.3.0
|
pip-tools==7.3.0
|
||||||
@ -82,6 +93,10 @@ pre-commit==3.5.0
|
|||||||
# via -r requirements-dev.in
|
# via -r requirements-dev.in
|
||||||
pycodestyle==2.11.1
|
pycodestyle==2.11.1
|
||||||
# via flake8
|
# via flake8
|
||||||
|
pycparser==2.21
|
||||||
|
# via
|
||||||
|
# -c requirements.txt
|
||||||
|
# cffi
|
||||||
pydocstyle==6.3.0
|
pydocstyle==6.3.0
|
||||||
# via flake8-docstrings
|
# via flake8-docstrings
|
||||||
pyflakes==3.1.0
|
pyflakes==3.1.0
|
||||||
|
@ -48,4 +48,4 @@ regex # Advanced regular expressions
|
|||||||
sentry-sdk # Error reporting (optional)
|
sentry-sdk # Error reporting (optional)
|
||||||
setuptools # Standard dependency
|
setuptools # Standard dependency
|
||||||
tablib[xls,xlsx,yaml] # Support for XLS and XLSX formats
|
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
|
||||||
requests-oauthlib==1.3.1
|
requests-oauthlib==1.3.1
|
||||||
# via django-allauth
|
# via django-allauth
|
||||||
rpds-py==0.10.6
|
rpds-py==0.12.0
|
||||||
# via
|
# via
|
||||||
# jsonschema
|
# jsonschema
|
||||||
# referencing
|
# referencing
|
||||||
@ -311,7 +311,7 @@ urllib3==2.0.7
|
|||||||
# dulwich
|
# dulwich
|
||||||
# requests
|
# requests
|
||||||
# sentry-sdk
|
# sentry-sdk
|
||||||
weasyprint==54.3
|
weasyprint==60.1
|
||||||
# via
|
# via
|
||||||
# -r requirements.in
|
# -r requirements.in
|
||||||
# django-weasyprint
|
# django-weasyprint
|
||||||
|
Loading…
Reference in New Issue
Block a user