openapi-core/tests/unit/schema/test_specs.py

51 lines
1.3 KiB
Python
Raw Normal View History

2017-09-21 11:51:37 +00:00
import mock
import pytest
2018-04-18 10:39:03 +00:00
from openapi_core.schema.operations.exceptions import InvalidOperation
2018-04-17 12:18:40 +00:00
from openapi_core.schema.paths.models import Path
from openapi_core.schema.specs.models import Spec
2017-09-21 11:51:37 +00:00
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):
2019-06-18 11:39:07 +00:00
for path_name in spec.paths:
2017-09-21 11:51:37 +00:00
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):
2017-11-03 11:18:48 +00:00
with pytest.raises(InvalidOperation):
2017-10-19 09:34:20 +00:00
spec.get_operation('/path3', 'get')
def test_invalid_method(self, spec):
2017-11-03 11:18:48 +00:00
with pytest.raises(InvalidOperation):
2017-10-19 09:34:20 +00:00
spec.get_operation('/path1', 'post')