diff --git a/tests/functional/adapter/materialization/test_materialized_view.py b/tests/functional/adapter/materialization/test_materialized_view.py index 02a15aa9..d9a111ff 100644 --- a/tests/functional/adapter/materialization/test_materialized_view.py +++ b/tests/functional/adapter/materialization/test_materialized_view.py @@ -107,36 +107,68 @@ def test_mv_is_created_and_refreshed(self, project): results = run_sql_with_adapter(project.adapter, sql, fetch="all") assert len(results) == 5 - # Cleanup - project.adapter.execute("DROP MATERIALIZED VIEW mat_view") - def mv_overrides_relation(self, project, relation_type): +@pytest.mark.iceberg +class TestIcebergMaterializedViewDropAndCreate: + # Configuration in dbt_project.yml + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "name": "mv_test", + "models": { + "+materialized": "materialized_view", + }, + "seeds": { + "+column_types": {"some_date": "timestamp(6)"}, + }, + } + + # Everything that goes in the "seeds" directory + @pytest.fixture(scope="class") + def seeds(self): + return { + "seed.csv": seed_csv, + } + + # Everything that goes in the "models" directory + @pytest.fixture(scope="class") + def models(self): + return { + "mat_view_overrides_table.sql": model_sql, + "mat_view_overrides_view.sql": model_sql, + "mat_view_overrides_materializedview.sql": model_sql, + } + + def test_mv_overrides_relation(self, project): # Create relation with same name - project.adapter.execute(f"CREATE {relation_type} mat_view AS SELECT 3 c") - expected = {"mat_view": relation_type.replace(" ", "")} - check_relation_types(project.adapter, expected) + project.adapter.execute("CREATE VIEW mat_view_overrides_view AS SELECT 3 c") + project.adapter.execute("CREATE TABLE mat_view_overrides_table AS SELECT 4 d") + project.adapter.execute( + "CREATE MATERIALIZED VIEW mat_view_overrides_materializedview AS SELECT 5 e" + ) # Seed seed results = run_dbt(["seed"], expect_pass=True) assert len(results) == 1 - # Create MV, already existing relation with same name should be dropped beforehand + # Create MVs, already existing relations with same name should be dropped results = run_dbt(["run", "--full-refresh"], expect_pass=True) - assert len(results) == 1 - expected = {"mat_view": "materializedview"} - check_relation_types(project.adapter, expected) - - # Check if MV was created correctly - check_relations_equal(project.adapter, ["seed", "mat_view"]) - - # Cleanup - project.adapter.execute("DROP MATERIALIZED VIEW mat_view") + assert len(results) == 3 - def test_mv_overrides_table(self, project): - self.mv_overrides_relation(project, "table") - - def test_mv_overrides_view(self, project): - self.mv_overrides_relation(project, "view") + # Check if MVs were created correctly + expected = { + "mat_view_overrides_view": "materializedview", + "mat_view_overrides_table": "materializedview", + "mat_view_overrides_materializedview": "materializedview", + } + check_relation_types(project.adapter, expected) - def test_mv_overrides_materialized_view(self, project): - self.mv_overrides_relation(project, "materialized view") + check_relations_equal( + project.adapter, + [ + "seed", + "mat_view_overrides_view", + "mat_view_overrides_table", + "mat_view_overrides_materializedview", + ], + )