mirror of https://github.com/django/django.git
Moved AnonymousUser tests to its own test case.
This commit is contained in:
parent
2b5a511bd9
commit
7fce4dc5ff
|
@ -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')
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue