diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-09-05 14:06:36 -0400 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-09-17 15:17:05 -0300 |
| commit | 32e266dc5b756b52e6db4f4f453f51274aa9234e (patch) | |
| tree | d9714ba24c866dac1e126723c4a06a7a4cf35ffa /tests | |
| parent | a146fe293099d7f860ba13e4b3a571bbda55af22 (diff) | |
Refs #35530 -- Removed request.user or auser() fallback in auth.login and auth.alogin.
Per deprecation timeline.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/async/test_async_auth.py | 62 | ||||
| -rw-r--r-- | tests/auth_tests/test_login.py | 50 |
2 files changed, 9 insertions, 103 deletions
diff --git a/tests/async/test_async_auth.py b/tests/async/test_async_auth.py index d872a4c5bb..1ce2747d4d 100644 --- a/tests/async/test_async_auth.py +++ b/tests/async/test_async_auth.py @@ -8,7 +8,6 @@ from django.contrib.auth import ( from django.contrib.auth.models import AnonymousUser, User from django.http import HttpRequest from django.test import TestCase, override_settings -from django.utils.deprecation import RemovedInDjango61Warning class AsyncAuthTest(TestCase): @@ -61,68 +60,15 @@ class AsyncAuthTest(TestCase): self.assertIsInstance(user, User) self.assertEqual(user.username, second_user.username) - # RemovedInDjango61Warning: When the deprecation ends, replace with: - # async def test_alogin_without_user(self): - async def test_alogin_without_user_no_request_user(self): + async def test_alogin_without_user(self): request = HttpRequest() request.session = await self.client.asession() - # RemovedInDjango61Warning: When the deprecation ends, replace with: - # with self.assertRaisesMessage( - # AttributeError, - # "'NoneType' object has no attribute 'get_session_auth_hash'", - # ): - # await alogin(request, None) - with ( - self.assertRaisesMessage( - AttributeError, - "'HttpRequest' object has no attribute 'auser'", - ), - self.assertWarnsMessage( - RemovedInDjango61Warning, - "Fallback to request.auser() when user is None will be removed.", - ), + with self.assertRaisesMessage( + AttributeError, + "'NoneType' object has no attribute 'get_session_auth_hash'", ): await alogin(request, None) - # RemovedInDjango61Warning: When the deprecation ends, remove completely. - async def test_alogin_without_user_anonymous_request(self): - async def auser(): - return AnonymousUser() - - request = HttpRequest() - request.user = AnonymousUser() - request.auser = auser - request.session = await self.client.asession() - with ( - self.assertRaisesMessage( - AttributeError, - "'AnonymousUser' object has no attribute '_meta'", - ), - self.assertWarnsMessage( - RemovedInDjango61Warning, - "Fallback to request.auser() when user is None will be removed.", - ), - ): - await alogin(request, None) - - # RemovedInDjango61Warning: When the deprecation ends, remove completely. - async def test_alogin_without_user_authenticated_request(self): - async def auser(): - return self.test_user - - request = HttpRequest() - request.user = self.test_user - request.auser = auser - request.session = await self.client.asession() - with self.assertWarnsMessage( - RemovedInDjango61Warning, - "Fallback to request.auser() when user is None will be removed.", - ): - await alogin(request, None) - user = await aget_user(request) - self.assertIsInstance(user, User) - self.assertEqual(user.username, self.test_user.username) - async def test_alogout(self): await self.client.alogin(username="testuser", password="testpw") request = HttpRequest() diff --git a/tests/auth_tests/test_login.py b/tests/auth_tests/test_login.py index 2c0c1c5796..6da20ac5fa 100644 --- a/tests/auth_tests/test_login.py +++ b/tests/auth_tests/test_login.py @@ -1,8 +1,7 @@ from django.contrib import auth -from django.contrib.auth.models import AnonymousUser, User +from django.contrib.auth.models import User from django.http import HttpRequest from django.test import TestCase -from django.utils.deprecation import RemovedInDjango61Warning class TestLogin(TestCase): @@ -25,48 +24,9 @@ class TestLogin(TestCase): auth.login(self.request, self.user) self.assertEqual(self.request.session[auth.SESSION_KEY], str(self.user.pk)) - # RemovedInDjango61Warning: When the deprecation ends, replace with: - # def test_without_user(self): - def test_without_user_no_request_user(self): - # RemovedInDjango61Warning: When the deprecation ends, replace with: - # with self.assertRaisesMessage( - # AttributeError, - # "'NoneType' object has no attribute 'get_session_auth_hash'", - # ): - # auth.login(self.request, None) - with ( - self.assertRaisesMessage( - AttributeError, - "'HttpRequest' object has no attribute 'user'", - ), - self.assertWarnsMessage( - RemovedInDjango61Warning, - "Fallback to request.user when user is None will be removed.", - ), + def test_without_user(self): + with self.assertRaisesMessage( + AttributeError, + "'NoneType' object has no attribute 'get_session_auth_hash'", ): auth.login(self.request, None) - - # RemovedInDjango61Warning: When the deprecation ends, remove completely. - def test_without_user_anonymous_request(self): - self.request.user = AnonymousUser() - with ( - self.assertRaisesMessage( - AttributeError, - "'AnonymousUser' object has no attribute '_meta'", - ), - self.assertWarnsMessage( - RemovedInDjango61Warning, - "Fallback to request.user when user is None will be removed.", - ), - ): - auth.login(self.request, None) - - # RemovedInDjango61Warning: When the deprecation ends, remove completely. - def test_without_user_authenticated_request(self): - self.request.user = self.user - self.assertNotIn(auth.SESSION_KEY, self.request.session) - - msg = "Fallback to request.user when user is None will be removed." - with self.assertWarnsMessage(RemovedInDjango61Warning, msg): - auth.login(self.request, None) - self.assertEqual(self.request.session[auth.SESSION_KEY], str(self.user.pk)) |
