예제 #1
0
def test_construct_column_invalid():
    """
    GIVEN artifacts that are not valid
    WHEN construct_column is called with the artifacts
    THEN MalformedSchemaError is raised.
    """
    artifacts = ColArt(open_api=OAColArt(type="string"),
                       extension=ExtColArt(autoincrement=True))

    with pytest.raises(exceptions.MalformedSchemaError):
        column.construct_column(artifacts=artifacts)
예제 #2
0
def test_construct_column_index(index):
    """
    GIVEN value for index
    WHEN construct_column is called with the artifacts with index
    THEN the returned column index property is equal to index.
    """
    artifacts = types.ColumnArtifacts("integer", index=index)

    returned_column = column.construct_column(artifacts=artifacts)

    assert returned_column.index == index
예제 #3
0
def test_construct_column_unique(unique):
    """
    GIVEN value for unique
    WHEN construct_column is called with the artifacts with unique
    THEN the returned column unique property is equal to unique.
    """
    artifacts = types.ColumnArtifacts("integer", unique=unique)

    returned_column = column.construct_column(artifacts=artifacts)

    assert returned_column.unique == unique
예제 #4
0
def test_construct_column_autoincrement(autoincrement):
    """
    GIVEN value for autoincrement
    WHEN construct_column is called with the artifacts with autoincrement
    THEN the returned column autoincrement property is equal to autoincrement.
    """
    artifacts = types.ColumnArtifacts("integer", autoincrement=autoincrement)

    returned_column = column.construct_column(artifacts=artifacts)

    assert returned_column.autoincrement == autoincrement
예제 #5
0
def test_construct_column_primary_key(primary_key):
    """
    GIVEN value for primary_key
    WHEN construct_column is called with the artifacts with primary_key
    THEN the returned column primary_key property is equal to primary_key.
    """
    artifacts = types.ColumnArtifacts("integer", primary_key=primary_key)

    returned_column = column.construct_column(artifacts=artifacts)

    assert returned_column.primary_key == primary_key
예제 #6
0
def test_construct_column_nullable(nullable):
    """
    GIVEN value for nullable
    WHEN construct_column is called with the artifacts with nullable
    THEN the returned column nullable property is equal to nullable.
    """
    artifacts = types.ColumnArtifacts("integer", nullable=nullable)

    returned_column = column.construct_column(artifacts=artifacts)

    assert returned_column.nullable == nullable
예제 #7
0
def test_construct_column_valid():
    """
    GIVEN artifacts that are not valid
    WHEN construct_column is called with the artifacts
    THEN MalformedSchemaError is raised.
    """
    artifacts = ColArt(open_api=OAColArt(type="string"))

    return_column = column.construct_column(artifacts=artifacts)

    assert isinstance(return_column, facades.sqlalchemy.column.Column)
    assert isinstance(return_column.type, facades.sqlalchemy.column.String)
예제 #8
0
def test_construct_column_foreign_key():
    """
    GIVEN artifacts with foreign key
    WHEN construct_column is called with the artifacts
    THEN a column with a foreign key is returned.
    """
    artifacts = types.ColumnArtifacts("integer", foreign_key="table.column")

    returned_column = column.construct_column(artifacts=artifacts)

    assert len(returned_column.foreign_keys) == 1
    foreign_key = returned_column.foreign_keys.pop()
    assert str(foreign_key) == "ForeignKey('table.column')"
예제 #9
0
def test_construct_column(type_, expected_type):
    """
    GIVEN artifacts for a type
    WHEN construct_column is called with the artifacts
    THEN a column with the expected type is returned.
    """
    artifacts = types.ColumnArtifacts(type_)

    returned_column = column.construct_column(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