From b99c608ea10cabc97a6b251cdb6e81ef2a83bdcf Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 9 Jun 2024 12:18:26 -0400 Subject: [PATCH] Refs #35402 -- Added tests for invalid usage of submodules in some settings. --- tests/auth_tests/test_models.py | 7 +++++++ tests/auth_tests/test_validators.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/auth_tests/test_models.py b/tests/auth_tests/test_models.py index 34f411f2f95..983424843c8 100644 --- a/tests/auth_tests/test_models.py +++ b/tests/auth_tests/test_models.py @@ -433,6 +433,13 @@ class UserWithPermTestCase(TestCase): backend="invalid.backend.CustomModelBackend", ) + def test_invalid_backend_submodule(self): + with self.assertRaises(ImportError): + User.objects.with_perm( + "auth.test", + backend="json.tool", + ) + @override_settings( AUTHENTICATION_BACKENDS=["auth_tests.test_models.CustomModelBackend"] ) diff --git a/tests/auth_tests/test_validators.py b/tests/auth_tests/test_validators.py index 4da031a7931..506c85c0ae5 100644 --- a/tests/auth_tests/test_validators.py +++ b/tests/auth_tests/test_validators.py @@ -14,7 +14,7 @@ from django.contrib.auth.password_validation import ( password_validators_help_texts, validate_password, ) -from django.core.exceptions import ValidationError +from django.core.exceptions import ImproperlyConfigured, ValidationError from django.db import models from django.test import SimpleTestCase, TestCase, override_settings from django.test.utils import isolate_apps @@ -50,6 +50,15 @@ class PasswordValidationTest(SimpleTestCase): self.assertEqual(get_password_validators([]), []) + def test_get_password_validators_custom_invalid(self): + validator_config = [{"NAME": "json.tool"}] + msg = ( + "The module in NAME could not be imported: json.tool. " + "Check your AUTH_PASSWORD_VALIDATORS setting." + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): + get_password_validators(validator_config) + def test_validate_password(self): self.assertIsNone(validate_password("sufficiently-long")) msg_too_short = (