2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 03:26:45 +00:00

Provide mocked URL to dummy print requst (#9307)

* Provide mocked URL to dummy print requst

- FIxes bug which prevented background printing with DEBUG=False

* Disable debug for postgres testing
This commit is contained in:
Oliver 2025-03-16 00:53:19 +11:00 committed by GitHub
parent 3ac126102a
commit e1ac1c77c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -454,7 +454,7 @@ jobs:
INVENTREE_DB_PASSWORD: password INVENTREE_DB_PASSWORD: password
INVENTREE_DB_HOST: "127.0.0.1" INVENTREE_DB_HOST: "127.0.0.1"
INVENTREE_DB_PORT: 5432 INVENTREE_DB_PORT: 5432
INVENTREE_DEBUG: true INVENTREE_DEBUG: False
INVENTREE_LOG_LEVEL: WARNING INVENTREE_LOG_LEVEL: WARNING
INVENTREE_PLUGINS_ENABLED: false INVENTREE_PLUGINS_ENABLED: false

View File

@ -15,6 +15,7 @@ from django.template import Context, Template
from django.template.exceptions import TemplateDoesNotExist from django.template.exceptions import TemplateDoesNotExist
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -43,13 +44,18 @@ except OSError as err: # pragma: no cover
logger = structlog.getLogger('inventree') logger = structlog.getLogger('inventree')
MOCK_PRINT_HOST = 'localhost'
@override_settings(SITE_URL=MOCK_PRINT_HOST)
def dummy_print_request() -> HttpRequest: def dummy_print_request() -> HttpRequest:
"""Generate a dummy HTTP request object. """Generate a dummy HTTP request object.
This is required for internal print calls, as WeasyPrint *requires* a request object. - This is required for internal print calls, as WeasyPrint *requires* a request object.
- Additionally, we have to mock the HOST header, as WeasyPrint requires a valid HOST URL.
""" """
factory = RequestFactory() factory = RequestFactory()
request = factory.get('/') request = factory.get('/', headers={'host': MOCK_PRINT_HOST})
request.user = AnonymousUser() request.user = AnonymousUser()
return request return request