mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-24 11:09:54 +00:00
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import mock
|
|
import pytest
|
|
|
|
from openapi_core.exceptions import InvalidOperationError
|
|
from openapi_core.paths import Path
|
|
from openapi_core.specs import Spec
|
|
|
|
|
|
class TestSpecs(object):
|
|
|
|
@pytest.fixture
|
|
def path1(self):
|
|
operations = {
|
|
'get': mock.sentinel.path1_get,
|
|
}
|
|
return Path('path1', operations)
|
|
|
|
@pytest.fixture
|
|
def path2(self):
|
|
operations = {
|
|
'post': mock.sentinel.path2_psot,
|
|
}
|
|
return Path('path2', operations)
|
|
|
|
@pytest.fixture
|
|
def spec(self, path1, path2):
|
|
servers = []
|
|
paths = {
|
|
'/path1': path1,
|
|
'/path2': path2,
|
|
}
|
|
return Spec(servers, paths)
|
|
|
|
def test_iteritems(self, spec):
|
|
for path_name in spec.paths.keys():
|
|
assert spec[path_name] ==\
|
|
spec.paths[path_name]
|
|
|
|
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')
|