mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 06:18:17 +00:00

* refactor: remove middleware, add strategy "raw", and call render_deps() from within Template.render() * refactor: fix formatting * refactor: fix benchmark tests * refactor: avoid processing deps if rendered HTML contains no components * refactor: remove comments * refactor: rename "raw" to "ignore"
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
from pathlib import Path
|
|
from typing import Dict, Optional
|
|
|
|
import django
|
|
from django.conf import settings
|
|
|
|
# Common use case in our tests is to check that the component works in both
|
|
# "django" and "isolated" context behaviors. If you need only that, pass this
|
|
# tuple to `djc_test` as the `parametrize` argument.
|
|
PARAMETRIZE_CONTEXT_BEHAVIOR = (
|
|
["components_settings"],
|
|
[
|
|
[{"context_behavior": "django"}],
|
|
[{"context_behavior": "isolated"}],
|
|
],
|
|
["django", "isolated"],
|
|
)
|
|
|
|
|
|
def setup_test_config(
|
|
components: Optional[Dict] = None,
|
|
extra_settings: Optional[Dict] = None,
|
|
):
|
|
if settings.configured:
|
|
return
|
|
|
|
default_settings = {
|
|
"BASE_DIR": Path(__file__).resolve().parent,
|
|
"INSTALLED_APPS": ("django_components", "tests.test_app"),
|
|
"TEMPLATES": [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [
|
|
"tests/templates/",
|
|
"tests/components/", # Required for template relative imports in tests
|
|
],
|
|
"OPTIONS": {
|
|
"builtins": [
|
|
"django_components.templatetags.component_tags",
|
|
]
|
|
},
|
|
}
|
|
],
|
|
"COMPONENTS": {
|
|
"template_cache_size": 128,
|
|
**(components or {}),
|
|
},
|
|
"MIDDLEWARE": [],
|
|
"DATABASES": {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": ":memory:",
|
|
}
|
|
},
|
|
"SECRET_KEY": "secret",
|
|
"ROOT_URLCONF": "django_components.urls",
|
|
}
|
|
|
|
settings.configure(
|
|
**{
|
|
**default_settings,
|
|
**(extra_settings or {}),
|
|
}
|
|
)
|
|
|
|
django.setup()
|