def test_layer_builder_returns_self_on_with(): builder = LayerBuilder() test_model = SimpleModel.sample() assert isinstance(builder.with_model(test_model), LayerBuilder) assert isinstance(builder.with_table(MultiKeyModel), LayerBuilder) assert isinstance(builder.with_view(SimpleView), LayerBuilder) assert isinstance(builder.with_schema("third_schema"), LayerBuilder)
def layer_with_all(): model = SimpleModel.sample() layer = Layer(schemas=["aa"], tables=[SimpleModel], views=[SimpleView], models=[model]) return layer
def test_layer_builder_doesnt_infer_lower_level_ddl(): builder = LayerBuilder() test_model = SimpleModel.sample() builder.with_model(test_model) builder.with_table(MultiKeyModel) builder.with_schema("third_schema") layer = builder.build() assert layer.models == [test_model] assert layer.tables == [MultiKeyModel] assert layer.schemas == ["third_schema"]
"SELECT schema_one.simple_table.some_id, schema_one.simple_table.some_col\n" "FROM schema_one.simple_table\n" "WHERE schema_one.simple_table.some_id = '2'") actual = q.push_query(SimpleView) assert actual == expected expected = "DROP VIEW some_schema.test_view" assert q.pop_query(SimpleView) == expected @pytest.mark.parametrize( "model, expected_push, expected_pop", [ [ SimpleModel.sample(), "INSERT INTO schema_one.simple_table (some_id, some_col)\nVALUES ('1', 'foo')", "DELETE\nFROM schema_one.simple_table\nWHERE some_id = '1'", ], [ MultiKeyModel.sample(), ("INSERT INTO schema_two.multikey_table (id_one, id_two, not_id)\n" "VALUES ('a', 'b', 'bar')"), ("DELETE\n" "FROM schema_two.multikey_table\n" "WHERE id_one = 'a'\n" " AND id_two = 'b'"), ], ], ) def test_model(model, expected_push, expected_pop):
import pytest from shreqt.model import full_table_name, table_pk_fields, fields_dict from tests.resources import SimpleModel, MultiKeyModel @pytest.mark.parametrize( "table, expected", [ [SimpleModel.sample(), "schema_one.simple_table"], [SimpleModel, "schema_one.simple_table"], [MultiKeyModel, "schema_two.multikey_table"], ], ) def test_full_table_name_uses_object_or_class(table, expected): assert full_table_name(table) == expected @pytest.mark.parametrize( "table, expected", [ [SimpleModel.sample(), ["some_id"]], [SimpleModel, ["some_id"]], [MultiKeyModel, ["id_one", "id_two"]], ], ) def test_table_pk_fields_uses_object_or_class(table, expected): assert table_pk_fields(table) == expected @pytest.mark.parametrize(
def test_layer_with_models(): builder = LayerBuilder() models = [SimpleModel.sample(), MultiKeyModel.sample()] builder.with_models(*models) layer = builder.build() assert layer.models == models