Projet

Général

Profil

0001-tests-add-tests-on-user-creation-trough-manager-4307.patch

Benjamin Dauvergne, 19 mai 2020 18:17

Télécharger (8,1 ko)

Voir les différences:

Subject: [PATCH 1/5] tests: add tests on user creation trough manager (#43074)

 tests/test_manager.py      |  11 ++--
 tests/test_user_manager.py | 126 +++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+), 4 deletions(-)
tests/test_manager.py
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 17

  
18
from __future__ import unicode_literals
19

  
18 20
import pytest
19 21
import json
20 22

  
......
236 238
    form.set('password2', 'ABcd1234')
237 239
    response = form.submit()
238 240
    assert User.objects.filter(ou=ou2).count() == 1
239
    assert 'Email already used' in response
241
    assert 'This email address is already in use.' in response
240 242

  
241 243
    # create first user with john.doe2@gmail.com ou OU2 : OK
242 244
    ou_add = app.get(url)
......
253 255
    # john.doe@gmail.com in OU2 : NOK
254 256
    response.form.set('email', 'john.doe@gmail.com')
255 257
    response = form.submit()
256
    assert 'Email already used' in response
258
    assert 'This email address is already in use.' in response
257 259

  
258 260
    # create first user with email john.doe@gmail.com in OU1: NOK
259 261
    settings.A2_EMAIL_IS_UNIQUE = True
......
269 271
    form.set('password2', 'ABcd1234')
270 272
    response = form.submit()
271 273
    assert User.objects.filter(ou=ou1).count() == 0
272
    assert 'Email already used' in response
274
    assert 'This email address is already in use.' in response
275

  
273 276
    form = response.form
274 277
    form.set('email', 'john.doe3@gmail.com')
275 278
    form.set('password1', 'ABcd1234')
......
281 284
    # john.doe@gmail.com in OU2 : NOK
282 285
    response.form.set('email', 'john.doe@gmail.com')
283 286
    response = form.submit()
284
    assert 'Email already used' in response
287
    assert 'This email address is already in use.' in response
285 288

  
286 289
    # check redirect to default ou
287 290
    url1 = reverse('a2-manager-user-add-default-ou')
tests/test_user_manager.py
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
-