mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-07 20:37:44 +00:00
Test custom values in problem response
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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})
|
||||||
|
|||||||
10
tests/fixtures/problem/swagger.yaml
vendored
10
tests/fixtures/problem/swagger.yaml
vendored
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user