Skip to content

Commit

Permalink
Add adapter tests for date_spine macro
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Sep 14, 2023
1 parent e3fb225 commit be7ffb3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/adapter/dbt/tests/adapter/utils/fixture_date_spine.py
Original file line number Diff line number Diff line change
@@ -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
"""
21 changes: 21 additions & 0 deletions tests/adapter/dbt/tests/adapter/utils/test_date_spine.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit be7ffb3

Please sign in to comment.