def test_modelresolver__get_object_lang_type(schema, result): resolver = ModelResolver({}) resolved_type = resolver._get_object_lang_type(schema) assert resolved_type.container == ContainerType.DICT item_type = resolved_type.type assert item_type.container == ContainerType.PRIMITIVE assert item_type.type == result
def test_modelresolver__schema_to_lang_type_undef(): # see test_modelresolver__get_object_lang_type_no_item_type resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type({}) assert resolved_type.container == ContainerType.DICT item_type = resolved_type.type assert item_type.container == ContainerType.PRIMITIVE assert item_type.type == UNDEFINED
def test_modelresolver__schema_to_lang_type_array(): # see test_modelresolver__get_array_lang_type_no_item_type resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type({"type": "array"}) assert resolved_type.container == ContainerType.LIST item_type = resolved_type.type assert item_type.container == ContainerType.PRIMITIVE assert item_type.type == UNDEFINED
def test_modelresolver__schema_to_lang_type_primitive_nondefault_format(): resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type({ "type": "integer", "format": "int64" }) assert resolved_type.container == ContainerType.PRIMITIVE assert resolved_type.type == "integer" assert resolved_type.type_format == "int64"
def test_modelresolver__schema_to_lang_type_object(): # see test_modelresolver__get_object_lang_type_no_item_type resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type({"type": "object"}) assert resolved_type.container == ContainerType.DICT item_type = resolved_type.type assert item_type.container == ContainerType.PRIMITIVE assert item_type.type == UNDEFINED assert item_type.type_format == FORMAT_DEFAULT
def test_modelresolver_unique_model_name(): unique = { "type": "object", "properties": { "foo": { "type": "string" }, "bar": { "type": "integer" } }, } flattened = { (): { "definitions": { "Unique": unique }, "properties": { "Unique": { "$ref": ("definitions", "Unique") } }, }, ("definitions", "Unique"): unique, } resolver = ModelResolver(flattened) assert resolver._models == { (): "ResourceModel", ("definitions", "Unique"): "Unique", } models = resolver.resolve_models() assert models == { "ResourceModel": { "Unique": ResolvedType(ContainerType.MODEL, "Unique") }, "Unique": { "foo": ResolvedType(ContainerType.PRIMITIVE, "string"), "bar": ResolvedType(ContainerType.PRIMITIVE, "integer"), }, }
def test_modelresolver_duplicate_model_name(): flattened = { (): { "properties": { "ResourceModel": { "type": "object" } } }, ("properties", "ResourceModel"): { "type": "object" }, } with pytest.raises(ModelResolverError) as excinfo: ModelResolver(flattened) assert "ResourceModel" in str(excinfo.value)
def test_modelresolver__schema_to_lang_type_multiple(): resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type({"type": ["string"]}) assert resolved_type.container == ContainerType.MULTIPLE assert resolved_type.type == "multiple"
def test_modelresolver__schema_to_lang_type_primitive(): resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type({"type": "string"}) assert resolved_type.container == ContainerType.PRIMITIVE assert resolved_type.type == "string"
def test_modelresolver_empty_ref_path_results_in_model_name(): flattened = {(): {"properties": {"foo": {"type": "string"}}}} resolver = ModelResolver(flattened, "ResourceModel") assert resolver._models == {(): "ResourceModel"}
def test_modelresolver__schema_to_lang_type_ref(): resolver = ModelResolver({(): {}}) assert resolver._models == {(): "ResourceModel"} resolved_type = resolver._schema_to_lang_type({"$ref": ()}) assert resolved_type.container == ContainerType.MODEL assert resolved_type.type == "ResourceModel"
def test_modelresolver__get_primitive_lang_type(): sentinel = object() resolved_type = ModelResolver._get_primitive_lang_type(sentinel) assert resolved_type.container == ContainerType.PRIMITIVE assert resolved_type.type is sentinel
def test_modelresolver__get_array_container_type(schema, result): container_type = ModelResolver._get_array_container_type(schema) assert container_type == result
def test_modelresolver__schema_to_lang_duplicatetype(): resolver = ModelResolver({}) resolved_type = resolver._schema_to_lang_type( {"type": ["string", "string"]}) assert resolved_type.container == ContainerType.PRIMITIVE assert resolved_type.type == "string"
def test_modelresolver__get_primitive_lang_type(): sentinel = object() resolved_type = ModelResolver._get_primitive_lang_type(sentinel, {}) assert resolved_type.container == ContainerType.PRIMITIVE assert resolved_type.type is sentinel assert resolved_type.type_format == FORMAT_DEFAULT