summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2020-01-19 18:46:54 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2020-03-17 18:06:44 (GMT)
commit62d08f4243c8a9d558d8c9b8cea1e25b7345d8e8 (patch)
tree624bd62830839535f68a0f1535fd3b47b3f863b6
parent5e6226e1678a7feadae66f7a22f2b43925e6b36d (diff)
downloadwelco-62d08f4243c8a9d558d8c9b8cea1e25b7345d8e8.zip
welco-62d08f4243c8a9d558d8c9b8cea1e25b7345d8e8.tar.gz
welco-62d08f4243c8a9d558d8c9b8cea1e25b7345d8e8.tar.bz2
python3: always pass strings to json.loads, for 3.5 compatibility (#39092)
-rw-r--r--tests/test_source_maarch.py8
-rw-r--r--welco/sources/phone/views.py6
2 files changed, 7 insertions, 7 deletions
diff --git a/tests/test_source_maarch.py b/tests/test_source_maarch.py
index 2d908d4..231f1c6 100644
--- a/tests/test_source_maarch.py
+++ b/tests/test_source_maarch.py
@@ -51,7 +51,7 @@ class BaseMock(object):
class MaarchMock(BaseMock):
def list_endpoint(self, url, request):
- self.requests.append(('list_endpoint', url, request, json.loads(request.body)))
+ self.requests.append(('list_endpoint', url, request, json.loads(force_text(request.body))))
return {
'content': json.dumps(self.next_response()),
'headers': {
@@ -62,12 +62,12 @@ class MaarchMock(BaseMock):
list_endpoint.path = '^/rest/res/list$'
def update_external_infos(self, url, request):
- self.requests.append(('update_external_infos', url, request, json.loads(request.body)))
+ self.requests.append(('update_external_infos', url, request, json.loads(force_text(request.body))))
return json.dumps({})
update_external_infos.path = '^/rest/res/externalInfos$'
def update_status(self, url, request):
- self.requests.append(('update_status', url, request, json.loads(request.body)))
+ self.requests.append(('update_status', url, request, json.loads(force_text(request.body))))
return {
'content': json.dumps(self.next_response()),
'headers': {
@@ -78,7 +78,7 @@ class MaarchMock(BaseMock):
update_status.path = '^/rest/res/resource/status$'
def post_courrier(self, url, request):
- self.requests.append(('post_courrier', url, request, json.loads(request.body)))
+ self.requests.append(('post_courrier', url, request, json.loads(force_text(request.body))))
post_courrier.path = '^/rest/res$'
diff --git a/welco/sources/phone/views.py b/welco/sources/phone/views.py
index 7f59ada..9093273 100644
--- a/welco/sources/phone/views.py
+++ b/welco/sources/phone/views.py
@@ -85,7 +85,7 @@ def call_event(request):
'''
logger = logging.getLogger(__name__)
try:
- payload = json.loads(request.body)
+ payload = json.loads(force_text(request.body))
assert isinstance(payload, dict), 'payload is not a JSON object'
assert set(payload.keys()) <= set(['event', 'caller', 'callee', 'data']), \
'payload keys must be "event", "caller", "callee" and optionnaly "data"'
@@ -198,7 +198,7 @@ def take_line(request):
'''
logger = logging.getLogger(__name__)
try:
- payload = json.loads(request.body)
+ payload = json.loads(force_text(request.body))
assert isinstance(payload, dict), 'payload is not a JSON object'
assert list(payload.keys()) == ['callee'], 'payload must have only one key: callee'
except (TypeError, ValueError, AssertionError) as e:
@@ -219,7 +219,7 @@ def release_line(request):
'''
logger = logging.getLogger(__name__)
try:
- payload = json.loads(request.body)
+ payload = json.loads(force_text(request.body))
assert isinstance(payload, dict), 'payload is not a JSON object'
assert list(payload.keys()) == ['callee'], 'payload must have only one key: callee'
except (TypeError, ValueError, AssertionError) as e: