diff --git a/test/integration/034_changing_relation_type_tests/models/model.sql b/test/integration/034_changing_relation_type_tests/models/model.sql deleted file mode 100644 index c88e66ee170..00000000000 --- a/test/integration/034_changing_relation_type_tests/models/model.sql +++ /dev/null @@ -1,8 +0,0 @@ - -{{ config(materialized=var('materialized')) }} - -select '{{ var("materialized") }}' as materialization - -{% if var('materialized') == 'incremental' and is_incremental() %} - where 'abc' != (select max(materialization) from {{ this }}) -{% endif %} diff --git a/test/integration/034_changing_relation_type_tests/test_changing_relation_type.py b/test/integration/034_changing_relation_type_tests/test_changing_relation_type.py deleted file mode 100644 index 2c9794d5a86..00000000000 --- a/test/integration/034_changing_relation_type_tests/test_changing_relation_type.py +++ /dev/null @@ -1,45 +0,0 @@ -from pytest import mark -from test.integration.base import DBTIntegrationTest, use_profile - - -class TestChangingRelationType(DBTIntegrationTest): - - @property - def schema(self): - return "changing_relation_type_034" - - @staticmethod - def dir(path): - return path.lstrip("/") - - @property - def models(self): - return self.dir("models") - - def swap_types_and_test(self): - # test that dbt is able to do intelligent things when changing - # between materializations that create tables and views. - - results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEqual(results[0].node.config.materialized, 'view') - self.assertEqual(len(results), 1) - - results = self.run_dbt(['run', '--vars', 'materialized: table']) - self.assertEqual(results[0].node.config.materialized, 'table') - self.assertEqual(len(results), 1) - - results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEqual(results[0].node.config.materialized, 'view') - self.assertEqual(len(results), 1) - - results = self.run_dbt(['run', '--vars', 'materialized: incremental']) - self.assertEqual(results[0].node.config.materialized, 'incremental') - self.assertEqual(len(results), 1) - - results = self.run_dbt(['run', '--vars', 'materialized: view']) - self.assertEqual(results[0].node.config.materialized, 'view') - self.assertEqual(len(results), 1) - - @use_profile("postgres") - def test__postgres__switch_materialization(self): - self.swap_types_and_test() diff --git a/tests/adapter/dbt/tests/adapter/relations/test_changing_relation_type.py b/tests/adapter/dbt/tests/adapter/relations/test_changing_relation_type.py new file mode 100644 index 00000000000..38515bc0206 --- /dev/null +++ b/tests/adapter/dbt/tests/adapter/relations/test_changing_relation_type.py @@ -0,0 +1,44 @@ + + +from typing import List, Optional +import pytest + +from dbt.tests.util import run_dbt + + +_DEFAULT_CHANGE_RELATION_TYPE_MODEL = """ +{{ config(materialized=var('materialized')) }} + +select '{{ var("materialized") }}' as materialization + +{% if var('materialized') == 'incremental' and is_incremental() %} + where 'abc' != (select max(materialization) from {{ this }}) +{% endif %} +""" + + +class BaseChangeRelationTypeValidator: + @pytest.fixture(scope="class") + def models(self): + return { + "model_mc_modelface.sql": _DEFAULT_CHANGE_RELATION_TYPE_MODEL + } + + def _run_and_check_materialization(self, materialization, extra_args: Optional[List] = None): + run_args = ["run", '--vars', f'materialized: {materialization}'] + if extra_args: + run_args.extend(extra_args) + results = run_dbt(run_args) + assert results[0].node.config.materialized == materialization + assert len(results) == 1 + + def test_changing_materialization_changes_relation_type(self, project): + self._run_and_check_materialization('view') + self._run_and_check_materialization('table') + self._run_and_check_materialization('view') + self._run_and_check_materialization('incremental') + self._run_and_check_materialization('table', extra_args=['--full-refresh']) + + +class TestChangeRelationTypes(BaseChangeRelationTypeValidator): + pass