From 6906eb0b32a7b729d8f053d674f8951ae2773a55 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Fri, 9 Feb 2024 10:23:02 -0500 Subject: [PATCH] [Redshift] Add tests for unit testing (#680) * first pass * fix dbt-common version * try to fix dbt-postgres version * fix import * array and json types as TODO * add json test, TestRedshiftUnitTestCaseInsensitivity, TestRedshiftUnitTestInvalidInput * restore requirements --------- Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> --- dev-requirements.txt | 3 +- setup.py | 2 +- .../adapter/unit_testing/test_unit_testing.py | 42 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/functional/adapter/unit_testing/test_unit_testing.py diff --git a/dev-requirements.txt b/dev-requirements.txt index 0c8c9b1a3..8814be848 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,8 @@ # install latest changes in dbt-core + dbt-postgres # TODO: how to switch from HEAD to x.y.latest branches after minor releases? -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core git+https://github.com/dbt-labs/dbt-postgres.git@main +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-adapters.git git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter # if version 1.x or greater -> pin to major version diff --git a/setup.py b/setup.py index 4925bb04b..09b1cea88 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ def _plugin_version() -> str: packages=find_namespace_packages(include=["dbt", "dbt.*"]), include_package_data=True, install_requires=[ - "dbt-common<1.0", + "dbt-common>=0.1.0,<0.2.0", "dbt-adapters~=0.1.0a1", f"dbt-postgres~={_plugin_version()}", # dbt-redshift depends deeply on this package. it does not follow SemVer, therefore there have been breaking changes in previous patch releases diff --git a/tests/functional/adapter/unit_testing/test_unit_testing.py b/tests/functional/adapter/unit_testing/test_unit_testing.py new file mode 100644 index 000000000..4d89c4b08 --- /dev/null +++ b/tests/functional/adapter/unit_testing/test_unit_testing.py @@ -0,0 +1,42 @@ +import pytest +from dbt.tests.adapter.unit_testing.test_types import BaseUnitTestingTypes +from dbt.tests.adapter.unit_testing.test_case_insensitivity import BaseUnitTestCaseInsensivity +from dbt.tests.adapter.unit_testing.test_invalid_input import BaseUnitTestInvalidInput + + +class TestRedshiftUnitTestingTypes(BaseUnitTestingTypes): + @pytest.fixture + def data_types(self): + # sql_value, yaml_value + return [ + ["1", "1"], + ["1.0", "1.0"], + ["'1'", "1"], + ["'1'::numeric", "1"], + ["'string'", "string"], + ["true", "true"], + ["DATE '2020-01-02'", "2020-01-02"], + ["TIMESTAMP '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], + ["TIMESTAMPTZ '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], + [ + """JSON_PARSE('{"bar": "baz", "balance": 7.77, "active": false}')""", + """'{"bar": "baz", "balance": 7.77, "active": false}'""", + ], + # TODO: array types + # ["ARRAY[1,2,3]", """'{1, 2, 3}'"""], + # ["ARRAY[1.0,2.0,3.0]", """'{1.0, 2.0, 3.0}'"""], + # ["ARRAY[1::numeric,2::numeric,3::numeric]", """'{1.0, 2.0, 3.0}'"""], + # ["ARRAY['a','b','c']", """'{"a", "b", "c"}'"""], + # ["ARRAY[true,true,false]", """'{true, true, false}'"""], + # ["ARRAY[DATE '2020-01-02']", """'{"2020-01-02"}'"""], + # ["ARRAY[TIMESTAMP '2013-11-03 00:00:00-0']", """'{"2013-11-03 00:00:00-0"}'"""], + # ["ARRAY[TIMESTAMPTZ '2013-11-03 00:00:00-0']", """'{"2013-11-03 00:00:00-0"}'"""], + ] + + +class TestRedshiftUnitTestCaseInsensitivity(BaseUnitTestCaseInsensivity): + pass + + +class TestRedshiftUnitTestInvalidInput(BaseUnitTestInvalidInput): + pass