From 9f9b1f7232919e7e801d17b492494826ba207aee Mon Sep 17 00:00:00 2001 From: Juro Oravec Date: Mon, 7 Apr 2025 15:07:46 +0200 Subject: [PATCH] refactor: fix link in docs + call django.setup() in @djc_test if not done so (#1098) --- CHANGELOG.md | 2 ++ docs/overview/welcome.md | 2 +- src/django_components/util/testing.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0fd7dbc..7b1eb622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ Read more on [Component views and URLs](https://django-components.github.io/django-components/0.135/concepts/fundamentals/component_views_urls/). +- `@djc_test` can now be called without first calling `django.setup()`, in which case it does it for you. + #### Deprecation - Currently, view request handlers such as `get()` and `post()` methods can be defined diff --git a/docs/overview/welcome.md b/docs/overview/welcome.md index 7b285ac9..341fed6b 100644 --- a/docs/overview/welcome.md +++ b/docs/overview/welcome.md @@ -1,6 +1,6 @@ django-components -[![PyPI - Version](https://img.shields.io/pypi/v/django-components)](https://pypi.org/project/django-components/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-components)](https://pypi.org/project/django-components/) [![PyPI - License](https://img.shields.io/pypi/l/django-components)](https://github.com/django-components/django-components/blob/master/LICENSE/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/django-components)](https://pypistats.org/packages/django-components) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/django-components/django-components/tests.yml)](https://github.com/django-components/django-components/actions/workflows/tests.yml) [![asv](https://img.shields.io/badge/benchmarked%20by-asv-blue.svg?style=flat)](/django-components/benchmarks/) +[![PyPI - Version](https://img.shields.io/pypi/v/django-components)](https://pypi.org/project/django-components/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-components)](https://pypi.org/project/django-components/) [![PyPI - License](https://img.shields.io/pypi/l/django-components)](https://github.com/django-components/django-components/blob/master/LICENSE/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/django-components)](https://pypistats.org/packages/django-components) [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/django-components/django-components/tests.yml)](https://github.com/django-components/django-components/actions/workflows/tests.yml) [![asv](https://img.shields.io/badge/benchmarked%20by-asv-blue.svg?style=flat)](/django-components/latest/benchmarks/) `django-components` combines Django's templating system with the modularity seen in modern frontend frameworks like Vue or React. diff --git a/src/django_components/util/testing.py b/src/django_components/util/testing.py index 7f82d240..f10f3044 100644 --- a/src/django_components/util/testing.py +++ b/src/django_components/util/testing.py @@ -6,6 +6,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, from unittest.mock import patch from weakref import ReferenceType +import django from django.conf import settings as _django_settings from django.template import engines from django.test import override_settings @@ -296,6 +297,11 @@ def djc_test( # Contents of this function will run as the test def _wrapper_impl(*args: Any, **kwargs: Any) -> Any: + # If Django is not yet configured, do so now, because we'll need to access + # Django's settings when merging the given settings. + if not _django_settings.configured: + django.setup() + # Merge the settings current_django_settings = django_settings if not callable(django_settings) else None current_django_settings = current_django_settings.copy() if current_django_settings else {}