diff --git a/tests/auth_tests/test_basic.py b/tests/auth_tests/test_basic.py index 80a56f8ca3..886ad360e3 100644 --- a/tests/auth_tests/test_basic.py +++ b/tests/auth_tests/test_basic.py @@ -62,20 +62,6 @@ class BasicTestCase(TestCase): u3 = User.objects.create_user('testuser3', email=None) self.assertEqual(u3.email, '') - def test_anonymous_user(self): - "Check the properties of the anonymous user" - a = AnonymousUser() - self.assertIsNone(a.pk) - self.assertEqual(a.username, '') - self.assertEqual(a.get_username(), '') - self.assertTrue(a.is_anonymous) - self.assertFalse(a.is_authenticated) - self.assertFalse(a.is_staff) - self.assertFalse(a.is_active) - self.assertFalse(a.is_superuser) - self.assertEqual(a.groups.all().count(), 0) - self.assertEqual(a.user_permissions.all().count(), 0) - def test_superuser(self): "Check the creation and properties of a superuser" super = User.objects.create_superuser('super', 'super@example.com', 'super') diff --git a/tests/auth_tests/test_models.py b/tests/auth_tests/test_models.py index e546d61c64..62d598c2cd 100644 --- a/tests/auth_tests/test_models.py +++ b/tests/auth_tests/test_models.py @@ -5,12 +5,12 @@ from django.contrib.auth import get_user_model from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.auth.hashers import get_hasher from django.contrib.auth.models import ( - AbstractUser, Group, Permission, User, UserManager, + AbstractUser, AnonymousUser, Group, Permission, User, UserManager, ) from django.contrib.contenttypes.models import ContentType from django.core import mail from django.db.models.signals import post_save -from django.test import TestCase, override_settings +from django.test import SimpleTestCase, TestCase, override_settings from .models.with_custom_email_field import CustomEmailField @@ -303,3 +303,21 @@ class TestCreateSuperUserSignals(TestCase): def test_create_superuser(self): User.objects.create_superuser("JohnDoe", "mail@example.com", "1") self.assertEqual(self.signals_count, 1) + + +class AnonymousUserTests(SimpleTestCase): + + def setUp(self): + self.user = AnonymousUser() + + def test_properties(self): + self.assertIsNone(self.user.pk) + self.assertEqual(self.user.username, '') + self.assertEqual(self.user.get_username(), '') + self.assertIs(self.user.is_anonymous, True) + self.assertIs(self.user.is_authenticated, False) + self.assertIs(self.user.is_staff, False) + self.assertIs(self.user.is_active, False) + self.assertIs(self.user.is_superuser, False) + self.assertEqual(self.user.groups.all().count(), 0) + self.assertEqual(self.user.user_permissions.all().count(), 0)