okina: do not crash on 401/403 responses (#26012)
This commit is contained in:
parent
267c147bec
commit
847efa28a9
|
@ -48,6 +48,8 @@ class Okina(BaseResource):
|
|||
headers['Content-Type'] = 'application/json'
|
||||
data = json.dumps(payload)
|
||||
result = self.requests.post(url, data=data, auth=auth, headers=headers)
|
||||
if result.status_code in (401, 403):
|
||||
raise APIError(result.json()['message'], http_status=500)
|
||||
if result_is_json:
|
||||
return result.json()
|
||||
else:
|
||||
|
|
|
@ -1514,6 +1514,15 @@ def test_okina_errors(app, okina):
|
|||
assert resp.json['err'] == 1
|
||||
assert resp.json['data'] == None
|
||||
|
||||
# "normal" 401/403 response, ie problem with login/password
|
||||
for status_code in (401, 403):
|
||||
requests_get.return_value = utils.FakedResponse(content='''{"message": "Invalid credentials",
|
||||
"code": 4, "status" : %d}''' % status_code, status_code=status_code)
|
||||
resp = app.get('/okina/test/cities', status=500)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "Invalid credentials"
|
||||
assert resp.json['data'] is None
|
||||
|
||||
def test_okina_suscribe(app, okina):
|
||||
|
||||
for service in ('subscriber', 'subscription'):
|
||||
|
|
Loading…
Reference in New Issue