Merge pull request #173 from gjo/feature/webob

webob support
This commit is contained in:
A 2020-01-13 10:43:32 +00:00 committed by GitHub
commit 4b712cb2b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View file

@ -87,6 +87,8 @@ class Parameter(object):
return self.schema.default
if self.aslist and self.explode:
if hasattr(location, 'getall'):
return location.getall(self.name)
return location.getlist(self.name)
return location[self.name]

View file

@ -4,3 +4,4 @@ pytest-flake8
pytest-cov==2.5.1
flask
django==2.2.8; python_version>="3.0"
webob

View file

@ -37,6 +37,7 @@ tests_require =
pytest-flake8
pytest-cov
flask
webob
[options.packages.find]
exclude =

View file

@ -94,7 +94,7 @@ class TestRequestValidator(object):
def test_get_pets(self, validator):
request = MockRequest(
self.host_url, 'get', '/v1/pets',
path_pattern='/v1/pets', args={'limit': '10'},
path_pattern='/v1/pets', args={'limit': '10', 'ids': ['1', '2']},
)
result = validator.validate(request)
@ -106,6 +106,31 @@ class TestRequestValidator(object):
'limit': 10,
'page': 1,
'search': '',
'ids': [1, 2],
},
)
def test_get_pets_webob(self, validator):
from webob.multidict import GetDict
request = MockRequest(
self.host_url, 'get', '/v1/pets',
path_pattern='/v1/pets',
)
request.parameters.query = GetDict(
[('limit', '5'), ('ids', '1'), ('ids', '2')],
{}
)
result = validator.validate(request)
assert result.errors == []
assert result.body is None
assert result.parameters == RequestParameters(
query={
'limit': 5,
'page': 1,
'search': '',
'ids': [1, 2],
},
)