From 018252e011cfbab95b9c55d2eb64380f498c64ff Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 18 Apr 2024 17:18:46 -0400 Subject: [PATCH] add more package materialization + deprecation tests --- tests/functional/materializations/conftest.py | 24 ++++++ .../test_custom_materialization.py | 74 +++++++++++++++++-- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/tests/functional/materializations/conftest.py b/tests/functional/materializations/conftest.py index b808c1a6a7b..8441e72c0b2 100644 --- a/tests/functional/materializations/conftest.py +++ b/tests/functional/materializations/conftest.py @@ -325,6 +325,21 @@ {%- endmaterialization -%} """ +custom_materialization_dep__dbt_project_yml = """ +name: custom_materialization_default +macro-paths: ['macros'] +""" + +custom_materialization_sql = """ +{% materialization custom_materialization, default %} + {%- set target_relation = this.incorporate(type='table') %} + {% call statement('main') -%} + select 1 as column1 + {%- endcall %} + {{ return({'relations': [target_relation]}) }} +{% endmaterialization %} +""" + @pytest.fixture(scope="class") def override_view_adapter_pass_dep(project_root): @@ -368,3 +383,12 @@ def override_view_return_no_relation(project_root): }, } write_project_files(project_root, "override-view-return-no-relation", files) + + +@pytest.fixture(scope="class") +def custom_materialization_dep(project_root): + files = { + "dbt_project.yml": custom_materialization_dep__dbt_project_yml, + "macros": {"custom_materialization.sql": custom_materialization_sql}, + } + write_project_files(project_root, "custom-materialization-dep", files) diff --git a/tests/functional/materializations/test_custom_materialization.py b/tests/functional/materializations/test_custom_materialization.py index ad41798039b..dd165514ec1 100644 --- a/tests/functional/materializations/test_custom_materialization.py +++ b/tests/functional/materializations/test_custom_materialization.py @@ -10,11 +10,24 @@ """ +models_custom_materialization__model_sql = """ +{{ config(materialized='custom_materialization') }} +select 1 as id + +""" + + @pytest.fixture(scope="class") def models(): return {"model.sql": models__model_sql} +@pytest.fixture(scope="class") +def set_up_deprecations(): + deprecations.reset_deprecations() + assert deprecations.active_deprecations == set() + + class TestOverrideAdapterDependency: # make sure that if there's a dependency with an adapter-specific # materialization, we honor that materialization @@ -22,25 +35,74 @@ class TestOverrideAdapterDependency: def packages(self): return {"packages": [{"local": "override-view-adapter-dep"}]} - def test_adapter_dependency(self, project, override_view_adapter_dep): + def test_adapter_dependency(self, project, override_view_adapter_dep, set_up_deprecations): run_dbt(["deps"]) # this should error because the override is buggy run_dbt(["run"], expect_pass=False) + # overriding a built-in materialization scoped to adapter from package is deprecated + assert deprecations.active_deprecations == {"package-materialization-override"} + class TestOverrideDefaultDependency: @pytest.fixture(scope="class") def packages(self): return {"packages": [{"local": "override-view-default-dep"}]} - def test_default_dependency(self, project, override_view_default_dep): + def test_default_dependency(self, project, override_view_default_dep, set_up_deprecations): + run_dbt(["deps"]) + # this should error because the override is buggy + run_dbt(["run"], expect_pass=False) + + # overriding a built-in materialization from package is deprecated + assert deprecations.active_deprecations == {"package-materialization-override"} + + +root_view_override_macro = """ +{% materialization view, default %} + {{ return(view_default_override.materialization_view_default()) }} +{% endmaterialization %} +""" + + +class TestOverrideDefaultDependencyRootOverride: + @pytest.fixture(scope="class") + def packages(self): + return {"packages": [{"local": "override-view-default-dep"}]} + + @pytest.fixture(scope="class") + def macros(self): + return {"my_view.sql": root_view_override_macro} + + def test_default_dependency_with_root_override( + self, project, override_view_default_dep, set_up_deprecations + ): run_dbt(["deps"]) - deprecations.reset_deprecations() - assert deprecations.active_deprecations == set() # this should error because the override is buggy run_dbt(["run"], expect_pass=False) - expected = {"package-materialization-override"} - assert expected == deprecations.active_deprecations + + # using an package-overriden built-in materialization in a root matereialization is _not_ deprecated + assert deprecations.active_deprecations == set() + + +class TestCustomMaterializationDependency: + @pytest.fixture(scope="class") + def models(self): + return {"model.sql": models_custom_materialization__model_sql} + + @pytest.fixture(scope="class") + def packages(self): + return {"packages": [{"local": "custom-materialization-dep"}]} + + def test_custom_materialization_deopendency( + self, project, custom_materialization_dep, set_up_deprecations + ): + run_dbt(["deps"]) + # custom materilization is valid + run_dbt(["run"]) + + # using a custom materialization is from an installed package is _not_ deprecated + assert deprecations.active_deprecations == set() class TestOverrideAdapterDependencyPassing: