diff --git a/.changes/unreleased/Under the Hood-20220912-134000.yaml b/.changes/unreleased/Under the Hood-20220912-134000.yaml new file mode 100644 index 00000000000..ba104e8ef96 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20220912-134000.yaml @@ -0,0 +1,7 @@ +kind: Under the Hood +body: Convert default selector tests to pytest +time: 2022-09-12T13:40:00.625912-05:00 +custom: + Author: stu-k + Issue: "5728" + PR: "5820" diff --git a/test/integration/073_default_selectors_tests/models/model_a.sql b/test/integration/073_default_selectors_tests/models/model_a.sql deleted file mode 100644 index 542ed4ee3a5..00000000000 --- a/test/integration/073_default_selectors_tests/models/model_a.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1 AS fun \ No newline at end of file diff --git a/test/integration/073_default_selectors_tests/models/model_b.sql b/test/integration/073_default_selectors_tests/models/model_b.sql deleted file mode 100644 index 542ed4ee3a5..00000000000 --- a/test/integration/073_default_selectors_tests/models/model_b.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT 1 AS fun \ No newline at end of file diff --git a/test/integration/073_default_selectors_tests/models/schema.yml b/test/integration/073_default_selectors_tests/models/schema.yml deleted file mode 100644 index 21f42d721d7..00000000000 --- a/test/integration/073_default_selectors_tests/models/schema.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: 2 - -sources: - - name: src - schema: "{{ target.schema }}" - freshness: - warn_after: {count: 24, period: hour} - loaded_at_field: _loaded_at - tables: - - name: source_a - identifier: model_c - columns: - - name: fun - - name: _loaded_at - - name: src - schema: "{{ target.schema }}" - freshness: - warn_after: {count: 24, period: hour} - loaded_at_field: _loaded_at - tables: - - name: source_b - identifier: model_c - columns: - - name: fun - - name: _loaded_at - -models: - - name: model_a - columns: - - name: fun - tags: [marketing] - - name: model_b - columns: - - name: fun - tags: [finance] \ No newline at end of file diff --git a/test/integration/073_default_selectors_tests/seeds/model_c.csv b/test/integration/073_default_selectors_tests/seeds/model_c.csv deleted file mode 100644 index 6a55430b96c..00000000000 --- a/test/integration/073_default_selectors_tests/seeds/model_c.csv +++ /dev/null @@ -1,2 +0,0 @@ -fun,_loaded_at -1,2021-04-19 01:00:00 \ No newline at end of file diff --git a/test/integration/073_default_selectors_tests/test_default_selectors.py b/test/integration/073_default_selectors_tests/test_default_selectors.py deleted file mode 100644 index 27dfa090740..00000000000 --- a/test/integration/073_default_selectors_tests/test_default_selectors.py +++ /dev/null @@ -1,77 +0,0 @@ -import yaml -from test.integration.base import DBTIntegrationTest, use_profile - - -class TestDefaultSelectors(DBTIntegrationTest): - """Test the selectors' default argument""" - @property - def schema(self): - return 'test_default_selectors_101' - - @property - def models(self): - return 'models' - - @property - def project_config(self): - return { - 'config-version': 2, - 'model-paths': ['models'], - 'seed-paths': ['seeds'], - 'seeds': { - 'quote_columns': False, - }, - } - - @property - def selectors_config(self): - return yaml.safe_load(''' - selectors: - - name: default_selector - description: test default selector - definition: - union: - - method: source - value: "test.src.source_a" - - method: fqn - value: "model_a" - default: true - ''') - - def list_and_assert(self, expected): - '''list resources in the project with the selectors default''' - listed = self.run_dbt(['ls', '--resource-type', 'model']) - - assert len(listed) == len(expected) - - def compile_and_assert(self, expected): - '''Compile project with the selectors default''' - compiled = self.run_dbt(['compile']) - - assert len(compiled.results) == len(expected) - assert compiled.results[0].node.name == expected[0] - - def run_and_assert(self, expected): - run = self.run_dbt(['run']) - - assert len(run.results) == len(expected) - assert run.results[0].node.name == expected[0] - - def freshness_and_assert(self, expected): - self.run_dbt(['seed', '-s', 'test.model_c']) - freshness = self.run_dbt(['source', 'freshness']) - - assert len(freshness.results) == len(expected) - assert freshness.results[0].node.name == expected[0] - - @use_profile('postgres') - def test__postgres__model_a_only(self): - expected_model = ['model_a'] - - self.list_and_assert(expected_model) - self.compile_and_assert(expected_model) - - def test__postgres__source_a_only(self): - expected_source = ['source_a'] - - self.freshness_and_assert(expected_source) \ No newline at end of file diff --git a/tests/functional/selectors/test_default_selectors.py b/tests/functional/selectors/test_default_selectors.py new file mode 100644 index 00000000000..3be42bea132 --- /dev/null +++ b/tests/functional/selectors/test_default_selectors.py @@ -0,0 +1,98 @@ +import pytest +from dbt.tests.util import run_dbt + +models__schema_yml = """ +version: 2 + +sources: + - name: src + schema: "{{ target.schema }}" + freshness: + warn_after: {count: 24, period: hour} + loaded_at_field: _loaded_at + tables: + - name: source_a + identifier: model_c + columns: + - name: fun + - name: _loaded_at + - name: src + schema: "{{ target.schema }}" + freshness: + warn_after: {count: 24, period: hour} + loaded_at_field: _loaded_at + tables: + - name: source_b + identifier: model_c + columns: + - name: fun + - name: _loaded_at + +models: + - name: model_a + columns: + - name: fun + tags: [marketing] + - name: model_b + columns: + - name: fun + tags: [finance] +""" + +models__model_a_sql = """ +SELECT 1 AS fun +""" + +models__model_b_sql = """ +SELECT 1 AS fun +""" + +seeds__model_c_csv = """fun,_loaded_at +1,2021-04-19 01:00:00""" + + +@pytest.fixture(scope="class") +def models(): + return { + "schema.yml": models__schema_yml, + "model_b.sql": models__model_b_sql, + "model_a.sql": models__model_a_sql, + } + + +@pytest.fixture(scope="class") +def seeds(): + return {"model_c.csv": seeds__model_c_csv} + + +@pytest.fixture(scope="class") +def selectors(): + return """ + selectors: + - name: default_selector + description: test default selector + definition: + union: + - method: source + value: "test.src.source_a" + - method: fqn + value: "model_a" + default: true + """ + + +class TestDefaultSelectors: + def test_model__list(self, project): + result = run_dbt(["ls", "--resource-type", "model"]) + assert "test.model_a" in result + + def test_model__compile(self, project): + result = run_dbt(["compile"]) + assert len(result) == 1 + assert result.results[0].node.name == "model_a" + + def test_source__freshness(self, project): + run_dbt(["seed", "-s", "test.model_c"]) + result = run_dbt(["source", "freshness"]) + assert len(result) == 1 + assert result.results[0].node.name == "source_a"