mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
Response ranges support
This commit is contained in:
parent
1a05e7da89
commit
b0c4141f64
2 changed files with 39 additions and 6 deletions
|
@ -34,6 +34,12 @@ class Operation(object):
|
|||
try:
|
||||
return self.responses[http_status]
|
||||
except KeyError:
|
||||
# try range
|
||||
http_status_range = '{0}XX'.format(http_status[0])
|
||||
if http_status_range in self.responses:
|
||||
return self.responses[http_status_range]
|
||||
|
||||
|
||||
if 'default' not in self.responses:
|
||||
raise InvalidResponse(
|
||||
"Unknown response http status {0}".format(http_status))
|
||||
|
|
|
@ -7,14 +7,41 @@ from openapi_core.operations import Operation
|
|||
class TestSchemas(object):
|
||||
|
||||
@pytest.fixture
|
||||
def oepration(self):
|
||||
def operation(self):
|
||||
parameters = {
|
||||
'parameter_1': mock.sentinel.parameter_1,
|
||||
'parameter_2': mock.sentinel.parameter_2,
|
||||
}
|
||||
return Operation('get', '/path', parameters=parameters)
|
||||
return Operation('get', '/path', {}, parameters=parameters)
|
||||
|
||||
@property
|
||||
def test_iteritems(self, oepration):
|
||||
for name in oepration.parameters.keys():
|
||||
assert oepration[name] == oepration.parameters[name]
|
||||
def test_iteritems(self, operation):
|
||||
for name in operation.parameters.keys():
|
||||
assert operation[name] == operation.parameters[name]
|
||||
|
||||
|
||||
class TestResponses(object):
|
||||
|
||||
@pytest.fixture
|
||||
def operation(self):
|
||||
responses = {
|
||||
'200': mock.sentinel.response_200,
|
||||
'299': mock.sentinel.response_299,
|
||||
'2XX': mock.sentinel.response_2XX,
|
||||
'default': mock.sentinel.response_default,
|
||||
}
|
||||
return Operation('get', '/path', responses, parameters={})
|
||||
|
||||
def test_default(self, operation):
|
||||
response = operation.get_response()
|
||||
|
||||
assert response == operation.responses['default']
|
||||
|
||||
def test_range(self, operation):
|
||||
response = operation.get_response('201')
|
||||
|
||||
assert response == operation.responses['2XX']
|
||||
|
||||
def test_exact(self, operation):
|
||||
response = operation.get_response('200')
|
||||
|
||||
assert response == operation.responses['200']
|
||||
|
|
Loading…
Reference in a new issue