From be7ffb3a6f45b573208d18e5013fbacfcd7356a4 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 13 Sep 2023 10:48:38 -0700 Subject: [PATCH] Add adapter tests for `date_spine` macro --- .../tests/adapter/utils/fixture_date_spine.py | 43 +++++++++++++++++++ .../tests/adapter/utils/test_date_spine.py | 21 +++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/adapter/dbt/tests/adapter/utils/fixture_date_spine.py create mode 100644 tests/adapter/dbt/tests/adapter/utils/test_date_spine.py diff --git a/tests/adapter/dbt/tests/adapter/utils/fixture_date_spine.py b/tests/adapter/dbt/tests/adapter/utils/fixture_date_spine.py new file mode 100644 index 00000000000..75492aa3445 --- /dev/null +++ b/tests/adapter/dbt/tests/adapter/utils/fixture_date_spine.py @@ -0,0 +1,43 @@ +# If date_spine works properly, there should be no `null` values in the resulting model + +models__test_date_spine_sql = """ +with generated_dates as ( + {{ date_spine("day", "'2023-09-01'::date", "'2023-09-10'::date") }} +), expected_dates as ( + select '2023-09-01'::date as expected + union all + select '2023-09-02'::date as expected + union all + select '2023-09-03'::date as expected + union all + select '2023-09-04'::date as expected + union all + select '2023-09-05'::date as expected + union all + select '2023-09-06'::date as expected + union all + select '2023-09-07'::date as expected + union all + select '2023-09-08'::date as expected + union all + select '2023-09-09'::date as expected +), joined as ( + select + generated_dates.date_day, + expected_dates.expected + from generated_dates + left join expected_dates on generated_dates.date_day = expected_dates.expected +) + +SELECT * from joined +""" + +models__test_date_spine_yml = """ +version: 2 +models: + - name: test_date_spine + tests: + - assert_equal: + actual: date_day + expected: expected +""" diff --git a/tests/adapter/dbt/tests/adapter/utils/test_date_spine.py b/tests/adapter/dbt/tests/adapter/utils/test_date_spine.py new file mode 100644 index 00000000000..0a5d7b7d29f --- /dev/null +++ b/tests/adapter/dbt/tests/adapter/utils/test_date_spine.py @@ -0,0 +1,21 @@ +import pytest +from dbt.tests.adapter.utils.base_utils import BaseUtils +from dbt.tests.adapter.utils.fixture_date_spine import ( + models__test_date_spine_sql, + models__test_date_spine_yml, +) + + +class BaseDateSpine(BaseUtils): + @pytest.fixture(scope="class") + def models(self): + return { + "test_date_spine.yml": models__test_date_spine_yml, + "test_date_spine.sql": self.interpolate_macro_namespace( + models__test_date_spine_sql, "date_spine" + ), + } + + +class TestDateSpine(BaseDateSpine): + pass