コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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"
コード例 #5
0
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
コード例 #6
0
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"),
        },
    }
コード例 #7
0
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)
コード例 #8
0
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"
コード例 #9
0
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"
コード例 #10
0
def test_modelresolver_empty_ref_path_results_in_model_name():
    flattened = {(): {"properties": {"foo": {"type": "string"}}}}
    resolver = ModelResolver(flattened, "ResourceModel")
    assert resolver._models == {(): "ResourceModel"}
コード例 #11
0
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"
コード例 #12
0
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
コード例 #13
0
def test_modelresolver__get_array_container_type(schema, result):
    container_type = ModelResolver._get_array_container_type(schema)
    assert container_type == result
コード例 #14
0
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"
コード例 #15
0
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