Esempio n. 1
0
def test_spec_to_column_no_type():
    """
    GIVEN column schema without type
    WHEN column_factory is called with the schema
    THEN TypeMissingError is raised.
    """
    with pytest.raises(exceptions.TypeMissingError):
        column_factory._spec_to_column(spec={})
Esempio n. 2
0
def test_spec_to_column_type_unsupported():
    """
    GIVEN column schema with type that has not been implemented
    WHEN column_factory is called with the schema
    THEN FeatureNotImplementedError is raised.
    """
    with pytest.raises(exceptions.FeatureNotImplementedError):
        column_factory._spec_to_column(spec={"type": "unsupported"})
Esempio n. 3
0
def test_spec_to_column_number_double():
    """
    GIVEN schema with number type and double format
    WHEN column_factory is called with the schema
    THEN FeatureNotImplementedError is raised.
    """
    with pytest.raises(exceptions.FeatureNotImplementedError):
        column_factory._spec_to_column(spec={
            "type": "number",
            "format": "double"
        })
Esempio n. 4
0
def test_spec_to_column_integer_unsupported_format():
    """
    GIVEN schema with integer type and unsupported format
    WHEN column_factory is called with the schema
    THEN FeatureNotImplementedError is raised.
    """
    with pytest.raises(exceptions.FeatureNotImplementedError):
        column_factory._spec_to_column(spec={
            "type": "integer",
            "format": "unsupported"
        })
Esempio n. 5
0
def test_spec_to_column_number():
    """
    GIVEN schema with number type
    WHEN column_factory is called with the schema
    THEN SQLAlchemy Float column is returned.
    """
    column = column_factory._spec_to_column(spec={"type": "number"})

    assert isinstance(column.type, sqlalchemy.Float)
Esempio n. 6
0
def test_spec_to_column_integer():
    """
    GIVEN schema with integer type
    WHEN column_factory is called with the schema
    THEN SQLAlchemy Integer column is returned.
    """
    column = column_factory._spec_to_column(spec={"type": "integer"})

    assert isinstance(column.type, sqlalchemy.Integer)
Esempio n. 7
0
def test_spec_to_column_column_return():
    """
    GIVEN valid schema
    WHEN column_factory is called with the schema
    THEN an instance of SQLAlchemy Column is returned.
    """
    column = column_factory._spec_to_column(spec={"type": "number"})

    assert isinstance(column, sqlalchemy.Column)
Esempio n. 8
0
def test_spec_to_column_string():
    """
    GIVEN schema with string type
    WHEN column_factory is called with the schema
    THEN SQLAlchemy String column is returned.
    """
    column = column_factory._spec_to_column(spec={"type": "string"})

    assert isinstance(column.type, sqlalchemy.String)
Esempio n. 9
0
def test_spec_to_column_boolean():
    """
    GIVEN schema with boolean type
    WHEN column_factory is called with the schema
    THEN SQLAlchemy boolean column is returned.
    """
    column = column_factory._spec_to_column(spec={"type": "boolean"})

    assert isinstance(column.type, sqlalchemy.Boolean)
Esempio n. 10
0
def test_spec_to_column_primary_key(primary_key: bool):
    """
    GIVEN valid schema and the value of the primary key property
    WHEN column_factory is called with the schema
    THEN the returned SQLAlchemy column primary_key property is set to the input.
    """
    column = column_factory._spec_to_column(spec={
        "type": "number",
        "x-primary-key": primary_key
    })

    assert column.primary_key == primary_key
Esempio n. 11
0
def test_spec_to_column_index(index: bool):
    """
    GIVEN valid schema and the value of the index property
    WHEN column_factory is called with the schema
    THEN the returned SQLAlchemy column index property is set to the input.
    """
    column = column_factory._spec_to_column(spec={
        "type": "number",
        "x-index": index
    })

    assert column.index == index
Esempio n. 12
0
def test_spec_to_column_unique(unique: bool):
    """
    GIVEN valid schema and the value of the unique property
    WHEN column_factory is called with the schema
    THEN the returned SQLAlchemy column unique property is set to the input.
    """
    column = column_factory._spec_to_column(spec={
        "type": "number",
        "x-unique": unique
    })

    assert column.unique == unique
Esempio n. 13
0
def test_spec_to_column_string_length():
    """
    GIVEN schema with string type and maxLength property
    WHEN column_factory is called with the schema
    THEN SQLAlchemy String column is returned with the length set to the maxLength.
    """
    column = column_factory._spec_to_column(spec={
        "type": "string",
        "maxLength": 1
    })

    assert column.type.length == 1
Esempio n. 14
0
def test_spec_to_column_integer_int64():
    """
    GIVEN schema with integer type and int64 format
    WHEN column_factory is called with the schema
    THEN SQLAlchemy BigInteger column is returned.
    """
    column = column_factory._spec_to_column(spec={
        "type": "integer",
        "format": "int64"
    })

    assert isinstance(column.type, sqlalchemy.BigInteger)
Esempio n. 15
0
def test_spec_to_column_autoincrement(autoincrement: bool):
    """
    GIVEN valid schema and the value of the autoincrement property
    WHEN column_factory is called with the schema
    THEN the returned SQLAlchemy column autoincrement property is set to the input.
    """
    column = column_factory._spec_to_column(spec={
        "type": "number",
        "x-autoincrement": autoincrement
    })

    assert column.autoincrement == autoincrement
Esempio n. 16
0
def test_spec_to_column_foreign_key():
    """
    GIVEN valid schema which has x-foreign-key set
    WHEN column_factory is called with the schema
    THEN the returned SQLAlchemy column foreign key property is set.
    """
    column = column_factory._spec_to_column(spec={
        "type": "number",
        "x-foreign-key": "foreign.key"
    })

    assert len(column.foreign_keys) == 1
    foreign_key = column.foreign_keys.pop()
    assert str(foreign_key) == "ForeignKey('foreign.key')"
Esempio n. 17
0
def test_spec_to_column_nullable(required: typing.Optional[bool],
                                 nullable: typing.Optional[bool],
                                 expected: bool):
    """
    GIVEN schema, the value for the nullable property and the required argument
    WHEN column_factory is called with the schema and required argument
    THEN SQLAlchemy column is returned where nullable property is equal to the
        expected input.
    """
    kwargs: typing.Dict[str, bool] = {}
    if required is not None:
        kwargs["required"] = required
    schema: typing.Dict[str, typing.Union[str, bool]] = {"type": "number"}
    if nullable is not None:
        schema["nullable"] = nullable
    column = column_factory._spec_to_column(spec=schema, **kwargs)

    assert column.nullable == expected