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 #608

Merged
merged 5 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
85 changes: 76 additions & 9 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
from dbt.tests.adapter.constraints.test_constraints import (
BaseTableConstraintsColumnsEqual,
BaseViewConstraintsColumnsEqual,
BaseConstraintsRuntimeEnforcement
BaseIncrementalConstraintsColumnsEqual,
BaseConstraintsRuntimeDdlEnforcement,
BaseConstraintsRollback,
BaseIncrementalConstraintsRuntimeDdlEnforcement,
BaseIncrementalConstraintsRollback,
)
from dbt.tests.adapter.constraints.fixtures import (
my_model_sql,
my_incremental_model_sql,
my_model_wrong_order_sql,
my_model_wrong_name_sql,
my_model_view_wrong_order_sql,
my_model_incremental_wrong_order_sql,
my_model_wrong_name_sql,
my_model_view_wrong_name_sql,
my_model_incremental_wrong_name_sql,
model_schema_yml,
)

_expected_sql_bigquery = """
create or replace table {0} (
create or replace table <model_identifier> (
id integer not null,
color string,
date_day string
Expand Down Expand Up @@ -65,7 +72,10 @@ def data_types(self, int_type, string_type):
]


class TestBigQueryTableConstraintsColumnsEqual(BigQueryColumnEqualSetup, BaseTableConstraintsColumnsEqual):
class TestBigQueryTableConstraintsColumnsEqual(
BigQueryColumnEqualSetup,
BaseTableConstraintsColumnsEqual
):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -75,7 +85,10 @@ def models(self):
}


class TestBigQueryViewConstraintsColumnsEqual(BigQueryColumnEqualSetup, BaseViewConstraintsColumnsEqual):
class TestBigQueryViewConstraintsColumnsEqual(
BigQueryColumnEqualSetup,
BaseViewConstraintsColumnsEqual
):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -85,19 +98,73 @@ def models(self):
}


class TestBigQueryConstraintsRuntimeEnforcement(BaseConstraintsRuntimeEnforcement):
class TestBigQueryIncrementalConstraintsColumnsEqual(
BigQueryColumnEqualSetup,
BaseIncrementalConstraintsColumnsEqual
):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_sql,
"my_model_wrong_order.sql": my_model_incremental_wrong_order_sql,
"my_model_wrong_name.sql": my_model_incremental_wrong_name_sql,
"constraints_schema.yml": constraints_yml,
}


class TestBigQueryTableConstraintsRuntimeDdlEnforcement(
BaseConstraintsRuntimeDdlEnforcement
):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_wrong_order_sql,
"constraints_schema.yml": constraints_yml,
}

@pytest.fixture(scope="class")
def expected_sql(self, project):
relation = relation_from_name(project.adapter, "my_model")
return _expected_sql_bigquery.format(relation)
return _expected_sql_bigquery


class TestBigQueryTableConstraintsRollback(
BaseConstraintsRollback
):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_sql,
"constraints_schema.yml": constraints_yml,
}

@pytest.fixture(scope="class")
def expected_error_messages(self):
return ["Required field id cannot be null"]

class TestBigQueryIncrementalConstraintsRuntimeDdlEnforcement(
BaseIncrementalConstraintsRuntimeDdlEnforcement
):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_incremental_wrong_order_sql,
"constraints_schema.yml": constraints_yml,
}

@pytest.fixture(scope="class")
def expected_sql(self, project):
return _expected_sql_bigquery


class TestBigQueryIncrementalConstraintsRollback(
BaseIncrementalConstraintsRollback
):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_incremental_model_sql,
"constraints_schema.yml": constraints_yml,
}

@pytest.fixture(scope="class")
def expected_error_messages(self):
return ["Required field id cannot be null"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a newline at the end here so that the linters don't freak out. I'm actually surprised it passed the code checks. Perhaps we didn't turn it on for tests/functional yet in dbt-spark.