summaryrefslogtreecommitdiff
path: root/tests/async
diff options
context:
space:
mode:
authorJon Janzen <jon@jonjanzen.com>2024-03-31 12:29:10 -0700
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-10-07 14:19:41 +0200
commit50f89ae850f6b4e35819fe725a08c7e579bfd099 (patch)
tree856a0e954e0be928c55f6070f2ac8b766459b3e7 /tests/async
parent4cad317ff1f9a79d54c1d5b12f1ccbd260ca009f (diff)
Fixed #35303 -- Implemented async auth backends and utils.
Diffstat (limited to 'tests/async')
-rw-r--r--tests/async/test_async_auth.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/async/test_async_auth.py b/tests/async/test_async_auth.py
index f6551c63ee..37884d13a6 100644
--- a/tests/async/test_async_auth.py
+++ b/tests/async/test_async_auth.py
@@ -33,9 +33,40 @@ class AsyncAuthTest(TestCase):
self.assertIsInstance(user, User)
self.assertEqual(user.username, self.test_user.username)
+ async def test_changed_password_invalidates_aget_user(self):
+ request = HttpRequest()
+ request.session = await self.client.asession()
+ await alogin(request, self.test_user)
+
+ self.test_user.set_password("new_password")
+ await self.test_user.asave()
+
+ user = await aget_user(request)
+
+ self.assertIsNotNone(user)
+ self.assertTrue(user.is_anonymous)
+ # Session should be flushed.
+ self.assertIsNone(request.session.session_key)
+
+ async def test_alogin_new_user(self):
+ request = HttpRequest()
+ request.session = await self.client.asession()
+ await alogin(request, self.test_user)
+ second_user = await User.objects.acreate_user(
+ "testuser2", "test2@example.com", "testpw2"
+ )
+ await alogin(request, second_user)
+ user = await aget_user(request)
+ self.assertIsInstance(user, User)
+ self.assertEqual(user.username, second_user.username)
+
async def test_alogin_without_user(self):
+ async def auser():
+ return self.test_user
+
request = HttpRequest()
request.user = self.test_user
+ request.auser = auser
request.session = await self.client.asession()
await alogin(request, None)
user = await aget_user(request)