def test_construct_kwargs(): """ GIVEN artifacts with kwargs WHEN construct is called with the artifacts THEN the column is constructed with the kwargs. """ artifacts = _create_artifacts() artifacts.extension.kwargs = {"doc": "doc 1"} returned_column = json.construct(artifacts=artifacts) assert returned_column.doc == "doc 1"
def test_construct(): """ GIVEN artifacts for a type WHEN construct is called with the artifacts THEN a column with the JSON type is returned. """ artifacts = _create_artifacts() returned_column = json.construct(artifacts=artifacts) assert isinstance(returned_column, sqlalchemy.Column) assert isinstance(returned_column.type, sqlalchemy.JSON)
def test_construct_args(art_parent_key, art_item_key, art_value, column_key, column_value): """ GIVEN artifacts where a key has been set to a value WHEN construct is called with the artifacts THEN a column where the key has the expected value is returned. """ artifacts = _create_artifacts() setattr(getattr(artifacts, art_parent_key), art_item_key, art_value) returned_column = json.construct(artifacts=artifacts) assert (functools.reduce(getattr, column_key.split("."), returned_column) == column_value)
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 = _create_artifacts() artifacts.extension.foreign_key = "table.column" artifacts.extension.foreign_key_kwargs = {"name": "name 1"} returned_column = json.construct(artifacts=artifacts) assert len(returned_column.foreign_keys) == 1 foreign_key = returned_column.foreign_keys.pop() assert foreign_key.name == "name 1"
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 = _create_artifacts() artifacts.extension.foreign_key = "table.column" returned_column = json.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