Test custom values in problem response

This commit is contained in:
Rafael Caricio
2016-04-08 15:12:54 +02:00
parent e73a2194d3
commit e37c994956
4 changed files with 22 additions and 1 deletions

View File

@@ -343,7 +343,7 @@ class Operation(SecureOperation):
logger.debug('... Adding security decorator (%r)', security_decorator, extra=vars(self)) logger.debug('... Adding security decorator (%r)', security_decorator, extra=vars(self))
function = security_decorator(function) function = security_decorator(function)
if UWSGIMetricsCollector.is_available(): if UWSGIMetricsCollector.is_available(): # pragma: no cover
decorator = UWSGIMetricsCollector(self.path, self.method) decorator = UWSGIMetricsCollector(self.path, self.method)
function = decorator(function) function = decorator(function)

View File

@@ -60,3 +60,9 @@ def test_errors(problem_app):
problematic_json = app_client.get( problematic_json = app_client.get(
'/v1.0/json_response_with_undefined_value_to_serialize') # type: flask.Response '/v1.0/json_response_with_undefined_value_to_serialize') # type: flask.Response
assert problematic_json.status_code == 500 assert problematic_json.status_code == 500
custom_problem = app_client.get('/v1.0/customized_problem_response')
assert custom_problem.status_code == 402
problem_body = json.loads(custom_problem.data.decode('utf-8'))
assert 'amount' in problem_body
assert problem_body['amount'] == 23.

View File

@@ -332,3 +332,8 @@ def get_data_as_binary():
def get_invalid_response(): def get_invalid_response():
return {"simple": object()} return {"simple": object()}
def get_custom_problem_response():
return problem(402, "You need to pay", "Missing amount",
ext={'amount': 23.0})

View File

@@ -81,3 +81,13 @@ paths:
responses: responses:
200: 200:
description: Never happens description: Never happens
/customized_problem_response:
get:
description: Custom problem response
operationId: fakeapi.hello.get_custom_problem_response
produces:
- application/json
responses:
200:
description: Custom problem response