From a90b0f0483a01837b4a394663fb5a37ef7dbc0a5 Mon Sep 17 00:00:00 2001 From: OGAWA Hirofumi Date: Wed, 4 Nov 2020 06:03:31 +0900 Subject: [PATCH] Use application/json for upload REST api Upload REST api body is empty, but since this is REST api, so use "Content-Type: application/json" instead of "text/html; charset=utf-8" [We want to use a json response instead of using HTTP headers?] --- src/bepasty/apis/rest.py | 2 ++ src/bepasty/tests/test_rest_server.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bepasty/apis/rest.py b/src/bepasty/apis/rest.py index e9cb34f9..f510208a 100644 --- a/src/bepasty/apis/rest.py +++ b/src/bepasty/apis/rest.py @@ -79,6 +79,8 @@ def update_item(self, item, name): # Make a Response and create Transaction-ID from ItemName response = make_response() + response.headers['Content-Type'] = 'application/json' + response.data = '{}' name_b = name if isinstance(name, bytes_type) else name.encode() trans_id_b = base64.b64encode(name_b) trans_id_s = trans_id_b if isinstance(trans_id_b, str) else trans_id_b.decode() diff --git a/src/bepasty/tests/test_rest_server.py b/src/bepasty/tests/test_rest_server.py index 2dddcfb7..f0a20a35 100644 --- a/src/bepasty/tests/test_rest_server.py +++ b/src/bepasty/tests/test_rest_server.py @@ -183,14 +183,14 @@ def check_data_response(response, meta, data, offset=0, total_size=None, assert data == response.data -def check_json_response(response, metas, check_data=True): - check_response(response, 200, check_data=check_data) +def check_json_response(response, metas, code=200, check_data=True): + check_response(response, code, check_data=check_data) if check_data: assert metas == response.json def check_upload_response(response, code=201, check_data=True): - check_response(response, code, 'text/html; charset=utf-8', check_data) + check_json_response(response, {}, code=code, check_data=check_data) if code == 200: assert len(response.headers[TRANSACTION_ID]) > 0