python3: replace DjangoWebtestResponse body with text (#40012)
This commit is contained in:
parent
7ca962ba6b
commit
012eba57a0
|
@ -43,7 +43,7 @@ def valid_signature_required(setting):
|
||||||
if signature_header_name in request.META:
|
if signature_header_name in request.META:
|
||||||
if request.META[signature_header_name].startswith('sha1='):
|
if request.META[signature_header_name].startswith('sha1='):
|
||||||
algo, received_hmac = request.META[signature_header_name].rsplit('=')
|
algo, received_hmac = request.META[signature_header_name].rsplit('=')
|
||||||
computed_hmac = hmac.new(api_secret, request.body, sha1).hexdigest()
|
computed_hmac = hmac.new(api_secret, request.content, sha1).hexdigest()
|
||||||
# the received hmac is uppercase according to
|
# the received hmac is uppercase according to
|
||||||
# http://doc.ozwillo.com/#ref-3-2-1
|
# http://doc.ozwillo.com/#ref-3-2-1
|
||||||
if received_hmac.lower() != computed_hmac:
|
if received_hmac.lower() != computed_hmac:
|
||||||
|
@ -73,7 +73,7 @@ def is_ozwillo_enabled(func):
|
||||||
@valid_signature_required(setting='OZWILLO_SECRET')
|
@valid_signature_required(setting='OZWILLO_SECRET')
|
||||||
def create_publik_instance(request):
|
def create_publik_instance(request):
|
||||||
try:
|
try:
|
||||||
data = json.loads(request.body)
|
data = json.loads(request.text)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warning(u'ozwillo: received non JSON request')
|
logger.warning(u'ozwillo: received non JSON request')
|
||||||
return HttpResponseBadRequest('invalid JSON content')
|
return HttpResponseBadRequest('invalid JSON content')
|
||||||
|
@ -120,7 +120,7 @@ def create_publik_instance(request):
|
||||||
@atomic
|
@atomic
|
||||||
def delete_publik_instance(request):
|
def delete_publik_instance(request):
|
||||||
try:
|
try:
|
||||||
data = json.loads(request.body)
|
data = json.loads(request.text)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warning(u'ozwillo: received non JSON request')
|
logger.warning(u'ozwillo: received non JSON request')
|
||||||
return HttpResponseBadRequest('invalid JSON content')
|
return HttpResponseBadRequest('invalid JSON content')
|
||||||
|
|
|
@ -43,13 +43,13 @@ def test_unlogged_access(app):
|
||||||
|
|
||||||
def test_access(logged_app):
|
def test_access(logged_app):
|
||||||
resp = logged_app.get('/', status=200)
|
resp = logged_app.get('/', status=200)
|
||||||
assert 'User Profile' not in resp.body
|
assert 'User Profile' not in resp.text
|
||||||
assert 'Services' in resp.body
|
assert 'Services' in resp.text
|
||||||
assert 'Variables' in resp.body
|
assert 'Variables' in resp.text
|
||||||
|
|
||||||
Authentic(title='bar', slug='bar', base_url='http://bar.example.net').save()
|
Authentic(title='bar', slug='bar', base_url='http://bar.example.net').save()
|
||||||
resp = logged_app.get('/', status=200)
|
resp = logged_app.get('/', status=200)
|
||||||
assert 'User Profile' in resp.body
|
assert 'User Profile' in resp.text
|
||||||
|
|
||||||
|
|
||||||
def test_logout(logged_app):
|
def test_logout(logged_app):
|
||||||
|
|
|
@ -109,24 +109,24 @@ def test_enable_manual(admin_user):
|
||||||
|
|
||||||
# get matomo's validation page
|
# get matomo's validation page
|
||||||
resp = app.get('/visits-tracking/enable-manual', status=200)
|
resp = app.get('/visits-tracking/enable-manual', status=200)
|
||||||
assert re.search('<textarea.* name="tracking_js"', resp.body)
|
assert re.search('<textarea.* name="tracking_js"', resp.text)
|
||||||
|
|
||||||
# validate and get matomo's home page
|
# validate and get matomo's home page
|
||||||
resp.form['tracking_js'] = '...js_code_1...'
|
resp.form['tracking_js'] = '...js_code_1...'
|
||||||
resp = resp.form.submit().follow()
|
resp = resp.form.submit().follow()
|
||||||
assert resp.body.find('Manual configuration.')
|
assert resp.text.find('Manual configuration.')
|
||||||
assert re.search('<textarea.* name="tracking_js"', resp.body)
|
assert re.search('<textarea.* name="tracking_js"', resp.text)
|
||||||
assert resp.body.find('...js_code_1...</textarea>') != -1
|
assert resp.text.find('...js_code_1...</textarea>') != -1
|
||||||
assert resp.body.find('<button class="submit-button">Save</button>') != -1
|
assert resp.text.find('<button class="submit-button">Save</button>') != -1
|
||||||
|
|
||||||
# update JS code on matomo's home page
|
# update JS code on matomo's home page
|
||||||
resp.form['tracking_js'] = '...js_code_2...'
|
resp.form['tracking_js'] = '...js_code_2...'
|
||||||
resp = resp.form.submit().follow()
|
resp = resp.form.submit().follow()
|
||||||
assert resp.body.find('Manual configuration.') != -1
|
assert resp.text.find('Manual configuration.') != -1
|
||||||
assert re.search('<textarea.* name="tracking_js"', resp.body)
|
assert re.search('<textarea.* name="tracking_js"', resp.text)
|
||||||
assert resp.body.find('...js_code_2...</textarea>') != -1
|
assert resp.text.find('...js_code_2...</textarea>') != -1
|
||||||
assert resp.body.find('<button class="submit-button">Save</button>') != -1
|
assert resp.text.find('<button class="submit-button">Save</button>') != -1
|
||||||
assert resp.body.find('Good respect of user rights') != -1
|
assert resp.text.find('Good respect of user rights') != -1
|
||||||
|
|
||||||
# check html tags
|
# check html tags
|
||||||
resp.form['tracking_js'] = '<script>...js_code_2...</script>'
|
resp.form['tracking_js'] = '<script>...js_code_2...</script>'
|
||||||
|
@ -177,7 +177,7 @@ def test_enable_auto(mocked_post, admin_user):
|
||||||
resp3 = resp2.follow()
|
resp3 = resp2.follow()
|
||||||
|
|
||||||
# expect the CNIL compliance message is displayed
|
# expect the CNIL compliance message is displayed
|
||||||
assert resp3.body.find('Excellent respect of user rights') != -1
|
assert resp3.text.find('Excellent respect of user rights') != -1
|
||||||
|
|
||||||
@mock.patch('requests.post')
|
@mock.patch('requests.post')
|
||||||
def test_enable_auto_warning(mocked_post, admin_user):
|
def test_enable_auto_warning(mocked_post, admin_user):
|
||||||
|
@ -201,10 +201,10 @@ def test_enable_auto_warning(mocked_post, admin_user):
|
||||||
resp3 = resp2.follow()
|
resp3 = resp2.follow()
|
||||||
|
|
||||||
# expect 'ping fails' warning
|
# expect 'ping fails' warning
|
||||||
assert resp3.body.find('class="warning">ping: ping fails') != -1
|
assert resp3.text.find('class="warning">ping: ping fails') != -1
|
||||||
|
|
||||||
# expect the CNIL compliance message is displayed
|
# expect the CNIL compliance message is displayed
|
||||||
assert resp3.body.find('Excellent respect of user rights') != -1
|
assert resp3.text.find('Excellent respect of user rights') != -1
|
||||||
|
|
||||||
@mock.patch('requests.post')
|
@mock.patch('requests.post')
|
||||||
def test_enable_auto_error(mocked_post, admin_user):
|
def test_enable_auto_error(mocked_post, admin_user):
|
||||||
|
@ -228,4 +228,4 @@ def test_enable_auto_error(mocked_post, admin_user):
|
||||||
resp3 = resp2.follow()
|
resp3 = resp2.follow()
|
||||||
|
|
||||||
# expect a Django error message is displayed
|
# expect a Django error message is displayed
|
||||||
assert resp3.body.find('class="error">matomo: get_javascript_tag fails') != -1
|
assert resp3.text.find('class="error">matomo: get_javascript_tag fails') != -1
|
||||||
|
|
Loading…
Reference in New Issue