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:
parent
3ac126102a
commit
e1ac1c77c0
2
.github/workflows/qc_checks.yaml
vendored
2
.github/workflows/qc_checks.yaml
vendored
@ -454,7 +454,7 @@ jobs:
|
||||
INVENTREE_DB_PASSWORD: password
|
||||
INVENTREE_DB_HOST: "127.0.0.1"
|
||||
INVENTREE_DB_PORT: 5432
|
||||
INVENTREE_DEBUG: true
|
||||
INVENTREE_DEBUG: False
|
||||
INVENTREE_LOG_LEVEL: WARNING
|
||||
INVENTREE_PLUGINS_ENABLED: false
|
||||
|
||||
|
@ -15,6 +15,7 @@ from django.template import Context, Template
|
||||
from django.template.exceptions import TemplateDoesNotExist
|
||||
from django.template.loader import render_to_string
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@ -43,13 +44,18 @@ except OSError as err: # pragma: no cover
|
||||
logger = structlog.getLogger('inventree')
|
||||
|
||||
|
||||
MOCK_PRINT_HOST = 'localhost'
|
||||
|
||||
|
||||
@override_settings(SITE_URL=MOCK_PRINT_HOST)
|
||||
def dummy_print_request() -> HttpRequest:
|
||||
"""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()
|
||||
request = factory.get('/')
|
||||
request = factory.get('/', headers={'host': MOCK_PRINT_HOST})
|
||||
request.user = AnonymousUser()
|
||||
return request
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user