2008-07-19 07:54:34 +08:00
|
|
|
|
|
|
|
BASIC_TESTS = """
|
2008-06-30 21:11:12 +08:00
|
|
|
>>> from django.contrib.auth.models import User, AnonymousUser
|
2007-07-29 02:30:40 +08:00
|
|
|
>>> u = User.objects.create_user('testuser', 'test@example.com', 'testpw')
|
|
|
|
>>> u.has_usable_password()
|
|
|
|
True
|
|
|
|
>>> u.check_password('bad')
|
|
|
|
False
|
|
|
|
>>> u.check_password('testpw')
|
|
|
|
True
|
|
|
|
>>> u.set_unusable_password()
|
|
|
|
>>> u.save()
|
|
|
|
>>> u.check_password('testpw')
|
|
|
|
False
|
|
|
|
>>> u.has_usable_password()
|
|
|
|
False
|
|
|
|
>>> u2 = User.objects.create_user('testuser2', 'test2@example.com')
|
|
|
|
>>> u2.has_usable_password()
|
|
|
|
False
|
2007-12-11 14:37:07 +08:00
|
|
|
|
|
|
|
>>> u.is_authenticated()
|
|
|
|
True
|
|
|
|
>>> u.is_staff
|
|
|
|
False
|
|
|
|
>>> u.is_active
|
|
|
|
True
|
2009-03-31 06:00:07 +08:00
|
|
|
>>> u.is_superuser
|
|
|
|
False
|
2007-12-11 14:37:07 +08:00
|
|
|
|
2007-09-16 02:01:29 +08:00
|
|
|
>>> a = AnonymousUser()
|
2007-12-11 14:37:07 +08:00
|
|
|
>>> a.is_authenticated()
|
|
|
|
False
|
2007-09-16 02:01:29 +08:00
|
|
|
>>> a.is_staff
|
|
|
|
False
|
2007-12-11 14:37:07 +08:00
|
|
|
>>> a.is_active
|
|
|
|
False
|
2009-03-31 06:00:07 +08:00
|
|
|
>>> a.is_superuser
|
|
|
|
False
|
2007-09-16 02:01:29 +08:00
|
|
|
>>> a.groups.all()
|
|
|
|
[]
|
|
|
|
>>> a.user_permissions.all()
|
|
|
|
[]
|
2008-06-08 13:31:16 +08:00
|
|
|
|
2009-03-31 06:00:07 +08:00
|
|
|
# superuser tests.
|
|
|
|
>>> super = User.objects.create_superuser('super', 'super@example.com', 'super')
|
|
|
|
>>> super.is_superuser
|
|
|
|
True
|
|
|
|
>>> super.is_active
|
|
|
|
True
|
|
|
|
>>> super.is_staff
|
|
|
|
True
|
|
|
|
|
2008-06-08 13:31:16 +08:00
|
|
|
#
|
|
|
|
# Tests for createsuperuser management command.
|
|
|
|
# It's nearly impossible to test the interactive mode -- a command test helper
|
|
|
|
# would be needed (and *awesome*) -- so just test the non-interactive mode.
|
|
|
|
# This covers most of the important validation, but not all.
|
|
|
|
#
|
|
|
|
>>> from django.core.management import call_command
|
|
|
|
|
2009-04-06 03:00:27 +08:00
|
|
|
>>> call_command("createsuperuser", interactive=False, username="joe", email="joe@somewhere.org")
|
2008-06-08 13:31:16 +08:00
|
|
|
Superuser created successfully.
|
|
|
|
|
|
|
|
>>> u = User.objects.get(username="joe")
|
|
|
|
>>> u.email
|
|
|
|
u'joe@somewhere.org'
|
|
|
|
>>> u.password
|
|
|
|
u'!'
|
2010-05-21 22:08:49 +08:00
|
|
|
>>> call_command("createsuperuser", interactive=False, username="joe+admin@somewhere.org", email="joe@somewhere.org")
|
|
|
|
Superuser created successfully.
|
|
|
|
|
|
|
|
>>> u = User.objects.get(username="joe+admin@somewhere.org")
|
|
|
|
>>> u.email
|
|
|
|
u'joe@somewhere.org'
|
|
|
|
>>> u.password
|
|
|
|
u'!'
|
2008-06-30 21:11:12 +08:00
|
|
|
"""
|