openapi-core/tests/unit/test_operations.py

48 lines
1.3 KiB
Python
Raw Normal View History

2017-09-21 11:51:37 +00:00
import mock
import pytest
2018-04-17 12:18:40 +00:00
from openapi_core.schema.operations.models import Operation
2017-09-21 11:51:37 +00:00
class TestSchemas(object):
@pytest.fixture
2017-11-06 11:19:18 +00:00
def operation(self):
2017-09-21 11:51:37 +00:00
parameters = {
'parameter_1': mock.sentinel.parameter_1,
'parameter_2': mock.sentinel.parameter_2,
}
2017-11-06 11:19:18 +00:00
return Operation('get', '/path', {}, parameters=parameters)
2017-09-21 11:51:37 +00:00
2017-11-06 11:19:18 +00:00
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']