def test_calculate_column_schema_dict_ignore_invalid():
    """
    GIVEN schema with invalid x-dict-ignore
    WHEN _calculate_column_schema is called with the schema
    THEN MalformedExtensionPropertyError is raised.
    """
    with pytest.raises(exceptions.MalformedExtensionPropertyError):
        column._calculate_column_schema(
            artifacts=ColArt(open_api=OAColArt(type="type 1")),
            schema={
                "type": "type 1",
                "x-dict-ignore": "True"
            },
        )
Example #2
0
def test_calculate_column_schema_json():
    """
    GIVEN schema
    WHEN _calculate_column_schema is called with the schema
    THEN the schema is returned.
    """
    artifacts = ColArt(open_api=OAColArt(type="type 1"),
                       extension=ExtColArt(json=True))
    schema = {
        "type": "object",
        "properties": {
            "column": {
                "$ref": "#/components/schemas/RefSchema"
            }
        },
    }
    schemas = {"RefSchema": {"type": "integer"}}

    returned_schema = column._calculate_column_schema(artifacts=artifacts,
                                                      schema=schema,
                                                      schemas=schemas)

    assert returned_schema == {
        "type": "object",
        "properties": {
            "column": {
                "type": "integer"
            }
        },
    }
def test_calculate_column_schema(artifacts, expected_schema):
    """
    GIVEN schema
    WHEN _calculate_column_schema is called with the schema
    THEN the schema is returned.
    """
    returned_schema = column._calculate_column_schema(
        artifacts=artifacts, schema=copy.deepcopy(expected_schema))

    assert returned_schema == expected_schema