api: fixes and changes to always return content type in API

- few tweeks here and there
This commit is contained in:
RhodeCode Admin 2023-03-28 10:21:23 +02:00
parent 745c3af99f
commit 047254866b
6 changed files with 67 additions and 58 deletions

View file

@ -63,7 +63,7 @@ class TestApi(object):
def test_api_missing_non_optional_param_args_null(self):
id_, params = build_data(self.apikey, 'get_repo')
params = params.replace('"args": {}', '"args": null')
params = params.replace(b'"args": {}', b'"args": null')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
@ -71,7 +71,7 @@ class TestApi(object):
def test_api_missing_non_optional_param_args_bad(self):
id_, params = build_data(self.apikey, 'get_repo')
params = params.replace('"args": {}', '"args": 1')
params = params.replace(b'"args": {}', b'"args": 1')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
@ -111,13 +111,13 @@ class TestApi(object):
def test_api_args_is_null(self):
__, params = build_data(self.apikey, 'get_users', )
params = params.replace('"args": {}', '"args": null')
params = params.replace(b'"args": {}', b'"args": null')
response = api_call(self.app, params)
assert response.status == '200 OK'
def test_api_args_is_bad(self):
__, params = build_data(self.apikey, 'get_users', )
params = params.replace('"args": {}', '"args": 1')
params = params.replace(b'"args": {}', b'"args": 1')
response = api_call(self.app, params)
assert response.status == '200 OK'

View file

@ -86,7 +86,8 @@ def build_data(apikey, method, **kw):
def api_call(app, params, status=None):
response = app.post(
API_URL, content_type='application/json', params=params, status=status)
API_URL, content_type='application/json', params=params, status=status,
headers=[('Content-Type', 'application/json')])
return response