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

50 lines
1.3 KiB
Python
Raw Normal View History

2018-07-28 20:57:49 +00:00
import pytest
from jsonschema.validators import RefResolver
from openapi_spec_validator.validators import Dereferencer
from openapi_spec_validator import default_handlers
from openapi_core.schema.schemas.registries import SchemaRegistry
class TestSchemaRegistryGetOrCreate(object):
@pytest.fixture
def schema_dict(self):
return {
'type': 'object',
'properties': {
'message': {
'type': 'string',
},
'suberror': {
'$ref': '#/components/schemas/Error',
},
},
}
@pytest.fixture
def spec_dict(self, schema_dict):
return {
'components': {
'schemas': {
'Error': schema_dict,
},
},
}
@pytest.fixture
def dereferencer(self, spec_dict):
spec_resolver = RefResolver('', spec_dict, handlers=default_handlers)
return Dereferencer(spec_resolver)
@pytest.fixture
def schemas_registry(self, dereferencer):
return SchemaRegistry(dereferencer)
def test_recursion(self, schemas_registry, schema_dict):
schema, _ = schemas_registry.get_or_create(schema_dict)
assert schema.properties['suberror'] ==\
schema.properties['suberror'].properties['suberror']