Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for enforcing contracts on incremental materializations #529

Merged
merged 7 commits into from
Mar 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
@@ -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,
BaseIncrementalConstraintsRuntimeDdlEnforcement,
BaseIncrementalConstraintsRollback,
)


_expected_sql_snowflake = """
create or replace transient table {0} (
create or replace transient table <model_identifier> (
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
id integer not null primary key,
color text,
date_day text
Expand Down Expand Up @@ -51,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

Expand All @@ -59,13 +63,29 @@ class TestSnowflakeViewConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseVi
pass


class TestSnowflakeConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement):
class TestSnowflakeIncrementalConstraintsColumnsEqual(SnowflakeColumnEqualSetup, BaseIncrementalConstraintsColumnsEqual):
pass


class TestSnowflakeTableConstraintsDdlEnforcement(BaseConstraintsRuntimeDdlEnforcement):
@pytest.fixture(scope="class")
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_sql(self, project):
relation = relation_from_name(project.adapter, "my_model")
return _expected_sql_snowflake.format(relation)
def expected_error_messages(self):
return ["NULL result in a non-nullable column"]


class TestSnowflakeIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback):
@pytest.fixture(scope="class")
def expected_error_messages(self):
return ["NULL result in a non-nullable column"]