From 9cfb21ef861f2da82b86880de6d3fd0f5842c1f5 Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:49:15 -0600 Subject: [PATCH] Add tests for cross-database `cast` macro (#173) Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> --- .../unreleased/Features-20240412-192040.yaml | 6 ++++ .../dbt/tests/adapter/utils/fixture_cast.py | 33 +++++++++++++++++++ .../dbt/tests/adapter/utils/test_cast.py | 23 +++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 .changes/unreleased/Features-20240412-192040.yaml create mode 100644 dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py create mode 100644 dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py diff --git a/.changes/unreleased/Features-20240412-192040.yaml b/.changes/unreleased/Features-20240412-192040.yaml new file mode 100644 index 00000000..dc3f6799 --- /dev/null +++ b/.changes/unreleased/Features-20240412-192040.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Cross-database `cast` macro +time: 2024-04-12T19:20:40.904842-06:00 +custom: + Author: MichelleArk dbeatty10 + Issue: "84" diff --git a/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py b/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py new file mode 100644 index 00000000..fe29c706 --- /dev/null +++ b/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py @@ -0,0 +1,33 @@ +# cast + +seeds__data_cast_csv = """field,output +abc,abc +123,123 +, +""" + + +models__test_cast_sql = """ +with data as ( + + select * from {{ ref('data_cast') }} + +) + +select + {{ cast('field', api.Column.translate_type('string')) }} as actual, + output as expected + +from data +""" + + +models__test_cast_yml = """ +version: 2 +models: + - name: test_cast + data_tests: + - assert_equal: + actual: actual + expected: expected +""" diff --git a/dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py b/dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py new file mode 100644 index 00000000..686b7697 --- /dev/null +++ b/dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py @@ -0,0 +1,23 @@ +import pytest + +from dbt.tests.adapter.utils import base_utils, fixture_cast + + +class BaseCast(base_utils.BaseUtils): + @pytest.fixture(scope="class") + def seeds(self): + return {"data_cast.csv": fixture_cast.seeds__data_cast_csv} + + @pytest.fixture(scope="class") + def models(self): + return { + "test_cast.yml": fixture_cast.models__test_cast_yml, + "test_cast.sql": self.interpolate_macro_namespace( + self.interpolate_macro_namespace(fixture_cast.models__test_cast_sql, "cast"), + "type_string", + ), + } + + +class TestCast(BaseCast): + pass