From 012eba57a035f3b9f2c8073868d0e9310c7fa7e4 Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Wed, 19 Feb 2020 17:30:51 +0100 Subject: [PATCH] python3: replace DjangoWebtestResponse body with text (#40012) --- hobo/contrib/ozwillo/views.py | 6 +++--- tests/test_manager.py | 8 ++++---- tests/test_matomo_views.py | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/hobo/contrib/ozwillo/views.py b/hobo/contrib/ozwillo/views.py index 00b580b..1862727 100644 --- a/hobo/contrib/ozwillo/views.py +++ b/hobo/contrib/ozwillo/views.py @@ -43,7 +43,7 @@ def valid_signature_required(setting): if signature_header_name in request.META: if request.META[signature_header_name].startswith('sha1='): 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 # http://doc.ozwillo.com/#ref-3-2-1 if received_hmac.lower() != computed_hmac: @@ -73,7 +73,7 @@ def is_ozwillo_enabled(func): @valid_signature_required(setting='OZWILLO_SECRET') def create_publik_instance(request): try: - data = json.loads(request.body) + data = json.loads(request.text) except ValueError: logger.warning(u'ozwillo: received non JSON request') return HttpResponseBadRequest('invalid JSON content') @@ -120,7 +120,7 @@ def create_publik_instance(request): @atomic def delete_publik_instance(request): try: - data = json.loads(request.body) + data = json.loads(request.text) except ValueError: logger.warning(u'ozwillo: received non JSON request') return HttpResponseBadRequest('invalid JSON content') diff --git a/tests/test_manager.py b/tests/test_manager.py index 67e7255..67c74bb 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -43,13 +43,13 @@ def test_unlogged_access(app): def test_access(logged_app): resp = logged_app.get('/', status=200) - assert 'User Profile' not in resp.body - assert 'Services' in resp.body - assert 'Variables' in resp.body + assert 'User Profile' not in resp.text + assert 'Services' in resp.text + assert 'Variables' in resp.text Authentic(title='bar', slug='bar', base_url='http://bar.example.net').save() resp = logged_app.get('/', status=200) - assert 'User Profile' in resp.body + assert 'User Profile' in resp.text def test_logout(logged_app): diff --git a/tests/test_matomo_views.py b/tests/test_matomo_views.py index 8326e8b..3323677 100644 --- a/tests/test_matomo_views.py +++ b/tests/test_matomo_views.py @@ -109,24 +109,24 @@ def test_enable_manual(admin_user): # get matomo's validation page resp = app.get('/visits-tracking/enable-manual', status=200) - assert re.search('') != -1 - assert resp.body.find('') != -1 + assert resp.text.find('Manual configuration.') + assert re.search('') != -1 + assert resp.text.find('') != -1 # update JS code on matomo's home page resp.form['tracking_js'] = '...js_code_2...' resp = resp.form.submit().follow() - assert resp.body.find('Manual configuration.') != -1 - assert re.search('') != -1 - assert resp.body.find('') != -1 - assert resp.body.find('Good respect of user rights') != -1 + assert resp.text.find('Manual configuration.') != -1 + assert re.search('') != -1 + assert resp.text.find('') != -1 + assert resp.text.find('Good respect of user rights') != -1 # check html tags resp.form['tracking_js'] = '' @@ -177,7 +177,7 @@ def test_enable_auto(mocked_post, admin_user): resp3 = resp2.follow() # 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') 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() # 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 - assert resp3.body.find('Excellent respect of user rights') != -1 + assert resp3.text.find('Excellent respect of user rights') != -1 @mock.patch('requests.post') 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() # 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