summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_auth_backends.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-31 10:01:31 +0100
committerGitHub <noreply@github.com>2023-12-31 10:01:31 +0100
commitd88ec42bd0a37340c8477a6f20bf26e58bd84735 (patch)
treeabd9422f7fb34a19579a74515ce84d9f472cd226 /tests/auth_tests/test_auth_backends.py
parent81ccf92f154c6d9eac3e30bac0aa67574d0ace15 (diff)
Used addCleanup() in tests where appropriate.
Diffstat (limited to 'tests/auth_tests/test_auth_backends.py')
-rw-r--r--tests/auth_tests/test_auth_backends.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index 81406f37e6..a7005de8a4 100644
--- a/tests/auth_tests/test_auth_backends.py
+++ b/tests/auth_tests/test_auth_backends.py
@@ -95,19 +95,16 @@ class BaseModelBackendTest:
backend = "django.contrib.auth.backends.ModelBackend"
def setUp(self):
- self.patched_settings = modify_settings(
+ # 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},
)
- self.patched_settings.enable()
+ patched_settings.enable()
+ self.addCleanup(patched_settings.disable)
self.create_users()
- def tearDown(self):
- self.patched_settings.disable()
- # The custom_perms test messes with ContentTypes, which will
- # be cached; flush the cache to ensure there are no side effects
- # Refs #14975, #14925
- ContentType.objects.clear_cache()
-
def test_has_perm(self):
user = self.UserModel._default_manager.get(pk=self.user.pk)
self.assertIs(user.has_perm("auth.test"), False)
@@ -615,9 +612,9 @@ class PermissionDeniedBackendTest(TestCase):
def setUp(self):
self.user_login_failed = []
signals.user_login_failed.connect(self.user_login_failed_listener)
-
- def tearDown(self):
- signals.user_login_failed.disconnect(self.user_login_failed_listener)
+ self.addCleanup(
+ signals.user_login_failed.disconnect, self.user_login_failed_listener
+ )
def user_login_failed_listener(self, sender, credentials, **kwargs):
self.user_login_failed.append(credentials)