コード例 #1
0
def test_construct_nullable(nullable):
    """
    GIVEN value for nullable
    WHEN construct is called with the artifacts with nullable
    THEN the returned column nullable property is equal to nullable.
    """
    artifacts = ColArt(open_api=OAColArt(type="integer", nullable=nullable))

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.nullable == nullable
コード例 #2
0
def test_construct_json(type_):
    """
    GIVEN artifacts for a JSON type
    WHEN construct is called with the artifacts
    THEN a column with the expected type is returned.
    """
    artifacts = ColArt(open_api=OAColArt(type=type_), extension=ExtColArt(json=True))

    returned_column = column.construct(artifacts=artifacts)

    assert isinstance(returned_column, sqlalchemy.Column)
    assert isinstance(returned_column.type, sqlalchemy.JSON)
コード例 #3
0
def test_construct_kwargs():
    """
    GIVEN artifacts with kwargs
    WHEN construct is called with the artifacts
    THEN the column is constructed with the kwargs.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"), extension=ExtColArt(kwargs={"doc": "doc 1"})
    )

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.doc == "doc 1"
コード例 #4
0
def test_construct_unique(unique):
    """
    GIVEN value for unique
    WHEN construct is called with the artifacts with unique
    THEN the returned column unique property is equal to unique.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"), extension=ExtColArt(unique=unique)
    )

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.unique == unique
コード例 #5
0
def test_construct_index(index):
    """
    GIVEN value for index
    WHEN construct is called with the artifacts with index
    THEN the returned column index property is equal to index.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"), extension=ExtColArt(index=index)
    )

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.index == index
コード例 #6
0
def test_construct_primary_key(primary_key):
    """
    GIVEN value for primary_key
    WHEN construct is called with the artifacts with primary_key
    THEN the returned column primary_key property is equal to primary_key.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"), extension=ExtColArt(primary_key=primary_key)
    )

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.primary_key == primary_key
コード例 #7
0
def test_construct_default_type_mapped():
    """
    GIVEN artifacts with a format that requires mapping with default value
    WHEN construct is called with the artifacts
    THEN a column with a default value that is mapped is returned.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="string", format="binary", default="value 1")
    )

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.default.arg == b"value 1"
コード例 #8
0
def test_construct(type_, expected_type):
    """
    GIVEN artifacts for a type
    WHEN construct is called with the artifacts
    THEN a column with the expected type is returned.
    """
    artifacts = ColArt(open_api=OAColArt(type=type_))

    returned_column = column.construct(artifacts=artifacts)

    assert isinstance(returned_column, sqlalchemy.Column)
    assert isinstance(returned_column.type, expected_type)
    assert len(returned_column.foreign_keys) == 0
    assert returned_column.nullable is True
コード例 #9
0
def test_construct_autoincrement(autoincrement):
    """
    GIVEN value for autoincrement
    WHEN construct is called with the artifacts with autoincrement
    THEN the returned column autoincrement property is equal to autoincrement.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"),
        extension=ExtColArt(autoincrement=autoincrement),
    )

    returned_column = column.construct(artifacts=artifacts)

    assert returned_column.autoincrement == autoincrement
コード例 #10
0
def test_construct_default(default):
    """
    GIVEN artifacts with default value
    WHEN construct is called with the artifacts
    THEN a column with a default value is returned.
    """
    artifacts = ColArt(open_api=OAColArt(type="integer", default=default))

    returned_column = column.construct(artifacts=artifacts)

    if default is not None:
        assert returned_column.default.arg == default
    else:
        assert returned_column.default == default
コード例 #11
0
def test_construct_foreign_key():
    """
    GIVEN artifacts with foreign key
    WHEN construct is called with the artifacts
    THEN a column with a foreign key is returned.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"),
        extension=ExtColArt(foreign_key="table.column"),
    )

    returned_column = column.construct(artifacts=artifacts)

    assert len(returned_column.foreign_keys) == 1
    foreign_key = returned_column.foreign_keys.pop()
    assert str(foreign_key) == "ForeignKey('table.column')"
    assert foreign_key.name is None
コード例 #12
0
def test_construct_foreign_key_kwargs():
    """
    GIVEN artifacts with foreign key and foreign key kwargs
    WHEN construct is called with the artifacts
    THEN a column with a foreign key with the kwargs is returned.
    """
    artifacts = ColArt(
        open_api=OAColArt(type="integer"),
        extension=ExtColArt(
            foreign_key="table.column", foreign_key_kwargs={"name": "name 1"}
        ),
    )

    returned_column = column.construct(artifacts=artifacts)

    assert len(returned_column.foreign_keys) == 1
    foreign_key = returned_column.foreign_keys.pop()
    assert foreign_key.name == "name 1"