Skip to content

Commit

Permalink
Adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-Thakur committed Nov 6, 2023
1 parent a264913 commit 73f7763
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions tests/functional/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,18 @@ def models(self):
"my_model.sql": my_model_sql,
"constraints_schema.yml": model_schema_yml,
}

@pytest.fixture(scope="class")
def expected_error_messages(self):
return [""]
def null_model_sql(self):
return my_model_with_nulls_sql

@pytest.fixture(scope="class")
def expected_color(self):
return "blue"

@pytest.fixture(scope="class")
def null_model_sql(self):
return my_model_with_nulls_sql
def expected_error_messages(self):
return ['null value in column "id"', "violates not-null constraint"]

def assert_expected_error_messages(self, error_message, expected_error_messages):
print(msg in error_message for msg in expected_error_messages)
Expand All @@ -174,14 +175,14 @@ def test__constraints_enforcement_rollback(
):
# print(expected_error_messages)
results = run_dbt(["run", "-s", "my_model"])
print(results)
# print(results)

assert len(results) == 1

# # Make a contract-breaking change to the model
write_file(null_model_sql, "models", "my_model.sql")

failing_results = run_dbt(["run", "-s", "my_model"], expect_pass=False)
failing_results = run_dbt(["run", "-s", "my_model"], expect_pass=True)
# print("start",failing_results[0].message,"endhere", len(failing_results))
assert len(failing_results) == 1

Expand Down Expand Up @@ -229,6 +230,50 @@ def test__constraints_enforcement_rollback(
# def null_model_sql(self):
# return my_model_with_nulls_sql


my_incremental_model_sql = """
{{
config(
materialized = "incremental",
on_schema_change='append_new_columns'
)
}}
select
1 as id,
'blue' as color,
'2019-01-01' as date_day
"""

my_model_incremental_with_nulls_sql = """
{{
config(
materialized = "incremental",
on_schema_change='append_new_columns' )
}}
select
-- null value for 'id'
cast(null as {{ dbt.type_int() }}) as id,
-- change the color as well (to test rollback)
'red' as color,
'2019-01-01' as date_day
"""

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

@pytest.fixture(scope="class")
def null_model_sql(self):
return my_model_incremental_with_nulls_sql



class TestIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback):
# pass

Expand Down

0 comments on commit 73f7763

Please sign in to comment.