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-01-19 18:55:23 (GMT)
commit2b3b7c770720cdc5d81dc147b3e0a2db29f1f837 (patch)
treeb492cfcfbcae47f07238d6b924fd494952131156
parentc73074866b6c851b00b514435785845e5b9469fe (diff)
downloadwelco-2b3b7c770720cdc5d81dc147b3e0a2db29f1f837.zip
welco-2b3b7c770720cdc5d81dc147b3e0a2db29f1f837.tar.gz
welco-2b3b7c770720cdc5d81dc147b3e0a2db29f1f837.tar.bz2
python3: always pass strings to json.loads, for 3.5 compatibility
-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: