~grupoesoc/cubicerp-addons/7.0

« back to all changes in this revision

Viewing changes to report_geraldo/lib/geraldo/site/newsite/django_1_0/django/contrib/auth/tests/forms.py

  • Committer: Cubic ERP
  • Date: 2014-01-07 15:38:09 UTC
  • Revision ID: info@cubicerp.com-20140107153809-4jmif3zoi8rcveve
[ADD] cubicReport

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
FORM_TESTS = """
 
3
>>> from django.contrib.auth.models import User
 
4
>>> from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
 
5
>>> from django.contrib.auth.forms import PasswordChangeForm
 
6
 
 
7
The user already exists.
 
8
 
 
9
>>> user = User.objects.create_user("jsmith", "jsmith@example.com", "test123")
 
10
>>> data = {
 
11
...     'username': 'jsmith',
 
12
...     'password1': 'test123',
 
13
...     'password2': 'test123',
 
14
... }
 
15
>>> form = UserCreationForm(data)
 
16
>>> form.is_valid()
 
17
False
 
18
>>> form["username"].errors
 
19
[u'A user with that username already exists.']
 
20
 
 
21
The username contains invalid data.
 
22
 
 
23
>>> data = {
 
24
...     'username': 'jsmith@example.com',
 
25
...     'password1': 'test123',
 
26
...     'password2': 'test123',
 
27
... }
 
28
>>> form = UserCreationForm(data)
 
29
>>> form.is_valid()
 
30
False
 
31
>>> form["username"].errors
 
32
[u'This value must contain only letters, numbers and underscores.']
 
33
 
 
34
The verification password is incorrect.
 
35
 
 
36
>>> data = {
 
37
...     'username': 'jsmith2',
 
38
...     'password1': 'test123',
 
39
...     'password2': 'test',
 
40
... }
 
41
>>> form = UserCreationForm(data)
 
42
>>> form.is_valid()
 
43
False
 
44
>>> form["password2"].errors
 
45
[u"The two password fields didn't match."]
 
46
 
 
47
The success case.
 
48
 
 
49
>>> data = {
 
50
...     'username': 'jsmith2',
 
51
...     'password1': 'test123',
 
52
...     'password2': 'test123',
 
53
... }
 
54
>>> form = UserCreationForm(data)
 
55
>>> form.is_valid()
 
56
True
 
57
>>> form.save()
 
58
<User: jsmith2>
 
59
 
 
60
The user submits an invalid username.
 
61
 
 
62
>>> data = {
 
63
...     'username': 'jsmith_does_not_exist',
 
64
...     'password': 'test123',
 
65
... }
 
66
 
 
67
>>> form = AuthenticationForm(None, data)
 
68
>>> form.is_valid()
 
69
False
 
70
>>> form.non_field_errors()
 
71
[u'Please enter a correct username and password. Note that both fields are case-sensitive.']
 
72
 
 
73
The user is inactive.
 
74
 
 
75
>>> data = {
 
76
...     'username': 'jsmith',
 
77
...     'password': 'test123',
 
78
... }
 
79
>>> user.is_active = False
 
80
>>> user.save()
 
81
>>> form = AuthenticationForm(None, data)
 
82
>>> form.is_valid()
 
83
False
 
84
>>> form.non_field_errors()
 
85
[u'This account is inactive.']
 
86
 
 
87
>>> user.is_active = True
 
88
>>> user.save()
 
89
 
 
90
The success case
 
91
 
 
92
>>> form = AuthenticationForm(None, data)
 
93
>>> form.is_valid()
 
94
True
 
95
>>> form.non_field_errors()
 
96
[]
 
97
 
 
98
The old password is incorrect.
 
99
 
 
100
>>> data = {
 
101
...     'old_password': 'test',
 
102
...     'new_password1': 'abc123',
 
103
...     'new_password2': 'abc123',
 
104
... }
 
105
>>> form = PasswordChangeForm(user, data)
 
106
>>> form.is_valid()
 
107
False
 
108
>>> form["old_password"].errors
 
109
[u'Your old password was entered incorrectly. Please enter it again.']
 
110
 
 
111
The two new passwords do not match.
 
112
 
 
113
>>> data = {
 
114
...     'old_password': 'test123',
 
115
...     'new_password1': 'abc123',
 
116
...     'new_password2': 'abc',
 
117
... }
 
118
>>> form = PasswordChangeForm(user, data)
 
119
>>> form.is_valid()
 
120
False
 
121
>>> form["new_password2"].errors
 
122
[u"The two password fields didn't match."]
 
123
 
 
124
The success case.
 
125
 
 
126
>>> data = {
 
127
...     'old_password': 'test123',
 
128
...     'new_password1': 'abc123',
 
129
...     'new_password2': 'abc123',
 
130
... }
 
131
>>> form = PasswordChangeForm(user, data)
 
132
>>> form.is_valid()
 
133
True
 
134
 
 
135
"""