Skip to content

Commit

Permalink
Use application/json for upload REST api
Browse files Browse the repository at this point in the history
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?]
  • Loading branch information
OGAWAHirofumi committed Nov 3, 2020
1 parent 434701d commit a90b0f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/bepasty/apis/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/bepasty/tests/test_rest_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a90b0f0

Please sign in to comment.