From 095997913e582e8d7f828adce996f571d0b84468 Mon Sep 17 00:00:00 2001 From: colin-rogers-dbt <111200756+colin-rogers-dbt@users.noreply.github.com> Date: Wed, 12 Oct 2022 15:24:51 -0700 Subject: [PATCH] migrate 034 integration test to functional (#6054) * migrate 034 integration test to functional * formatting fixes * move to adapter directory * add extra args --- .../models/model.sql | 8 ---- .../test_changing_relation_type.py | 45 ------------------- .../relations/test_changing_relation_type.py | 44 ++++++++++++++++++ 3 files changed, 44 insertions(+), 53 deletions(-) delete mode 100644 test/integration/034_changing_relation_type_tests/models/model.sql delete mode 100644 test/integration/034_changing_relation_type_tests/test_changing_relation_type.py create mode 100644 tests/adapter/dbt/tests/adapter/relations/test_changing_relation_type.py 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