Skip to content

Commit

Permalink
95 dbt16 tests (#99)
Browse files Browse the repository at this point in the history
* adding table & incremental sql header model test

* add validate-sql & null_compare tests

* poetry updated & tox.ini list
  • Loading branch information
tglunde authored Nov 3, 2023
1 parent 368cf8f commit 06115b3
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 186 deletions.
6 changes: 6 additions & 0 deletions dbt/include/exasol/macros/validate_sql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% macro exasol__validate_sql(sql) -%}
{% call statement('validate_sql') -%}
{{ sql }} limit 0
{% endcall %}
{{ return(load_result('validate_sql')) }}
{% endmacro %}
337 changes: 170 additions & 167 deletions poetry.lock

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion tests/functional/adapter/constraints/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,43 @@
|separatemeplease|
insert into <model_identifier>
select id, color, date_day from ( select 'blue' as color, 1 as id, '2019-01-01' as date_day ) as model_subq
"""
"""

exasol_model_contract_sql_header_sql = """
{{
config(
materialized = "table"
)
}}
{% call set_sql_header(config) %}
alter session set TIME_ZONE = 'Asia/Kolkata';
{%- endcall %}
select session_parameter(current_session, 'TIME_ZONE') as column_name
"""

exasol_model_incremental_contract_sql_header = """
{{
config(
materialized = "incremental",
on_schema_change="append_new_columns"
)
}}
{% call set_sql_header(config) %}
alter session set TIME_ZONE = 'Asia/Kolkata';
{%- endcall %}
select session_parameter(current_session, 'TIME_ZONE') as column_name
"""

exasol_model_contract_header_schema_yml = """
version: 2
models:
- name: my_model_contract_sql_header
config:
contract:
enforced: true
columns:
- name: column_name
data_type: varchar(2000000)
"""
97 changes: 80 additions & 17 deletions tests/functional/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from dbt.tests.adapter.constraints.test_constraints import (
BaseConstraintsRollback,
BaseConstraintsRuntimeDdlEnforcement,
BaseContractSqlHeader,
BaseIncrementalConstraintsColumnsEqual,
BaseIncrementalConstraintsRollback,
BaseIncrementalConstraintsRuntimeDdlEnforcement,
BaseModelConstraintsRuntimeEnforcement,
BaseTableConstraintsColumnsEqual,
BaseViewConstraintsColumnsEqual,
BaseConstraintQuotedColumn
BaseConstraintQuotedColumn,
)

from dbt.tests.util import (
Expand All @@ -36,13 +37,17 @@
my_model_view_wrong_order_sql,
my_model_view_wrong_name_sql,
exasol_expected_sql,
exasol_model_contract_sql_header_sql,
exasol_model_incremental_contract_sql_header,
exasol_model_contract_header_schema_yml,
)


class ExasolColumnEqualSetup:
@pytest.fixture
def string_type(self):
return "CHAR(50)"

@pytest.fixture
def int_type(self):
return "INTEGER"
Expand All @@ -55,7 +60,11 @@ def data_types(self, schema_int_type, int_type, string_type):
["'1'", string_type, string_type],
["cast('2019-01-01' as date)", "date", "DATE"],
["true", "boolean", "BOOLEAN"],
["cast('2013-11-03T00:00:00.000000' as TIMESTAMP)", "timestamp(6)", "TIMESTAMP"],
[
"cast('2013-11-03T00:00:00.000000' as TIMESTAMP)",
"timestamp(6)",
"TIMESTAMP",
],
["cast('1.0' as DECIMAL(10,2))", "DECIMAL", "DECIMAL"],
]

Expand All @@ -70,12 +79,22 @@ def models(self):
"my_model_wrong_name.sql": my_model_wrong_name_sql,
"constraints_schema.yml": exasol_model_schema_yml,
}

def test__constraints_wrong_column_data_types(self, project, string_type, int_type, schema_string_type, schema_int_type, data_types):

def test__constraints_wrong_column_data_types(
self,
project,
string_type,
int_type,
schema_string_type,
schema_int_type,
data_types,
):
pass


class TestExasolViewConstraintsColumnsEqual(ExasolColumnEqualSetup, BaseViewConstraintsColumnsEqual):
class TestExasolViewConstraintsColumnsEqual(
ExasolColumnEqualSetup, BaseViewConstraintsColumnsEqual
):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -84,9 +103,18 @@ def models(self):
"constraints_schema.yml": exasol_model_schema_yml,
}

def test__constraints_wrong_column_data_types(self, project, string_type, int_type, schema_string_type, schema_int_type, data_types):
def test__constraints_wrong_column_data_types(
self,
project,
string_type,
int_type,
schema_string_type,
schema_int_type,
data_types,
):
pass


class TestExasolIncrementalConstraintsColumnsEqual(
ExasolColumnEqualSetup, BaseIncrementalConstraintsColumnsEqual
):
Expand All @@ -98,11 +126,21 @@ def models(self):
"constraints_schema.yml": exasol_model_schema_yml,
}

def test__constraints_wrong_column_data_types(self, project, string_type, int_type, schema_string_type, schema_int_type, data_types):
def test__constraints_wrong_column_data_types(
self,
project,
string_type,
int_type,
schema_string_type,
schema_int_type,
data_types,
):
pass


class TestExasolTableConstraintsRuntimeDdlEnforcement(BaseConstraintsRuntimeDdlEnforcement):
class TestExasolTableConstraintsRuntimeDdlEnforcement(
BaseConstraintsRuntimeDdlEnforcement
):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -115,19 +153,18 @@ def expected_sql(self):
return exasol_expected_sql



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

@pytest.fixture(scope="class")
def expected_error_messages(self):
return ["constraint violation - not null"]

# Exasol constraint failures generate their own error messages which have to be handled differently than in the standard tests
def test__constraints_enforcement_rollback(
self, project, expected_color, expected_error_messages, null_model_sql
Expand Down Expand Up @@ -169,7 +206,7 @@ def models(self):
@pytest.fixture(scope="class")
def expected_error_messages(self):
return ["constraint violation - not null"]

# Exasol constraint failures generate their own error messages which have to be handled differently than in the standard tests
def test__constraints_enforcement_rollback(
self, project, expected_color, expected_error_messages, null_model_sql
Expand All @@ -185,8 +222,9 @@ def test__constraints_enforcement_rollback(
assert expected_error_messages[0] in failing_results[0].message



class TestExasolModelConstraintsRuntimeEnforcement(BaseModelConstraintsRuntimeEnforcement):
class TestExasolModelConstraintsRuntimeEnforcement(
BaseModelConstraintsRuntimeEnforcement
):
@pytest.fixture(scope="class")
def models(self):
return {
Expand Down Expand Up @@ -214,14 +252,15 @@ def expected_sql(self):
'2019-01-01' as date_day ) as model_subq
"""


class TestExasolConstraintQuotedColumn(BaseConstraintQuotedColumn):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_with_quoted_column_name_sql,
"constraints_schema.yml": exasol_quoted_column_schema_yml,
}

@pytest.fixture(scope="class")
def expected_sql(self):
return """
Expand All @@ -240,4 +279,28 @@ def expected_sql(self):
1 as id,
'2019-01-01' as date_day
) as model_subq
"""
"""

class BaseExasolTableContractSqlHeader(BaseContractSqlHeader):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model_contract_sql_header.sql": exasol_model_contract_sql_header_sql,
"constraints_schema.yml": exasol_model_contract_header_schema_yml,
}

class BaseExasolIncrementalContractSqlHeader(BaseContractSqlHeader):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model_contract_sql_header.sql": exasol_model_incremental_contract_sql_header,
"constraints_schema.yml": exasol_model_contract_header_schema_yml,

}

class TestExasolTableContractSqlHeader(BaseExasolTableContractSqlHeader):
pass

class TestExasolIncrementalContractSqlHeader(BaseExasolIncrementalContractSqlHeader):
pass

12 changes: 12 additions & 0 deletions tests/functional/adapter/utils/test_null_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dbt.tests.adapter.utils.test_null_compare import (
BaseMixedNullCompare,
BaseNullCompare,
)


class TestExasolMixedNullCompare(BaseMixedNullCompare):
pass


class TestExasolNullCompareBaseNullCompare(BaseNullCompare):
pass
8 changes: 8 additions & 0 deletions tests/functional/adapter/utils/test_validate_sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from dbt.tests.adapter.basic.test_generic_tests import pytest
from dbt.tests.adapter.utils.test_validate_sql import BaseValidateSqlMethod


class TestExasolValidateSqlMethod(BaseValidateSqlMethod):
@pytest.fixture(scope="class")
def valid_sql(self) -> str:
return "select 1 as column_name"
6 changes: 5 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[tox]
isolated_build = True
env_list = py{38,39,310,311}
env_list =
py38
py39
py310
311

[testenv]
passenv = *
Expand Down

0 comments on commit 06115b3

Please sign in to comment.