mirror of
https://github.com/django-components/django-components.git
synced 2025-09-21 05:09:44 +00:00

Some checks are pending
Docs - build & deploy / docs (push) Waiting to run
Run tests / build (ubuntu-latest, 3.10) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.11) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.12) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.13) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.8) (push) Waiting to run
Run tests / test_sampleproject (3.13) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.9) (push) Waiting to run
Run tests / build (windows-latest, 3.10) (push) Waiting to run
Run tests / build (windows-latest, 3.11) (push) Waiting to run
Run tests / build (windows-latest, 3.12) (push) Waiting to run
Run tests / build (windows-latest, 3.13) (push) Waiting to run
Run tests / build (windows-latest, 3.8) (push) Waiting to run
Run tests / build (windows-latest, 3.9) (push) Waiting to run
Run tests / test_docs (3.13) (push) Waiting to run
73 lines
2.2 KiB
Python
73 lines
2.2 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,
|
|
) -> 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",
|
|
],
|
|
"loaders": [
|
|
# Default Django loader
|
|
"django.template.loaders.filesystem.Loader",
|
|
# Including this is the same as APP_DIRS=True
|
|
"django.template.loaders.app_directories.Loader",
|
|
# Components loader
|
|
"django_components.template_loader.Loader",
|
|
],
|
|
},
|
|
},
|
|
],
|
|
"COMPONENTS": {
|
|
**(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()
|