Handle parameter deserialization errors

This commit is contained in:
Artur Maciag 2018-08-17 11:42:52 +01:00
parent 06e80079fe
commit b75798aa62
2 changed files with 24 additions and 1 deletions

View file

@ -108,7 +108,10 @@ class Parameter(object):
if not self.schema:
return value
deserialized = self.deserialize(value)
try:
deserialized = self.deserialize(value)
except (ValueError, AttributeError) as exc:
raise InvalidParameterValue(str(exc))
try:
return self.schema.unmarshal(deserialized)

View file

@ -297,6 +297,26 @@ class TestPetstore(object):
assert response_result.errors == []
assert response_result.data == data_json
def test_get_pets_parameter_deserialization_error(self, spec):
host_url = 'http://petstore.swagger.io/v1'
path_pattern = '/v1/pets'
query_params = {
'limit': 1,
'tags': 12,
}
request = MockRequest(
host_url, 'GET', '/pets',
path_pattern=path_pattern, args=query_params,
)
with pytest.raises(InvalidParameterValue):
request.get_parameters(spec)
body = request.get_body(spec)
assert body is None
def test_get_pets_wrong_parameter_type(self, spec):
host_url = 'http://petstore.swagger.io/v1'
path_pattern = '/v1/pets'