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 3010f20 commit fe39fc9
Showing 1 changed file with 51 additions and 31 deletions.
82 changes: 51 additions & 31 deletions tests/functional/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,24 @@
data_type: text
"""


class BaseConstraintsRollback:
@pytest.fixture(scope="class")
def models(self):
return {
"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 @@ -166,15 +164,15 @@ 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)
# print("start",failing_results[0].message,"endhere", len(failing_results))
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

# # Verify the previous table still exists
Expand All @@ -200,7 +198,29 @@ def test__constraints_enforcement_rollback(



# class TestIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback):


# @pytest.fixture(scope="class")
# def models(self):
# return {
# "my_model.sql": my_model_sql,
# "constraints_schema.yml": model_schema_yml,
# }
# @pytest.fixture(scope="class")
# def expected_error_messages(self):
# return [""]

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

class TestIncrementalConstraintsRollback(BaseIncrementalConstraintsRollback):
# pass

@pytest.fixture(scope="class")
def models(self):
Expand All @@ -224,33 +244,33 @@ def null_model_sql(self):



class TestValidateSqlMethod(BaseValidateSqlMethod):
pass
# class TestValidateSqlMethod(BaseValidateSqlMethod):
# pass

class TestNullCompare(BaseNullCompare):
pass
# class TestNullCompare(BaseNullCompare):
# pass


class TestMixedNullCompare(BaseMixedNullCompare):
pass
# class TestMixedNullCompare(BaseMixedNullCompare):
# pass


class TestEquals(BaseEquals):
pass
# class TestEquals(BaseEquals):
# pass




class TestConstraintQuotedColumn(BaseConstraintQuotedColumn):
@pytest.fixture(scope="class")
def expected_sql(self):
return """
create table <model_identifier> INCLUDE SCHEMA PRIVILEGES as ( select 'blue' as "from", 1 as id, '2019-01-01' as date_day ) ; """
pass
# class TestConstraintQuotedColumn(BaseConstraintQuotedColumn):
# @pytest.fixture(scope="class")
# def expected_sql(self):
# return """
# create table <model_identifier> INCLUDE SCHEMA PRIVILEGES as ( select 'blue' as "from", 1 as id, '2019-01-01' as date_day ) ; """
# pass

class TestModelConstraintsRuntimeEnforcement(BaseModelConstraintsRuntimeEnforcement):
@pytest.fixture(scope="class")
def expected_sql(self):
return """
create table <model_identifier> INCLUDE SCHEMA PRIVILEGES as ( -- depends_on: <foreign_key_model_identifier> select 'blue' as color, 1 as id, '2019-01-01' as date_day ) ;
"""
# class TestModelConstraintsRuntimeEnforcement(BaseModelConstraintsRuntimeEnforcement):
# @pytest.fixture(scope="class")
# def expected_sql(self):
# return """
# create table <model_identifier> INCLUDE SCHEMA PRIVILEGES as ( -- depends_on: <foreign_key_model_identifier> select 'blue' as color, 1 as id, '2019-01-01' as date_day ) ;
# """

0 comments on commit fe39fc9

Please sign in to comment.