Skip to content

Commit

Permalink
Add new tests from dbt-tests-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 committed Jul 28, 2023
1 parent 28136bf commit 95c652e
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20230728-180251.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Add new tests from dbt-tests-adapter
time: 2023-07-28T18:02:51.112439+02:00
custom:
Author: damian3031
Issue: ""
PR: "335"
69 changes: 69 additions & 0 deletions tests/functional/adapter/constraints/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
trino_model_contract_sql_header_sql = """
{{
config(
materialized = "table"
)
}}
{% call set_sql_header(config) %}
set time zone 'Asia/Kolkata';
{%- endcall %}
select current_timezone() as column_name
"""

trino_model_incremental_contract_sql_header_sql = """
{{
config(
materialized = "incremental",
on_schema_change="append_new_columns"
)
}}
{% call set_sql_header(config) %}
set time zone 'Asia/Kolkata';
{%- endcall %}
select current_timezone() as column_name
"""

trino_model_schema_yml = """
version: 2
models:
Expand Down Expand Up @@ -105,3 +132,45 @@
- name: date_day
data_type: varchar
"""

trino_model_quoted_column_schema_yml = """
version: 2
models:
- name: my_model
config:
contract:
enforced: true
materialized: table
constraints:
- type: check
# this one is the on the user
expression: ("from" = 'blue')
columns: [ '"from"' ]
columns:
- name: id
data_type: integer
description: hello
constraints:
- type: not_null
tests:
- unique
- name: from # reserved word
quote: true
data_type: varchar
constraints:
- type: not_null
- name: date_day
data_type: varchar
"""

trino_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
"""
56 changes: 56 additions & 0 deletions tests/functional/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
my_model_sql,
my_model_view_wrong_name_sql,
my_model_view_wrong_order_sql,
my_model_with_quoted_column_name_sql,
my_model_wrong_name_sql,
my_model_wrong_order_sql,
)
from dbt.tests.adapter.constraints.test_constraints import (
BaseConstraintQuotedColumn,
BaseConstraintsRollback,
BaseConstraintsRuntimeDdlEnforcement,
BaseIncrementalConstraintsColumnsEqual,
BaseIncrementalConstraintsRollback,
BaseIncrementalConstraintsRuntimeDdlEnforcement,
BaseIncrementalContractSqlHeader,
BaseModelConstraintsRuntimeEnforcement,
BaseTableConstraintsColumnsEqual,
BaseTableContractSqlHeader,
BaseViewConstraintsColumnsEqual,
)

from tests.functional.adapter.constraints.fixtures import (
trino_constrained_model_schema_yml,
trino_model_contract_header_schema_yml,
trino_model_contract_sql_header_sql,
trino_model_incremental_contract_sql_header_sql,
trino_model_quoted_column_schema_yml,
trino_model_schema_yml,
)

Expand Down Expand Up @@ -167,6 +175,24 @@ def expected_error_messages(self):
return ["NULL value not allowed for NOT NULL column: id"]


class TestTrinoTableContractSqlHeader(BaseTableContractSqlHeader):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model_contract_sql_header.sql": trino_model_contract_sql_header_sql,
"constraints_schema.yml": trino_model_contract_header_schema_yml,
}


class TestTrinoIncrementalContractSqlHeader(BaseIncrementalContractSqlHeader):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model_contract_sql_header.sql": trino_model_incremental_contract_sql_header_sql,
"constraints_schema.yml": trino_model_contract_header_schema_yml,
}


@pytest.mark.iceberg
class TestTrinoModelConstraintsRuntimeEnforcement(BaseModelConstraintsRuntimeEnforcement):
@pytest.fixture(scope="class")
Expand Down Expand Up @@ -199,3 +225,33 @@ def expected_sql(self):
)
;
"""


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

@pytest.fixture(scope="class")
def expected_sql(self):
return """
create table <model_identifier> (
id integer not null,
"from" varchar not null,
date_day varchar
) ;
insert into <model_identifier>
(
select id, "from", date_day
from (
select
'blue' as "from",
1 as id,
'2019-01-01' as date_day
) as model_subq
);
"""
5 changes: 5 additions & 0 deletions tests/functional/adapter/dbt_clone/test_dbt_clone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dbt.tests.adapter.dbt_clone.test_dbt_clone import BaseCloneNotPossible


class TestTrinoCloneNotPossible(BaseCloneNotPossible):
pass
17 changes: 17 additions & 0 deletions tests/functional/adapter/dbt_debug/test_dbt_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dbt.tests.adapter.dbt_debug.test_dbt_debug import (
BaseDebug,
BaseDebugProfileVariable,
)
from dbt.tests.util import run_dbt


class TestDebugTrino(BaseDebug):
def test_ok_trino(self, project):
run_dbt(["debug"])
assert "ERROR" not in self.capsys.readouterr().out


class TestDebugProfileVariableTrino(BaseDebugProfileVariable):
def test_ok_trino(self, project):
run_dbt(["debug"])
assert "ERROR" not in self.capsys.readouterr().out
10 changes: 10 additions & 0 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dbt.tests.adapter.utils.test_date_trunc import BaseDateTrunc
from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd
from dbt.tests.adapter.utils.test_datediff import BaseDateDiff
from dbt.tests.adapter.utils.test_equals import BaseEquals
from dbt.tests.adapter.utils.test_escape_single_quotes import (
BaseEscapeSingleQuotesQuote,
)
Expand All @@ -26,6 +27,7 @@
from dbt.tests.adapter.utils.test_safe_cast import BaseSafeCast
from dbt.tests.adapter.utils.test_split_part import BaseSplitPart
from dbt.tests.adapter.utils.test_string_literal import BaseStringLiteral
from dbt.tests.adapter.utils.test_validate_sql import BaseValidateSqlMethod

from tests.functional.adapter.fixture_datediff import (
models__test_datediff_sql,
Expand Down Expand Up @@ -146,6 +148,10 @@ def project_config_update(self):
}


class TestEquals(BaseEquals):
pass


class TestEscapeSingleQuotes(BaseEscapeSingleQuotesQuote):
pass

Expand Down Expand Up @@ -196,3 +202,7 @@ class TestSplitPart(BaseSplitPart):

class TestStringLiteral(BaseStringLiteral):
pass


class TestValidateSqlMethod(BaseValidateSqlMethod):
pass

0 comments on commit 95c652e

Please sign in to comment.