|
0
|
1 |
|
|
|
2 |
BASIC_TESTS = """ |
|
|
3 |
>>> from django.contrib.auth.models import User, AnonymousUser |
|
|
4 |
>>> u = User.objects.create_user('testuser', 'test@example.com', 'testpw') |
|
|
5 |
>>> u.has_usable_password() |
|
|
6 |
True |
|
|
7 |
>>> u.check_password('bad') |
|
|
8 |
False |
|
|
9 |
>>> u.check_password('testpw') |
|
|
10 |
True |
|
|
11 |
>>> u.set_unusable_password() |
|
|
12 |
>>> u.save() |
|
|
13 |
>>> u.check_password('testpw') |
|
|
14 |
False |
|
|
15 |
>>> u.has_usable_password() |
|
|
16 |
False |
|
|
17 |
>>> u2 = User.objects.create_user('testuser2', 'test2@example.com') |
|
|
18 |
>>> u2.has_usable_password() |
|
|
19 |
False |
|
|
20 |
|
|
|
21 |
>>> u.is_authenticated() |
|
|
22 |
True |
|
|
23 |
>>> u.is_staff |
|
|
24 |
False |
|
|
25 |
>>> u.is_active |
|
|
26 |
True |
|
|
27 |
>>> u.is_superuser |
|
|
28 |
False |
|
|
29 |
|
|
|
30 |
>>> a = AnonymousUser() |
|
|
31 |
>>> a.is_authenticated() |
|
|
32 |
False |
|
|
33 |
>>> a.is_staff |
|
|
34 |
False |
|
|
35 |
>>> a.is_active |
|
|
36 |
False |
|
|
37 |
>>> a.is_superuser |
|
|
38 |
False |
|
|
39 |
>>> a.groups.all() |
|
|
40 |
[] |
|
|
41 |
>>> a.user_permissions.all() |
|
|
42 |
[] |
|
|
43 |
|
|
|
44 |
# superuser tests. |
|
|
45 |
>>> super = User.objects.create_superuser('super', 'super@example.com', 'super') |
|
|
46 |
>>> super.is_superuser |
|
|
47 |
True |
|
|
48 |
>>> super.is_active |
|
|
49 |
True |
|
|
50 |
>>> super.is_staff |
|
|
51 |
True |
|
|
52 |
|
|
|
53 |
# |
|
|
54 |
# Tests for createsuperuser management command. |
|
|
55 |
# It's nearly impossible to test the interactive mode -- a command test helper |
|
|
56 |
# would be needed (and *awesome*) -- so just test the non-interactive mode. |
|
|
57 |
# This covers most of the important validation, but not all. |
|
|
58 |
# |
|
|
59 |
>>> from django.core.management import call_command |
|
|
60 |
|
|
|
61 |
>>> call_command("createsuperuser", interactive=False, username="joe", email="joe@somewhere.org") |
|
|
62 |
Superuser created successfully. |
|
|
63 |
|
|
|
64 |
>>> u = User.objects.get(username="joe") |
|
|
65 |
>>> u.email |
|
|
66 |
u'joe@somewhere.org' |
|
|
67 |
>>> u.password |
|
|
68 |
u'!' |
|
|
69 |
""" |