14 |
14 |
#
|
15 |
15 |
# You should have received a copy of the GNU Affero General Public License
|
16 |
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17 |
|
|
18 |
from __future__ import unicode_literals
|
|
19 |
|
17 |
20 |
import csv
|
18 |
21 |
import re
|
19 |
22 |
import time
|
... | ... | |
42 |
45 |
return set(elt.text for elt in response.pyquery('td.username'))
|
43 |
46 |
|
44 |
47 |
|
|
48 |
def test_create_user(app, superuser):
|
|
49 |
response = login(app, superuser, '/manage/users/')
|
|
50 |
response = response.click('Add user')
|
|
51 |
assert User.objects.count() == 1
|
|
52 |
response.form.set('username', 'john.doe')
|
|
53 |
response.form.set('email', 'john.doe@example.com')
|
|
54 |
response.form.set('first_name', 'Jôhn')
|
|
55 |
response.form.set('last_name', 'Döe')
|
|
56 |
response.form.set('password1', '1234Password')
|
|
57 |
response.form.set('password2', '1234Password')
|
|
58 |
response.form.set('send_password_reset', False)
|
|
59 |
response = response.form.submit(status=302)
|
|
60 |
assert User.objects.count() == 2
|
|
61 |
user = User.objects.exclude(id=superuser.id).get()
|
|
62 |
assert user.ou == get_default_ou()
|
|
63 |
assert user.username == 'john.doe'
|
|
64 |
assert user.email == 'john.doe@example.com'
|
|
65 |
assert user.first_name == 'Jôhn'
|
|
66 |
assert user.last_name == 'Döe'
|
|
67 |
assert user.check_password('1234Password')
|
|
68 |
|
|
69 |
|
|
70 |
def test_create_user_only_name(app, superuser):
|
|
71 |
response = login(app, superuser, '/manage/users/')
|
|
72 |
response = response.click('Add user')
|
|
73 |
assert User.objects.count() == 1
|
|
74 |
response.form.set('first_name', 'Jôhn')
|
|
75 |
response.form.set('last_name', 'Döe')
|
|
76 |
response.form.set('password1', '1234Password')
|
|
77 |
response.form.set('password2', '1234Password')
|
|
78 |
response.form.set('send_password_reset', False)
|
|
79 |
response = response.form.submit(status=302)
|
|
80 |
assert User.objects.count() == 2
|
|
81 |
|
|
82 |
|
|
83 |
def test_create_user_only_email(app, superuser):
|
|
84 |
Attribute.objects.update(required=False)
|
|
85 |
response = login(app, superuser, '/manage/users/')
|
|
86 |
response = response.click('Add user')
|
|
87 |
assert User.objects.count() == 1
|
|
88 |
response.form.set('email', 'john.doe@example.com')
|
|
89 |
response.form.set('password1', '1234Password')
|
|
90 |
response.form.set('password2', '1234Password')
|
|
91 |
response.form.set('send_password_reset', False)
|
|
92 |
response = response.form.submit(status=302)
|
|
93 |
assert User.objects.count() == 2
|
|
94 |
|
|
95 |
|
|
96 |
def test_create_user_only_username(app, superuser):
|
|
97 |
Attribute.objects.update(required=False)
|
|
98 |
response = login(app, superuser, '/manage/users/')
|
|
99 |
response = response.click('Add user')
|
|
100 |
assert User.objects.count() == 1
|
|
101 |
response.form.set('username', 'john.doe')
|
|
102 |
response.form.set('password1', '1234Password')
|
|
103 |
response.form.set('password2', '1234Password')
|
|
104 |
response.form.set('send_password_reset', False)
|
|
105 |
response = response.form.submit(status=302)
|
|
106 |
assert User.objects.count() == 2
|
|
107 |
|
|
108 |
|
|
109 |
def test_create_user_no_identifier(app, superuser):
|
|
110 |
response = login(app, superuser, '/manage/users/')
|
|
111 |
response = response.click('Add user')
|
|
112 |
assert User.objects.count() == 1
|
|
113 |
response.form.set('password1', '1234Password')
|
|
114 |
response.form.set('password2', '1234Password')
|
|
115 |
response.form.set('send_password_reset', False)
|
|
116 |
response = response.form.submit(status=200)
|
|
117 |
assert User.objects.count() == 1
|
|
118 |
assert 'An account needs at least one identifier.' in response
|
|
119 |
|
|
120 |
|
|
121 |
def test_create_user_username_is_unique(app, superuser, settings):
|
|
122 |
settings.A2_USERNAME_IS_UNIQUE = True
|
|
123 |
Attribute.objects.update(required=False)
|
|
124 |
response = login(app, superuser, '/manage/users/')
|
|
125 |
response = response.click('Add user')
|
|
126 |
assert User.objects.count() == 1
|
|
127 |
response.form.set('username', 'john.doe')
|
|
128 |
response.form.set('password1', '1234Password')
|
|
129 |
response.form.set('password2', '1234Password')
|
|
130 |
response.form.set('send_password_reset', False)
|
|
131 |
response = response.form.submit(status=302)
|
|
132 |
assert User.objects.count() == 2
|
|
133 |
|
|
134 |
# try again
|
|
135 |
response = app.get('/manage/users/')
|
|
136 |
response = response.click('Add user')
|
|
137 |
response.form.set('username', 'john.doe')
|
|
138 |
response.form.set('password1', '1234Password')
|
|
139 |
response.form.set('password2', '1234Password')
|
|
140 |
response.form.set('send_password_reset', False)
|
|
141 |
response = response.form.submit(status=200)
|
|
142 |
assert User.objects.count() == 2
|
|
143 |
assert 'This username is already in use' in response
|
|
144 |
|
|
145 |
|
|
146 |
def test_create_user_email_is_unique(app, superuser, settings):
|
|
147 |
settings.A2_EMAIL_IS_UNIQUE = True
|
|
148 |
Attribute.objects.update(required=False)
|
|
149 |
response = login(app, superuser, '/manage/users/')
|
|
150 |
response = response.click('Add user')
|
|
151 |
assert User.objects.count() == 1
|
|
152 |
response.form.set('email', 'john.doe@example.com')
|
|
153 |
response.form.set('password1', '1234Password')
|
|
154 |
response.form.set('password2', '1234Password')
|
|
155 |
response.form.set('send_password_reset', False)
|
|
156 |
response = response.form.submit(status=302)
|
|
157 |
assert User.objects.count() == 2
|
|
158 |
|
|
159 |
# try again
|
|
160 |
response = app.get('/manage/users/')
|
|
161 |
response = response.click('Add user')
|
|
162 |
response.form.set('email', 'john.doe@example.com')
|
|
163 |
response.form.set('password1', '1234Password')
|
|
164 |
response.form.set('password2', '1234Password')
|
|
165 |
response.form.set('send_password_reset', False)
|
|
166 |
response = response.form.submit(status=200)
|
|
167 |
assert User.objects.count() == 2
|
|
168 |
assert 'This email address is already in use' in response
|
|
169 |
|
|
170 |
|
45 |
171 |
def test_manager_user_change_email(app, superuser_or_admin, simple_user, mailoutbox):
|
46 |
172 |
ou = get_default_ou()
|
47 |
173 |
ou.validate_emails = True
|
48 |
|
-
|