From 6cd8af4ecdd80ebda9e24115cdfa0e875bf7120e Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 16 Mar 2023 09:39:44 -0500 Subject: [PATCH 1/7] add test for enforcing contracts on incremental materializations --- dev-requirements.txt | 4 +-- tests/functional/adapter/test_constraints.py | 31 +++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 8d67d4a4f..2e9aa85e9 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git@er/ct-2293-incremental-mat#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git@er/ct-2293-incremental-mat#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index e2cfe1b96..6556112f5 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -1,15 +1,18 @@ import pytest -from dbt.tests.util import relation_from_name from dbt.tests.adapter.constraints.test_constraints import ( BaseTableConstraintsColumnsEqual, BaseViewConstraintsColumnsEqual, - BaseConstraintsRuntimeEnforcement + BaseIncrementalConstraintsColumnsEqual, + BaseConstraintsRuntimeDdlEnforcement, + BaseConstraintsRollback, + BaseIncrementalConstraintsRuntimeEnforcement, + BaseIncrementalConstraintsRollback, ) _expected_sql_snowflake = """ -create or replace transient table {0} ( +create or replace transient table ( id integer not null primary key, color text, date_day text @@ -59,13 +62,27 @@ class TestSnowflakeViewConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseVi pass -class TestSnowflakeConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement): +class TestSnowflakeIncrementalConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseIncrementalConstraintsColumnsEqual): + pass +class TestSnowflakeTableConstraintsDdlEnforcement(BaseConstraintsRuntimeDdlEnforcement): @pytest.fixture(scope="class") - def expected_sql(self, project): - relation = relation_from_name(project.adapter, "my_model") - return _expected_sql_snowflake.format(relation) + def expected_sql(self): + return _expected_sql_snowflake + +class TestSnowflakeTableConstraintsRollback(BaseConstraintsRollback): @pytest.fixture(scope="class") def expected_error_messages(self): return ["NULL result in a non-nullable column"] + + +class TestSnowflakeIncrementalConstraintsDdlEnforcement(BaseIncrementalConstraintsRuntimeEnforcement): + @pytest.fixture(scope="class") + def expected_sql(self): + return _expected_sql_snowflake + +class TestSnowflakeIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback): + @pytest.fixture(scope="class") + def expected_error_messages(self): + return ["NULL result in a non-nullable column"] \ No newline at end of file From 19c0b3ecf6a48141be72cf8986657d492ebd355a Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 16 Mar 2023 09:51:57 -0500 Subject: [PATCH 2/7] changelog --- .changes/1.5.0/Features-20230223-182450.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/1.5.0/Features-20230223-182450.yaml b/.changes/1.5.0/Features-20230223-182450.yaml index 9d4446888..e512824da 100644 --- a/.changes/1.5.0/Features-20230223-182450.yaml +++ b/.changes/1.5.0/Features-20230223-182450.yaml @@ -1,5 +1,5 @@ kind: Features -body: Enforce contracts on models materialized as tables and views +body: Enforce contracts on models with materializations of table, view or incremental. time: 2023-02-23T18:24:50.272955-05:00 custom: Author: michelleark emmyoop From 9512eedbde8622345d09ff2a896e31060d103286 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 16 Mar 2023 10:31:15 -0500 Subject: [PATCH 3/7] fix test name --- tests/functional/adapter/test_constraints.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index 6556112f5..b4553dcd1 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -6,7 +6,7 @@ BaseIncrementalConstraintsColumnsEqual, BaseConstraintsRuntimeDdlEnforcement, BaseConstraintsRollback, - BaseIncrementalConstraintsRuntimeEnforcement, + BaseIncrementalConstraintsRuntimeDdlEnforcement, BaseIncrementalConstraintsRollback, ) @@ -77,7 +77,7 @@ def expected_error_messages(self): return ["NULL result in a non-nullable column"] -class TestSnowflakeIncrementalConstraintsDdlEnforcement(BaseIncrementalConstraintsRuntimeEnforcement): +class TestSnowflakeIncrementalConstraintsDdlEnforcement(BaseIncrementalConstraintsRuntimeDdlEnforcement): @pytest.fixture(scope="class") def expected_sql(self): return _expected_sql_snowflake From c08f5f4f0cacf2dd8b57548bedfe7c39ca98108f Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 16 Mar 2023 11:39:18 -0500 Subject: [PATCH 4/7] remove changelog --- .changes/1.5.0/Features-20230223-182450.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/1.5.0/Features-20230223-182450.yaml b/.changes/1.5.0/Features-20230223-182450.yaml index e512824da..9d4446888 100644 --- a/.changes/1.5.0/Features-20230223-182450.yaml +++ b/.changes/1.5.0/Features-20230223-182450.yaml @@ -1,5 +1,5 @@ kind: Features -body: Enforce contracts on models with materializations of table, view or incremental. +body: Enforce contracts on models materialized as tables and views time: 2023-02-23T18:24:50.272955-05:00 custom: Author: michelleark emmyoop From 4ecd7cf8abd2f3563befd4f7a206f151ce273499 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Wed, 22 Mar 2023 10:29:39 -0500 Subject: [PATCH 5/7] reorg tests --- tests/functional/adapter/test_constraints.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index b4553dcd1..1d6a29240 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -71,17 +71,18 @@ def expected_sql(self): return _expected_sql_snowflake +class TestSnowflakeIncrementalConstraintsDdlEnforcement(BaseIncrementalConstraintsRuntimeDdlEnforcement): + @pytest.fixture(scope="class") + def expected_sql(self): + return _expected_sql_snowflake + + class TestSnowflakeTableConstraintsRollback(BaseConstraintsRollback): @pytest.fixture(scope="class") def expected_error_messages(self): return ["NULL result in a non-nullable column"] -class TestSnowflakeIncrementalConstraintsDdlEnforcement(BaseIncrementalConstraintsRuntimeDdlEnforcement): - @pytest.fixture(scope="class") - def expected_sql(self): - return _expected_sql_snowflake - class TestSnowflakeIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback): @pytest.fixture(scope="class") def expected_error_messages(self): From d2327fd6999c9a130dd104390537c77e393d1a9a Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Wed, 22 Mar 2023 10:30:14 -0500 Subject: [PATCH 6/7] add new lines --- tests/functional/adapter/test_constraints.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index 1d6a29240..45df88fb5 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -54,6 +54,7 @@ def data_types(self, int_type, schema_int_type, string_type): ["""TO_VARIANT(PARSE_JSON('{"key3": "value3", "key4": "value4"}'))""", 'variant', 'VARIANT'], ] + class TestSnowflakeTableConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseTableConstraintsColumnsEqual): pass @@ -65,6 +66,7 @@ class TestSnowflakeViewConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseVi class TestSnowflakeIncrementalConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseIncrementalConstraintsColumnsEqual): pass + class TestSnowflakeTableConstraintsDdlEnforcement(BaseConstraintsRuntimeDdlEnforcement): @pytest.fixture(scope="class") def expected_sql(self): @@ -86,4 +88,4 @@ def expected_error_messages(self): class TestSnowflakeIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback): @pytest.fixture(scope="class") def expected_error_messages(self): - return ["NULL result in a non-nullable column"] \ No newline at end of file + return ["NULL result in a non-nullable column"] From 5cee2e4aa516867aa602845b24449e3a22767a54 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Mon, 27 Mar 2023 14:10:32 -0500 Subject: [PATCH 7/7] reset dev reqs --- dev-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 2e9aa85e9..8d67d4a4f 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git@er/ct-2293-incremental-mat#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git@er/ct-2293-incremental-mat#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor