diff options
Diffstat (limited to 'tests/check_framework')
| -rw-r--r-- | tests/check_framework/test_security.py | 22 | ||||
| -rw-r--r-- | tests/check_framework/test_urls.py | 11 | ||||
| -rw-r--r-- | tests/check_framework/urls/good_error_handler_deferred_annotations.py | 15 |
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/check_framework/test_security.py b/tests/check_framework/test_security.py index cb035a90a4..387a9808cb 100644 --- a/tests/check_framework/test_security.py +++ b/tests/check_framework/test_security.py @@ -1,11 +1,18 @@ +import unittest +from typing import TYPE_CHECKING + from django.conf import settings from django.core.checks.messages import Error, Warning from django.core.checks.security import base, csrf, sessions from django.core.management.utils import get_random_secret_key from django.test import SimpleTestCase from django.test.utils import override_settings +from django.utils.version import PY314 from django.views.generic import View +if TYPE_CHECKING: + from django.http.request import HttpRequest + class CheckSessionCookieSecureTest(SimpleTestCase): @override_settings( @@ -611,6 +618,12 @@ def failure_view_with_invalid_signature(): pass +if PY314: + + def failure_view_with_deferred_annotations(request: HttpRequest, reason: str): + pass + + good_class_based_csrf_failure_view = View.as_view() @@ -651,6 +664,15 @@ class CSRFFailureViewTest(SimpleTestCase): def test_failure_view_valid_class_based(self): self.assertEqual(csrf.check_csrf_failure_view(None), []) + @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only") + @override_settings( + CSRF_FAILURE_VIEW=( + "check_framework.test_security.failure_view_with_deferred_annotations" + ), + ) + def test_failure_view_valid_deferred_annotations(self): + self.assertEqual(csrf.check_csrf_failure_view(None), []) + class CheckCrossOriginOpenerPolicyTest(SimpleTestCase): @override_settings( diff --git a/tests/check_framework/test_urls.py b/tests/check_framework/test_urls.py index a31c5fd856..8931bc75f4 100644 --- a/tests/check_framework/test_urls.py +++ b/tests/check_framework/test_urls.py @@ -1,3 +1,5 @@ +import unittest + from django.conf import settings from django.core.checks.messages import Error, Warning from django.core.checks.urls import ( @@ -10,6 +12,7 @@ from django.core.checks.urls import ( ) from django.test import SimpleTestCase from django.test.utils import override_settings +from django.utils.version import PY314 class CheckUrlConfigTests(SimpleTestCase): @@ -322,6 +325,14 @@ class CheckCustomErrorHandlersTests(SimpleTestCase): result = check_custom_error_handlers(None) self.assertEqual(result, []) + @unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only") + @override_settings( + ROOT_URLCONF="check_framework.urls.good_error_handler_deferred_annotations", + ) + def test_good_function_based_handlers_deferred_annotations(self): + result = check_custom_error_handlers(None) + self.assertEqual(result, []) + @override_settings( ROOT_URLCONF="check_framework.urls.good_class_based_error_handlers", ) diff --git a/tests/check_framework/urls/good_error_handler_deferred_annotations.py b/tests/check_framework/urls/good_error_handler_deferred_annotations.py new file mode 100644 index 0000000000..8b4ead5566 --- /dev/null +++ b/tests/check_framework/urls/good_error_handler_deferred_annotations.py @@ -0,0 +1,15 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from django.http.request import HttpRequest + +urlpatterns = [] + +handler400 = __name__ + ".good_handler_deferred_annotations" +handler403 = __name__ + ".good_handler_deferred_annotations" +handler404 = __name__ + ".good_handler_deferred_annotations" +handler500 = __name__ + ".good_handler_deferred_annotations" + + +def good_handler_deferred_annotations(request: HttpRequest, exception=None): + pass |
