Skip to content

Commit

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

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

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

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

def assert_expected_error_messages(self, error_message, expected_error_messages):
print(msg in error_message for msg in expected_error_messages)
Expand All @@ -175,14 +174,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=True)
failing_results = run_dbt(["run", "-s", "my_model"], expect_pass=False)
# print("start",failing_results[0].message,"endhere", len(failing_results))
assert len(failing_results) == 1

Expand Down Expand Up @@ -230,50 +229,6 @@ 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 736829c

Please sign in to comment.