tests: use resp.text (#36515)
This commit is contained in:
parent
e4bd408044
commit
1ea19f1c74
File diff suppressed because it is too large
Load Diff
|
@ -2152,24 +2152,24 @@ def test_api_ics_formdata(pub, local_user, ics_data):
|
|||
# check it gets the data
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar', user=local_user))
|
||||
resp2 = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar/', user=local_user))
|
||||
assert remove_dtstamp(resp.body) == remove_dtstamp(resp2.body)
|
||||
assert remove_dtstamp(resp.text) == remove_dtstamp(resp2.text)
|
||||
assert resp.headers['content-type'] == 'text/calendar; charset=utf-8'
|
||||
assert resp.body.count('BEGIN:VEVENT') == 10
|
||||
assert resp.text.count('BEGIN:VEVENT') == 10
|
||||
# check that description contains form name, display id, workflow status,
|
||||
# backoffice url and attached user
|
||||
pattern = re.compile('DESCRIPTION:testé \| 1-\d+ \| New', re.MULTILINE)
|
||||
m = pattern.findall(resp.body)
|
||||
pattern = re.compile(u'DESCRIPTION:testé \| 1-\d+ \| New', re.MULTILINE)
|
||||
m = pattern.findall(resp.text)
|
||||
assert len(m) == 10
|
||||
assert resp.body.count('Jean Darmette') == 10
|
||||
assert resp.body.count('DTSTART') == 10
|
||||
assert resp.text.count('Jean Darmette') == 10
|
||||
assert resp.text.count('DTSTART') == 10
|
||||
|
||||
# check with a filter
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar?filter=done', user=local_user))
|
||||
assert resp.body.count('BEGIN:VEVENT') == 20
|
||||
pattern = re.compile('DESCRIPTION:testé \| 1-\d+ \| Finished', re.MULTILINE)
|
||||
m = pattern.findall(resp.body)
|
||||
assert resp.text.count('BEGIN:VEVENT') == 20
|
||||
pattern = re.compile(u'DESCRIPTION:testé \| 1-\d+ \| Finished', re.MULTILINE)
|
||||
m = pattern.findall(resp.text)
|
||||
assert len(m) == 20
|
||||
assert resp.body.count('Jean Darmette') == 20
|
||||
assert resp.text.count('Jean Darmette') == 20
|
||||
|
||||
# check 404 on erroneous field var
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/xxx', user=local_user), status=404)
|
||||
|
@ -2183,9 +2183,9 @@ def test_api_ics_formdata(pub, local_user, ics_data):
|
|||
# check ics data with start and end varnames
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar/foobar2', user=local_user))
|
||||
resp2 = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar/foobar2/', user=local_user))
|
||||
assert remove_dtstamp(resp.body) == remove_dtstamp(resp2.body)
|
||||
assert resp.body.count('DTSTART') == 10
|
||||
assert resp.body.count('DTEND') == 10
|
||||
assert remove_dtstamp(resp.text) == remove_dtstamp(resp2.text)
|
||||
assert resp.text.count('DTSTART') == 10
|
||||
assert resp.text.count('DTEND') == 10
|
||||
|
||||
def test_api_ics_formdata_http_auth(pub, local_user, ics_data):
|
||||
role = Role.select()[0]
|
||||
|
@ -2211,7 +2211,7 @@ def test_api_ics_formdata_http_auth(pub, local_user, ics_data):
|
|||
# check it gets the data
|
||||
resp = app.get('/api/forms/test/ics/foobar?email=%s' % local_user.email, status=200)
|
||||
assert resp.headers['content-type'] == 'text/calendar; charset=utf-8'
|
||||
assert resp.body.count('BEGIN:VEVENT') == 10
|
||||
assert resp.text.count('BEGIN:VEVENT') == 10
|
||||
|
||||
# check it fails with a different password
|
||||
app.authorization = ('Basic', ('user', 'password2'))
|
||||
|
@ -2600,7 +2600,7 @@ def test_reverse_geocoding(pub):
|
|||
get_app(pub).get('/api/reverse-geocoding', status=400)
|
||||
resp = get_app(pub).get('/api/reverse-geocoding?lat=0&lon=0')
|
||||
assert resp.content_type == 'application/json'
|
||||
assert resp.body == json.dumps({'address': 'xxx'})
|
||||
assert resp.text == json.dumps({'address': 'xxx'})
|
||||
assert urlopen.call_args[0][0] == 'https://nominatim.entrouvert.org/reverse?zoom=18&format=json&addressdetails=1&lat=0&lon=0&accept-language=en'
|
||||
|
||||
pub.site_options.add_section('options')
|
||||
|
@ -2687,7 +2687,7 @@ def test_geocoding(pub):
|
|||
get_app(pub).get('/api/geocoding', status=400)
|
||||
resp = get_app(pub).get('/api/geocoding?q=test')
|
||||
assert resp.content_type == 'application/json'
|
||||
assert resp.body == json.dumps([{'lat': 0, 'lon': 0}])
|
||||
assert resp.text == json.dumps([{'lat': 0, 'lon': 0}])
|
||||
assert urlopen.call_args[0][0] == 'https://nominatim.entrouvert.org/search?format=json&q=test&accept-language=en'
|
||||
|
||||
pub.site_options.add_section('options')
|
||||
|
|
|
@ -38,16 +38,16 @@ def test_login_logout(pub):
|
|||
resp = login(get_app(pub), username='foo', password='foo').get('/')
|
||||
resp = resp.click('Logout')
|
||||
resp = resp.follow()
|
||||
assert resp.body == resp_initial.body
|
||||
assert resp.text == resp_initial.text
|
||||
|
||||
def test_register_account(pub):
|
||||
resp = get_app(pub).get('/').click('Login').follow()
|
||||
assert not 'register' in resp.body
|
||||
assert not 'register' in resp.text
|
||||
|
||||
pub.cfg['identities'] = {'creation': 'self'}
|
||||
pub.write_cfg()
|
||||
resp = get_app(pub).get('/').click('Login').follow()
|
||||
assert 'register'in resp.body
|
||||
assert 'register'in resp.text
|
||||
resp = resp.click('New Account page')
|
||||
resp.form['username'] = 'foobar'
|
||||
assert resp.form.submit().location == 'http://example.net/login/'
|
||||
|
@ -61,12 +61,12 @@ def test_login_2auth(pub_2auth):
|
|||
resp.form['username'] = 'foo'
|
||||
resp.form['password'] = 'foo'
|
||||
resp = resp.form.submit().follow()
|
||||
assert '/logout' in resp.body
|
||||
assert '/logout' in resp.text
|
||||
|
||||
resp = get_app(pub_2auth).get('/').click('Login').follow()
|
||||
resp.form['method'] = 'SAML identity provider'
|
||||
resp = resp.form.submit().follow()
|
||||
assert 'SSO support is not yet configured' in resp.body
|
||||
assert 'SSO support is not yet configured' in resp.text
|
||||
|
||||
def test_register_2auth(pub_2auth):
|
||||
pub_2auth.cfg['identities'] = {'creation': 'self'}
|
||||
|
@ -74,7 +74,7 @@ def test_register_2auth(pub_2auth):
|
|||
resp = get_app(pub_2auth).get('/register/')
|
||||
resp.form['method'] = 'Username / password'
|
||||
resp = resp.form.submit().follow()
|
||||
assert 'New Account' in resp.body
|
||||
assert 'New Account' in resp.text
|
||||
|
||||
resp = get_app(pub_2auth).get('/register/')
|
||||
resp.form['method'] = 'SAML identity provider'
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -264,7 +264,7 @@ def test_fc_settings():
|
|||
resp.forms[0]['methods$elementfc'].checked = True
|
||||
resp = resp.forms[0].submit().follow()
|
||||
|
||||
assert 'FranceConnect' in resp.body
|
||||
assert 'FranceConnect' in resp.text
|
||||
resp = resp.click('FranceConnect')
|
||||
resp = resp.forms[0].submit('user_field_mappings$add_element')
|
||||
resp = resp.forms[0].submit('user_field_mappings$add_element')
|
||||
|
@ -321,7 +321,7 @@ def test_fc_settings_no_user_profile():
|
|||
resp.forms[0]['methods$elementfc'].checked = True
|
||||
resp = resp.forms[0].submit().follow()
|
||||
|
||||
assert 'FranceConnect' in resp.body
|
||||
assert 'FranceConnect' in resp.text
|
||||
resp = resp.click('FranceConnect')
|
||||
resp = resp.forms[0].submit('user_field_mappings$add_element')
|
||||
resp = resp.forms[0].submit('user_field_mappings$add_element')
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -42,7 +42,7 @@ def test_no_user_registration(pub):
|
|||
def test_link_on_login_page(pub):
|
||||
app = get_app(pub)
|
||||
page = app.get('/login/')
|
||||
assert '/register/' in page.body
|
||||
assert '/register/' in page.text
|
||||
|
||||
def test_no_password(pub):
|
||||
app = get_app(pub)
|
||||
|
@ -61,7 +61,7 @@ def test_user_registration_mismatch(pub):
|
|||
register_form['password$pwd1'] = 'bar'
|
||||
register_form['password$pwd2'] = 'baz'
|
||||
resp = register_form.submit()
|
||||
assert 'Passwords do not match' in resp.body
|
||||
assert 'Passwords do not match' in resp.text
|
||||
|
||||
def do_user_registration(pub, username='foo', password='bar'):
|
||||
initial_user_count = pub.user_class.count()
|
||||
|
@ -169,7 +169,7 @@ def test_user_login(pub):
|
|||
resp.forms[0]['username'] = 'foo'
|
||||
resp.forms[0]['password'] = 'foo'
|
||||
resp = resp.forms[0].submit()
|
||||
assert 'Invalid credentials' in resp.body
|
||||
assert 'Invalid credentials' in resp.text
|
||||
|
||||
# correct passwod
|
||||
app = get_app(pub)
|
||||
|
@ -190,7 +190,7 @@ def test_forgotten(pub, emails):
|
|||
|
||||
app = get_app(pub)
|
||||
resp = app.get('/login/')
|
||||
assert '/ident/password/forgotten' in resp.body
|
||||
assert '/ident/password/forgotten' in resp.text
|
||||
|
||||
resp = app.get('/ident/password/forgotten')
|
||||
resp.forms[0]['username'] = 'bar' # this account doesn't exist
|
||||
|
@ -209,7 +209,7 @@ def test_forgotten(pub, emails):
|
|||
resp = app.get('/ident/password/forgotten')
|
||||
resp.forms[0]['username'] = 'foo'
|
||||
resp = resp.forms[0].submit()
|
||||
assert 'A token for changing your password has been emailed to you.' in resp.body
|
||||
assert 'A token for changing your password has been emailed to you.' in resp.text
|
||||
|
||||
assert emails.get('Change Password Request')
|
||||
assert emails.get('Change Password Request')['to'] == 'foo@localhost'
|
||||
|
@ -221,16 +221,16 @@ def test_forgotten(pub, emails):
|
|||
|
||||
# cancel request
|
||||
resp = app.get(confirm_urls[1])
|
||||
assert 'Your request has been cancelled' in resp.body
|
||||
assert 'Your request has been cancelled' in resp.text
|
||||
|
||||
resp = app.get(confirm_urls[1])
|
||||
assert 'The token you submitted does not exist' in resp.body
|
||||
assert 'The token you submitted does not exist' in resp.text
|
||||
|
||||
# new forgotten request
|
||||
resp = app.get('/ident/password/forgotten')
|
||||
resp.forms[0]['username'] = 'foo'
|
||||
resp = resp.forms[0].submit()
|
||||
assert 'A token for changing your password has been emailed to you.' in resp.body
|
||||
assert 'A token for changing your password has been emailed to you.' in resp.text
|
||||
|
||||
body = emails.get('Change Password Request')['payload']
|
||||
confirm_urls = re.findall(r'http://.*\w', body)
|
||||
|
@ -238,7 +238,7 @@ def test_forgotten(pub, emails):
|
|||
assert 'a=cxlpw' in confirm_urls[1]
|
||||
|
||||
resp = app.get(confirm_urls[0])
|
||||
assert 'New password sent by email' in resp.body
|
||||
assert 'New password sent by email' in resp.text
|
||||
assert emails.get('Your new password')
|
||||
|
||||
# check new password is working
|
||||
|
@ -256,7 +256,7 @@ def test_forgotten(pub, emails):
|
|||
resp = app.get('/ident/password/forgotten')
|
||||
resp.forms[0]['username'] = 'foo'
|
||||
resp = resp.forms[0].submit()
|
||||
assert 'A token for changing your password has been emailed to you.' in resp.body
|
||||
assert 'A token for changing your password has been emailed to you.' in resp.text
|
||||
|
||||
body = emails.get('Change Password Request')['payload']
|
||||
confirm_urls = re.findall(r'http://.*\w', body)
|
||||
|
|
|
@ -157,15 +157,15 @@ def test_static_directories():
|
|||
assert get_app(pub).get('/static/xstatic/jquery.js')
|
||||
assert get_app(pub).get('/static/xstatic/jquery-ui.js')
|
||||
|
||||
assert 'Directory listing denied' in get_app(pub).get('/static/css/').body
|
||||
assert 'Directory listing denied' in get_app(pub).get('/static/css/').text
|
||||
assert get_app(pub).get('/static/xxx', status=404)
|
||||
|
||||
def test_jquery_debug_mode():
|
||||
FormDef.wipe()
|
||||
create_formdef()
|
||||
resp = get_app(pub).get('/category1/test-formdef-1/')
|
||||
assert 'jquery.min.js' in resp.body
|
||||
assert 'jquery.min.js' in resp.text
|
||||
pub.cfg['debug'] = {'debug_mode': True}
|
||||
pub.write_cfg()
|
||||
resp = get_app(pub).get('/category1/test-formdef-1/')
|
||||
assert 'jquery.js' in resp.body
|
||||
assert 'jquery.js' in resp.text
|
||||
|
|
|
@ -174,13 +174,13 @@ def test_session_substitution_variables(pub, user, app):
|
|||
resp = app.get('/foobar/')
|
||||
assert pub.session_manager.session_class.count() == 1
|
||||
session_id = pub.session_manager.session_class.select()[0].id
|
||||
assert 'Hello %s' % session_id in resp.body
|
||||
assert 'Hello %s' % session_id in resp.text
|
||||
|
||||
login(app, username='foo', password='foo')
|
||||
assert pub.session_manager.session_class.count() == 2
|
||||
session_id = [x for x in pub.session_manager.session_class.select() if x.id != session_id][0].id
|
||||
resp = app.get('/foobar/')
|
||||
assert 'Hello %s' % session_id in resp.body
|
||||
assert 'Hello %s' % session_id in resp.text
|
||||
|
||||
def test_session_substitution_variables_1st_page_condition(pub, user, app):
|
||||
pub.session_manager.session_class.wipe()
|
||||
|
@ -198,4 +198,4 @@ def test_session_substitution_variables_1st_page_condition(pub, user, app):
|
|||
resp = app.get('/foobar/')
|
||||
assert pub.session_manager.session_class.count() == 1
|
||||
session_id = pub.session_manager.session_class.select()[0].id
|
||||
assert 'COM1' in resp.body
|
||||
assert 'COM1' in resp.text
|
||||
|
|
Loading…
Reference in New Issue