2017-09-21 11:51:37 +00:00
|
|
|
import mock
|
|
|
|
import pytest
|
|
|
|
|
2017-10-19 09:34:20 +00:00
|
|
|
from openapi_core.exceptions import InvalidOperationError
|
|
|
|
from openapi_core.paths import Path
|
2017-09-21 11:51:37 +00:00
|
|
|
from openapi_core.specs import Spec
|
|
|
|
|
|
|
|
|
|
|
|
class TestSpecs(object):
|
|
|
|
|
|
|
|
@pytest.fixture
|
2017-10-19 09:34:20 +00:00
|
|
|
def path1(self):
|
2017-10-19 10:11:27 +00:00
|
|
|
operations = {
|
2017-10-19 09:34:20 +00:00
|
|
|
'get': mock.sentinel.path1_get,
|
|
|
|
}
|
|
|
|
return Path('path1', operations)
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def path2(self):
|
2017-10-19 10:11:27 +00:00
|
|
|
operations = {
|
2017-10-19 09:34:20 +00:00
|
|
|
'post': mock.sentinel.path2_psot,
|
|
|
|
}
|
|
|
|
return Path('path2', operations)
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def spec(self, path1, path2):
|
2017-09-21 11:51:37 +00:00
|
|
|
servers = []
|
|
|
|
paths = {
|
2017-10-19 09:34:20 +00:00
|
|
|
'/path1': path1,
|
|
|
|
'/path2': path2,
|
2017-09-21 11:51:37 +00:00
|
|
|
}
|
|
|
|
return Spec(servers, paths)
|
|
|
|
|
|
|
|
def test_iteritems(self, spec):
|
|
|
|
for path_name in spec.paths.keys():
|
|
|
|
assert spec[path_name] ==\
|
|
|
|
spec.paths[path_name]
|
2017-10-19 09:34:20 +00:00
|
|
|
|
|
|
|
def test_valid(self, spec):
|
|
|
|
operation = spec.get_operation('/path1', 'get')
|
|
|
|
|
|
|
|
assert operation == mock.sentinel.path1_get
|
|
|
|
|
|
|
|
def test_invalid_path(self, spec):
|
|
|
|
with pytest.raises(InvalidOperationError):
|
|
|
|
spec.get_operation('/path3', 'get')
|
|
|
|
|
|
|
|
def test_invalid_method(self, spec):
|
|
|
|
with pytest.raises(InvalidOperationError):
|
|
|
|
spec.get_operation('/path1', 'post')
|