Merge pull request #80 from p1c2u/fix/handle-parameter-deserialization-errors

Handle parameter deserialization errors
This commit is contained in:
A 2018-08-17 13:34:41 +01:00 committed by GitHub
commit da9838b3ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -108,7 +108,10 @@ class Parameter(object):
if not self.schema:
return 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'