Projet

Général

Profil

0001-python3-compare-test-strings-against-DjangoWebtestRe.patch

Paul Marillonnet, 01 avril 2019 19:27

Télécharger (20,9 ko)

Voir les différences:

Subject: [PATCH] python3: compare test strings against
 DjangoWebtestResponse.text (#31169)

 tests/test_auth_oidc.py    | 12 ++---
 tests/test_login.py        |  8 ++--
 tests/test_manager.py      |  4 +-
 tests/test_registration.py | 92 +++++++++++++++++++-------------------
 tests/test_user_manager.py | 14 +++---
 tests/utils.py             |  2 +-
 6 files changed, 66 insertions(+), 66 deletions(-)
tests/test_auth_oidc.py
266 266
    OU.cached.cache.clear()
267 267

  
268 268
    response = app.get('/admin/').maybe_follow()
269
    assert oidc_provider.name in response.content
269
    assert oidc_provider.name in response.text
270 270
    response = response.click(oidc_provider.name)
271 271
    location = urlparse.urlparse(response.location)
272 272
    endpoint = urlparse.urlparse(oidc_provider.authorization_endpoint)
......
372 372
    with utils.check_log(caplog, 'revoked token from OIDC'):
373 373
        with oidc_provider_mock(oidc_provider, oidc_provider_jwkset, code):
374 374
            response = response.click(href='logout')
375
    assert 'https://idp.example.com/logout' in response.content
375
    assert 'https://idp.example.com/logout' in response.text
376 376

  
377 377

  
378 378
def test_show_on_login_page(app, oidc_provider):
......
380 380
    get_providers.cache.clear()
381 381
    has_providers.cache.clear()
382 382
    response = app.get('/login/')
383
    assert 'oidc-a-oididp' in response.content
383
    assert 'oidc-a-oididp' in response.text
384 384

  
385 385
    # do not show this provider on login page anymore
386 386
    oidc_provider.show = False
......
390 390
    get_providers.cache.clear()
391 391
    has_providers.cache.clear()
392 392
    response = app.get('/login/')
393
    assert 'oidc-a-oididp' not in response.content
393
    assert 'oidc-a-oididp' not in response.text
394 394

  
395 395

  
396 396
def test_strategy_find_uuid(app, caplog, code, oidc_provider, oidc_provider_jwkset, login_url,
......
407 407
    assert User.objects.count() == 1
408 408

  
409 409
    response = app.get('/').maybe_follow()
410
    assert oidc_provider.name in response.content
410
    assert oidc_provider.name in response.text
411 411
    response = response.click(oidc_provider.name)
412 412
    location = urlparse.urlparse(response.location)
413 413
    query = check_simple_qs(urlparse.parse_qs(location.query))
......
438 438
    with utils.check_log(caplog, 'revoked token from OIDC'):
439 439
        with oidc_provider_mock(oidc_provider, oidc_provider_jwkset, code, nonce=nonce):
440 440
            response = response.click(href='logout')
441
    assert 'https://idp.example.com/logout' in response.content
441
    assert 'https://idp.example.com/logout' in response.text
442 442

  
443 443

  
444 444
def test_register_issuer(db, app, caplog, oidc_provider_jwkset):
tests/test_login.py
71 71
        response.form.set('username', 'zozo')
72 72
        response.form.set('password', 'zozo')
73 73
        response = response.form.submit('login-password-submit')
74
        assert 'too many login' not in response.content
74
        assert 'too many login' not in response.text
75 75

  
76 76
    settings.A2_LOGIN_EXPONENTIAL_RETRY_TIMEOUT_DURATION = 1.0
77 77
    settings.A2_LOGIN_EXPONENTIAL_RETRY_TIMEOUT_MIN_DURATION = 10.0
......
82 82
        response = response.form.submit('login-password-submit')
83 83
        if 1.8 ** i > 10:
84 84
            break
85
        assert 'too many login' not in response.content, '%s' % i
86
    assert 'too many login' in response.content, '%s' % i
85
        assert 'too many login' not in response.text, '%s' % i
86
    assert 'too many login' in response.text, '%s' % i
87 87

  
88 88

  
89 89
def test_encoded_utf8_in_next_url(app, db):
......
91 91
    response = app.get(url)
92 92
    response = response.follow()
93 93
    needle = 'next=%s' % quote(url)
94
    assert needle in response.content
94
    assert needle in response.text
95 95

  
96 96

  
97 97
def test_session_expire(app, simple_user, freezer):
tests/test_manager.py
123 123
def test_manager_user_detail_by_uuid(app, superuser, simple_user):
124 124
    url = reverse('a2-manager-user-by-uuid-detail', kwargs={'slug': simple_user.uuid})
125 125
    resp = login(app, superuser, url)
126
    assert '<strong>Actions</strong>' in resp.content
126
    assert '<strong>Actions</strong>' in resp.text
127 127
    assert simple_user.first_name.encode('utf-8') in resp.content
128 128

  
129 129

  
130 130
def test_manager_user_edit_by_uuid(app, superuser, simple_user):
131 131
    url = reverse('a2-manager-user-by-uuid-edit', kwargs={'slug': simple_user.uuid})
132 132
    resp = login(app, superuser, url)
133
    assert '<strong>Actions</strong>' not in resp.content
133
    assert '<strong>Actions</strong>' not in resp.text
134 134
    assert simple_user.first_name.encode('utf-8') in resp.content
135 135

  
136 136

  
tests/test_registration.py
37 37
    else:
38 38
        assert response.pyquery('a[href="/"]')
39 39

  
40
    assert '2 days' in response.content
41
    assert 'testbot@entrouvert.com' in response.content
40
    assert '2 days' in response.text
41
    assert 'testbot@entrouvert.com' in response.text
42 42
    assert len(mailoutbox) == 1
43 43

  
44 44
    link = get_link_from_mail(mailoutbox[0])
......
48 48
    response.form.set('password1', 'toto')
49 49
    response.form.set('password2', 'toto')
50 50
    response = response.form.submit()
51
    assert '8 characters' in response.content
51
    assert '8 characters' in response.text
52 52

  
53 53
    # set valid password
54 54
    response.form.set('password1', 'T0==toto')
55 55
    response.form.set('password2', 'T0==toto')
56 56
    response = response.form.submit()
57 57
    if good_next_url:
58
        assert 'You have just created an account.' in response.content
59
        assert next_url in response.content
58
        assert 'You have just created an account.' in response.text
59
        assert next_url in response.text
60 60
    else:
61 61
        assert urlparse(response['Location']).path == '/'
62 62
        response = response.follow()
63
        assert 'You have just created an account.' in response.content
63
        assert 'You have just created an account.' in response.text
64 64
    assert User.objects.count() == 1
65 65
    assert len(mailoutbox) == 2
66 66
    assert 'was successful' in mailoutbox[1].body
......
102 102
    assert urlparse(response['Location']).path == reverse('registration_complete')
103 103

  
104 104
    response = response.follow()
105
    assert '2 days' in response.content
106
    assert 'testbot@entrouvert.com' in response.content
107
    assert '2 days' in response.content
105
    assert '2 days' in response.text
106
    assert 'testbot@entrouvert.com' in response.text
107
    assert '2 days' in response.text
108 108
    assert len(mailoutbox) == 1
109 109

  
110 110
    link = get_link_from_mail(mailoutbox[0])
......
115 115
    response.form.set('password1', 'T0==toto')
116 116
    response.form.set('password2', 'T0==toto')
117 117
    response = response.form.submit()
118
    assert 'You have just created an account.' in response.content
119
    assert next_url in response.content
118
    assert 'You have just created an account.' in response.text
119
    assert next_url in response.text
120 120
    assert len(mailoutbox) == 2
121 121
    assert 'was successful' in mailoutbox[1].body
122 122

  
......
156 156
    assert urlparse(response['Location']).path == reverse('registration_complete')
157 157

  
158 158
    response = response.follow()
159
    assert '2 days' in response.content
160
    assert 'testbot@entrouvert.com' in response.content
159
    assert '2 days' in response.text
160
    assert 'testbot@entrouvert.com' in response.text
161 161
    assert len(mailoutbox) == 1
162 162
    link = get_link_from_mail(mailoutbox[0])
163 163

  
......
179 179
    response.form.set('password2', 'T0==toto')
180 180
    response = response.form.submit()
181 181

  
182
    assert 'Enter a valid value' in response.content
182
    assert 'Enter a valid value' in response.text
183 183

  
184 184
    # check regexp accepts some valid values
185 185
    response.form.set('username', 'abab')
......
188 188
    response = response.form.submit()
189 189
    assert urlparse(response['Location']).path == reverse('auth_homepage')
190 190
    response = response.follow()
191
    assert 'You have just created an account.' in response.content
191
    assert 'You have just created an account.' in response.text
192 192
    assert len(mailoutbox) == 2
193 193
    assert 'was successful' in mailoutbox[1].body
194 194

  
......
209 209
    assert urlparse(response['Location']).path == reverse('registration_complete')
210 210

  
211 211
    response = response.follow()
212
    assert '2 days' in response.content
213
    assert 'testbot@entrouvert.com' in response.content
212
    assert '2 days' in response.text
213
    assert 'testbot@entrouvert.com' in response.text
214 214
    assert len(mailoutbox) == 1
215 215

  
216 216
    link = get_link_from_mail(mailoutbox[0])
......
222 222
    response = response.form.submit()
223 223
    assert urlparse(response['Location']).path == reverse('auth_homepage')
224 224
    response = response.follow()
225
    assert 'You have just created an account.' in response.content
225
    assert 'You have just created an account.' in response.text
226 226
    assert len(mailoutbox) == 2
227 227
    assert 'was successful' in mailoutbox[1].body
228 228

  
......
238 238
    response.form.set('password2', 'T0==toto')
239 239
    response = response.form.submit()
240 240
    assert ('This username is already in use. Please supply a different username.' in
241
            response.content)
241
            response.text)
242 242

  
243 243

  
244 244
def test_email_is_unique(app, db, settings, mailoutbox):
......
255 255
    assert urlparse(response['Location']).path == reverse('registration_complete')
256 256

  
257 257
    response = response.follow()
258
    assert '2 days' in response.content
259
    assert 'testbot@entrouvert.com' in response.content
258
    assert '2 days' in response.text
259
    assert 'testbot@entrouvert.com' in response.text
260 260
    assert len(mailoutbox) == 1
261 261

  
262 262
    link = get_link_from_mail(mailoutbox[0])
......
267 267
    response = response.form.submit()
268 268
    assert urlparse(response['Location']).path == reverse('auth_homepage')
269 269
    response = response.follow()
270
    assert 'You have just created an account.' in response.content
270
    assert 'You have just created an account.' in response.text
271 271
    assert len(mailoutbox) == 2
272 272
    assert 'was successful' in mailoutbox[1].body
273 273

  
......
280 280
    assert urlparse(response['Location']).path == reverse('registration_complete')
281 281

  
282 282
    response = response.follow()
283
    assert '2 days' in response.content
284
    assert 'testbot@entrouvert.com' in response.content
285
    assert not 'This email address is already in use.' in response.content
283
    assert '2 days' in response.text
284
    assert 'testbot@entrouvert.com' in response.text
285
    assert not 'This email address is already in use.' in response.text
286 286
    assert len(mailoutbox) == 3
287 287
    assert 'You already have' in mailoutbox[2].body
288 288

  
......
316 316
    assert urlparse(response['Location']).path == reverse('registration_complete')
317 317

  
318 318
    response = response.follow()
319
    assert '2 days' in response.content
320
    assert 'testbot@entrouvert.com' in response.content
319
    assert '2 days' in response.text
320
    assert 'testbot@entrouvert.com' in response.text
321 321
    assert len(mailoutbox) == 1
322 322

  
323 323
    link = get_link_from_mail(mailoutbox[0])
......
334 334
    response = response.form.submit()
335 335
    assert urlparse(response['Location']).path == reverse('auth_homepage')
336 336
    response = response.follow()
337
    assert 'You have just created an account.' in response.content
337
    assert 'You have just created an account.' in response.text
338 338
    assert len(mailoutbox) == 2
339 339
    assert 'was successful' in mailoutbox[1].body
340 340

  
341 341
    response = app.get(reverse('account_management'))
342 342

  
343
    assert 'Nom' in response.content
344
    assert 'Prénom' not in response.content
343
    assert u'Nom' in response.text
344
    assert u'Prénom' not in response.text
345 345

  
346 346
    response = app.get(reverse('profile_edit'))
347 347
    assert 'edit-profile-profession' in response.form.fields
......
356 356

  
357 357
    response = response.follow()
358 358

  
359
    assert 'Nom' in response.content
360
    assert 'Doe' in response.content
361
    assert 'Profession' not in response.content
362
    assert 'pompier' not in response.content
363
    assert 'Prénom' not in response.content
364
    assert 'John' not in response.content
359
    assert u'Nom' in response.text
360
    assert u'Doe' in response.text
361
    assert u'Profession' not in response.text
362
    assert u'pompier' not in response.text
363
    assert u'Prénom' not in response.text
364
    assert u'John' not in response.text
365 365

  
366 366

  
367 367
def test_registration_email_blacklist(app, settings, db):
......
457 457
    response = response.form.submit()
458 458
    assert urlparse(response['Location']).path == reverse('registration_complete')
459 459
    response = response.follow()
460
    assert '2 days' in response.content
461
    assert 'johndoe@example.com' in response.content
460
    assert '2 days' in response.text
461
    assert 'johndoe@example.com' in response.text
462 462
    assert len(mailoutbox) == 1
463 463

  
464 464

  
......
483 483
        franceconnect=True)
484 484

  
485 485
    response = app.get(url)
486
    assert 'This email address is already in use.' in response.content
486
    assert 'This email address is already in use.' in response.text
487 487

  
488 488

  
489 489
def test_username_is_unique_multiple_objects_returned(app, db, settings, mailoutbox, rf):
......
509 509
        franceconnect=True)
510 510

  
511 511
    response = app.get(url)
512
    assert 'This username is already in use.' in response.content
512
    assert 'This username is already in use.' in response.text
513 513

  
514 514

  
515 515
def test_registration_redirect(app, db, settings, mailoutbox, external_redirect):
......
535 535
    assert urlparse(response['Location']).path == reverse('registration_complete')
536 536

  
537 537
    response = response.follow()
538
    assert '2 days' in response.content
539
    assert 'testbot@entrouvert.com' in response.content
538
    assert '2 days' in response.text
539
    assert 'testbot@entrouvert.com' in response.text
540 540
    assert len(mailoutbox) == 1
541 541

  
542 542
    link = get_link_from_mail(mailoutbox[0])
......
545 545
    response.form.set('password2', 'T0==toto')
546 546
    response = response.form.submit()
547 547

  
548
    assert 'You have just created an account.' in response.content
549
    assert new_next_url in response.content
548
    assert 'You have just created an account.' in response.text
549
    assert new_next_url in response.text
550 550

  
551 551
    assert User.objects.count() == 1
552 552
    assert len(mailoutbox) == 2
......
591 591
    response.form.set('password1', 'T0==toto')
592 592
    response.form.set('password2', 'T0==toto')
593 593
    response = response.form.submit()
594
    assert new_next_url in response.content
594
    assert new_next_url in response.text
595 595

  
596 596

  
597 597
def test_registration_activate_passwords_not_equal(app, db, settings, mailoutbox):
......
608 608
    response.form.set('password1', 'azerty12AZ')
609 609
    response.form.set('password2', 'AAAazerty12AZ')
610 610
    response = response.form.submit()
611
    assert "The two password fields didn&#39;t match." in response.content
611
    assert "The two password fields didn&#39;t match." in response.text
612 612

  
613 613

  
614 614
def test_authentication_method(app, db, rf, hooks):
tests/test_user_manager.py
29 29
    response = login(app, superuser_or_admin,
30 30
                     reverse('a2-manager-user-by-uuid-detail',
31 31
                             kwargs={'slug': text_type(simple_user.uuid)}))
32
    assert 'Change user email' in response.content
32
    assert 'Change user email' in response.text
33 33
    # cannot click it's a submit button :/
34 34
    response = app.get(reverse('a2-manager-user-by-uuid-change-email',
35 35
                               kwargs={'slug': text_type(simple_user.uuid)}))
......
37 37
    response.form.set('new_email', NEW_EMAIL)
38 38
    assert len(mailoutbox) == 0
39 39
    response = response.form.submit().follow()
40
    assert 'A mail was sent to john.doe@example.com to verify it.' in response.content
41
    assert 'Change user email' in response.content
40
    assert 'A mail was sent to john.doe@example.com to verify it.' in response.text
41
    assert 'Change user email' in response.text
42 42
    # cannot click it's a submit button :/
43 43
    assert len(mailoutbox) == 1
44 44
    assert simple_user.email in mailoutbox[0].body
......
51 51
    response = app.get(link).maybe_follow()
52 52
    assert (
53 53
        'your request for changing your email for john.doe@example.com is successful'
54
        in response.content)
54
        in response.text)
55 55
    simple_user.refresh_from_db()
56 56
    assert simple_user.email == NEW_EMAIL
57 57

  
......
68 68
    response = login(app, superuser_or_admin,
69 69
                     reverse('a2-manager-user-by-uuid-detail',
70 70
                             kwargs={'slug': text_type(simple_user.uuid)}))
71
    assert 'Change user email' in response.content
71
    assert 'Change user email' in response.text
72 72
    # cannot click it's a submit button :/
73 73
    response = app.get(reverse('a2-manager-user-by-uuid-change-email',
74 74
                               kwargs={'slug': text_type(simple_user.uuid)}))
75 75
    assert response.form['new_email'].value == simple_user.email
76 76
    assert len(mailoutbox) == 0
77 77
    response = response.form.submit().follow()
78
    assert 'A mail was sent to john.doe@example.com to verify it.' not in response.content
78
    assert 'A mail was sent to john.doe@example.com to verify it.' not in response.text
79 79

  
80 80

  
81 81
def test_search_by_attribute(app, simple_user, admin):
......
128 128
    num_queries = 4 + 4 * (user_count / DEFAULT_BATCH_SIZE + bool(user_count % DEFAULT_BATCH_SIZE))
129 129
    with django_assert_num_queries(num_queries):
130 130
         response = response.click('CSV')
131
    table = list(csv.reader(response.content.splitlines()))
131
    table = list(csv.reader(response.text.splitlines()))
132 132
    assert len(table) == (user_count + 1)
133 133
    assert len(table[0]) == (15 + AT_COUNT)
134 134

  
tests/utils.py
48 48
    assert '_auth_user_id' in app.session
49 49
    response = app.get(reverse('auth_logout')).maybe_follow()
50 50
    response = response.form.submit().maybe_follow()
51
    if 'continue-link' in response.content:
51
    if 'continue-link' in response.text:
52 52
        response = response.click('Continue logout').maybe_follow()
53 53
    assert '_auth_user_id' not in app.session
54 54
    return response
55
-