summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-01-04 05:55:29 +0100
committerGitHub <noreply@github.com>2024-01-04 05:55:29 +0100
commit0c5456ef37a22e2ce0d31e7ebf99d9fa04a5b9c4 (patch)
tree6c34138d147f7147f0a2ea694e866883086be2b0 /tests/auth_tests
parentd89a465e62ad876cc7f1332d1712700cb81f3995 (diff)
Used enterClassContext() where appropriate.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_auth_backends.py12
-rw-r--r--tests/auth_tests/test_remote_user.py14
2 files changed, 15 insertions, 11 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index a7005de8a4..3b4f40e6e0 100644
--- a/tests/auth_tests/test_auth_backends.py
+++ b/tests/auth_tests/test_auth_backends.py
@@ -94,15 +94,17 @@ class BaseModelBackendTest:
backend = "django.contrib.auth.backends.ModelBackend"
+ @classmethod
+ def setUpClass(cls):
+ cls.enterClassContext(
+ modify_settings(AUTHENTICATION_BACKENDS={"append": cls.backend})
+ )
+ super().setUpClass()
+
def setUp(self):
# The custom_perms test messes with ContentTypes, which will be cached.
# Flush the cache to ensure there are no side effects.
self.addCleanup(ContentType.objects.clear_cache)
- patched_settings = modify_settings(
- AUTHENTICATION_BACKENDS={"append": self.backend},
- )
- patched_settings.enable()
- self.addCleanup(patched_settings.disable)
self.create_users()
def test_has_perm(self):
diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py
index 6066ab96e9..d3cf4b9da5 100644
--- a/tests/auth_tests/test_remote_user.py
+++ b/tests/auth_tests/test_remote_user.py
@@ -20,13 +20,15 @@ class RemoteUserTest(TestCase):
known_user = "knownuser"
known_user2 = "knownuser2"
- def setUp(self):
- patched_settings = modify_settings(
- AUTHENTICATION_BACKENDS={"append": self.backend},
- MIDDLEWARE={"append": self.middleware},
+ @classmethod
+ def setUpClass(cls):
+ cls.enterClassContext(
+ modify_settings(
+ AUTHENTICATION_BACKENDS={"append": cls.backend},
+ MIDDLEWARE={"append": cls.middleware},
+ )
)
- patched_settings.enable()
- self.addCleanup(patched_settings.disable)
+ super().setUpClass()
def test_no_remote_user(self):
"""Users are not created when remote user is not specified."""