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 sql_header tests for constraints #750

Merged
merged 5 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230601-120430.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: test model constraints with sql headers
time: 2023-06-01T12:04:30.876751-04:00
custom:
Author: michelleark
Issue: "7714"
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -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@7714/model-contracts-sql-header#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git@7714/model-contracts-sql-header#egg=dbt-tests-adapter&subdirectory=tests/adapter
MichelleArk marked this conversation as resolved.
Show resolved Hide resolved

# if version 1.x or greater -> pin to major version
# if version 0.x -> pin to minor
Expand Down
52 changes: 52 additions & 0 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
BaseTableConstraintsColumnsEqual,
BaseViewConstraintsColumnsEqual,
BaseIncrementalConstraintsColumnsEqual,
BaseTableContractSqlHeader,
BaseIncrementalContractSqlHeader,
BaseConstraintsRuntimeDdlEnforcement,
BaseConstraintsRollback,
BaseIncrementalConstraintsRuntimeDdlEnforcement,
Expand All @@ -20,6 +22,7 @@
my_model_incremental_wrong_name_sql,
model_schema_yml,
constrained_model_schema_yml,
model_contract_header_schema_yml,
)

_expected_sql_bigquery = """
Expand All @@ -45,6 +48,37 @@
# - does not support a data type named 'text' (TODO handle this via type translation/aliasing!)
constraints_yml = model_schema_yml.replace("text", "string")
model_constraints_yml = constrained_model_schema_yml.replace("text", "string")
model_contract_header_schema_yml = model_contract_header_schema_yml.replace("text", "string")


my_model_contract_sql_header_sql = """
{{
config(
materialized = "table"
)
}}

{% call set_sql_header(config) %}
DECLARE DEMO STRING DEFAULT 'hello world';
{% endcall %}

SELECT DEMO as column_name
"""

my_model_incremental_contract_sql_header_sql = """
{{
config(
materialized = "incremental",
on_schema_change="append_new_columns"
)
}}

{% call set_sql_header(config) %}
DECLARE DEMO STRING DEFAULT 'hello world';
{% endcall %}

SELECT DEMO as column_name
"""


class BigQueryColumnEqualSetup:
Expand Down Expand Up @@ -113,6 +147,24 @@ def models(self):
}


class TestBigQueryTableContractsSqlHeader(BaseTableContractSqlHeader):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model_contract_sql_header.sql": my_model_contract_sql_header_sql,
"constraints_schema.yml": model_contract_header_schema_yml,
}


class TestBigQueryIncrementalContractsSqlHeader(BaseIncrementalContractSqlHeader):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model_contract_sql_header.sql": my_model_incremental_contract_sql_header_sql,
"constraints_schema.yml": model_contract_header_schema_yml,
}


class TestBigQueryTableConstraintsRuntimeDdlEnforcement(BaseConstraintsRuntimeDdlEnforcement):
@pytest.fixture(scope="class")
def models(self):
Expand Down