Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-scott committed Dec 19, 2023
1 parent e719d71 commit e4a7869
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 33 deletions.
5 changes: 5 additions & 0 deletions tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import BaseSingularTestsEphemeral
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp
from dbt.tests.adapter.basic.test_table_materialization import BaseTableMaterialization
from dbt.tests.adapter.basic.test_validate_connection import BaseValidateConnection


Expand Down Expand Up @@ -69,3 +70,7 @@ class TestBaseCachingSQLServer(BaseAdapterMethod):

class TestValidateConnectionSQLServer(BaseValidateConnection):
pass


class TestTableMaterializationSQLServer(BaseTableMaterialization):
...
2 changes: 1 addition & 1 deletion tests/functional/adapter/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def seeds(self):
- name: expected
config:
column_types:
timestamp_col: "datetimeoffset"
timestamp_col: "datetime2"
"""

return {
Expand Down
6 changes: 5 additions & 1 deletion tests/functional/adapter/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import re

import pytest
import yaml
from dbt.cli.exceptions import DbtUsageException
from dbt.tests.adapter.dbt_debug.test_dbt_debug import BaseDebug, BaseDebugProfileVariable
from dbt.tests.util import run_dbt

Expand Down Expand Up @@ -48,7 +50,9 @@ def test_badproject(self, project):
self.check_project(splitout)

def test_not_found_project(self, project):
run_dbt(["debug", "--project-dir", "nopass"], expect_pass=False)
with pytest.raises(DbtUsageException) as dbt_exeption:
run_dbt(["debug", "--project-dir", "nopass"], expect_pass=False)
dbt_exeption = dbt_exeption
splitout = self.capsys.readouterr().out.split("\n")
self.check_project(splitout, msg="ERROR not found")

Expand Down
38 changes: 36 additions & 2 deletions tests/functional/adapter/test_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from dbt.tests.adapter.grants.test_invalid_grants import BaseInvalidGrants
from dbt.tests.adapter.grants.test_model_grants import BaseModelGrants
from dbt.tests.adapter.grants.test_seed_grants import BaseSeedGrants
from dbt.tests.adapter.grants.test_snapshot_grants import BaseSnapshotGrants
from dbt.tests.adapter.grants.test_snapshot_grants import (
BaseSnapshotGrants,
user2_snapshot_schema_yml,
)
from dbt.tests.util import get_manifest, run_dbt, run_dbt_and_capture, write_file


class TestIncrementalGrantsSQLServer(BaseIncrementalGrants):
Expand All @@ -26,4 +30,34 @@ class TestSeedGrantsSQLServer(BaseSeedGrants):


class TestSnapshotGrantsSQLServer(BaseSnapshotGrants):
pass
def test_snapshot_grants(self, project, get_test_users):
test_users = get_test_users
select_privilege_name = self.privilege_grantee_name_overrides()["select"]

# run the snapshot
results = run_dbt(["snapshot"])
assert len(results) == 1
manifest = get_manifest(project.project_root)
snapshot_id = "snapshot.test.my_snapshot"
snapshot = manifest.nodes[snapshot_id]
expected = {select_privilege_name: [test_users[0]]}
assert snapshot.config.grants == expected
self.assert_expected_grants_match_actual(project, "my_snapshot", expected)

# run it again, nothing should have changed
# we do expect to see the grant again.
# dbt selects into a temporary table, drops existing, selects into original table name
# this means we need to grant select again, so we will see the grant again
(results, log_output) = run_dbt_and_capture(["--debug", "snapshot"])
assert len(results) == 1
assert "revoke " not in log_output
assert "grant " in log_output
self.assert_expected_grants_match_actual(project, "my_snapshot", expected)

# change the grantee, assert it updates
updated_yaml = self.interpolate_name_overrides(user2_snapshot_schema_yml)
write_file(updated_yaml, project.project_root, "snapshots", "schema.yml")
(results, log_output) = run_dbt_and_capture(["--debug", "snapshot"])
assert len(results) == 1
expected = {select_privilege_name: [test_users[1]]}
self.assert_expected_grants_match_actual(project, "my_snapshot", expected)
13 changes: 7 additions & 6 deletions tests/functional/adapter/test_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

from dbt.adapters.sqlserver import SQLServerAdapter

fixed_setup_sql = seeds__expected_sql.replace("TIMESTAMP WITHOUT TIME ZONE", "DATETIME").replace(
"TEXT", "VARCHAR(255)"
)
fixed_setup_sql = seeds__expected_sql.replace(
"TIMESTAMP WITHOUT TIME ZONE", "DATETIME2(6)"
).replace("TEXT", "VARCHAR(255)")

seeds__tricky_csv = """
seed_id,seed_id_str,a_bool,looks_like_a_bool,a_date,looks_like_a_date,relative,weekday
Expand Down Expand Up @@ -104,7 +104,7 @@
- name: a_date
tests:
- column_type:
type: datetime
type: datetime2
- name: looks_like_a_date
tests:
- column_type:
Expand Down Expand Up @@ -217,5 +217,6 @@ def test_custom_batch_size(self, project, logs_dir):
run_dbt(["seed"])
with open(os.path.join(logs_dir, "dbt.log"), "r") as fp:
logs = "".join(fp.readlines())

assert "Inserting batches of 350 records" in logs
# this is changed from 350.
# Fabric goes -1 of min batch of (2100/number of columns -1) or 400
assert "Inserting batches of 349.0 records" in logs
46 changes: 23 additions & 23 deletions tests/functional/adapter/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def macros(self):
}


class TestAnyValueSQLServer(BaseFixedMacro, BaseAnyValue):
class TestAnyValueSQLServer(BaseAnyValue):
pass


@pytest.mark.skip("bool_or not supported in this adapter")
class TestBoolOrSQLServer(BaseFixedMacro, BaseBoolOr):
class TestBoolOrSQLServer(BaseBoolOr):
pass


class TestCastBoolToTextSQLServer(BaseFixedMacro, BaseCastBoolToText):
class TestCastBoolToTextSQLServer(BaseCastBoolToText):
@pytest.fixture(scope="class")
def models(self):
models__test_cast_bool_to_text_sql = """
Expand Down Expand Up @@ -82,7 +82,7 @@ def models(self):
}


class TestConcatSQLServer(BaseFixedMacro, BaseConcat):
class TestConcatSQLServer(BaseConcat):
@pytest.fixture(scope="class")
def seeds(self):
return {
Expand All @@ -94,7 +94,7 @@ def seeds(self):
}


class TestDateTruncSQLServer(BaseFixedMacro, BaseDateTrunc):
class TestDateTruncSQLServer(BaseDateTrunc):
pass


Expand All @@ -105,41 +105,41 @@ class TestDateTruncSQLServer(BaseFixedMacro, BaseDateTrunc):
,d41d8cd98f00b204e9800998ecf8427e"""


class TestHashSQLServer(BaseFixedMacro, BaseHash):
class TestHashSQLServer(BaseHash):
@pytest.fixture(scope="class")
def seeds(self):
return {"data_hash.csv": seeds__data_hash_csv}


class TestStringLiteralSQLServer(BaseFixedMacro, BaseStringLiteral):
class TestStringLiteralSQLServer(BaseStringLiteral):
pass


class TestSplitPartSQLServer(BaseFixedMacro, BaseSplitPart):
class TestSplitPartSQLServer(BaseSplitPart):
pass


class TestDateDiffSQLServer(BaseFixedMacro, BaseDateDiff):
class TestDateDiffSQLServer(BaseDateDiff):
pass


class TestEscapeSingleQuotesSQLServer(BaseFixedMacro, BaseEscapeSingleQuotesQuote):
class TestEscapeSingleQuotesSQLServer(BaseEscapeSingleQuotesQuote):
pass


class TestIntersectSQLServer(BaseFixedMacro, BaseIntersect):
class TestIntersectSQLServer(BaseIntersect):
pass


class TestLastDaySQLServer(BaseFixedMacro, BaseLastDay):
class TestLastDaySQLServer(BaseLastDay):
pass


class TestLengthSQLServer(BaseFixedMacro, BaseLength):
class TestLengthSQLServer(BaseLength):
pass


class TestListaggSQLServer(BaseFixedMacro, BaseListagg):
class TestListaggSQLServer(BaseListagg):
# Only supported in SQL Server 2017 and later or cloud versions
# DISTINCT not supported
# limit not supported
Expand Down Expand Up @@ -221,15 +221,15 @@ def models(self):
}


class TestRightSQLServer(BaseFixedMacro, BaseRight):
class TestRightSQLServer(BaseRight):
pass


class TestSafeCastSQLServer(BaseFixedMacro, BaseSafeCast):
class TestSafeCastSQLServer(BaseSafeCast):
pass


class TestDateAddSQLServer(BaseFixedMacro, BaseDateAdd):
class TestDateAddSQLServer(BaseDateAdd):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
Expand All @@ -247,15 +247,15 @@ def project_config_update(self):
}


class TestExceptSQLServer(BaseFixedMacro, BaseExcept):
class TestExceptSQLServer(BaseExcept):
pass


class TestPositionSQLServer(BaseFixedMacro, BasePosition):
class TestPositionSQLServer(BasePosition):
pass


class TestReplaceSQLServer(BaseFixedMacro, BaseReplace):
class TestReplaceSQLServer(BaseReplace):
pass


Expand All @@ -264,15 +264,15 @@ class TestCurrentTimestampSQLServer(BaseCurrentTimestampNaive):


@pytest.mark.skip(reason="arrays not supported")
class TestArrayAppendSQLServer(BaseFixedMacro, BaseArrayAppend):
class TestArrayAppendSQLServer(BaseArrayAppend):
pass


@pytest.mark.skip(reason="arrays not supporteTd")
class TestArrayConcatSQLServer(BaseFixedMacro, BaseArrayConcat):
class TestArrayConcatSQLServer(BaseArrayConcat):
pass


@pytest.mark.skip(reason="arrays not supported")
class TestArrayConstructSQLServer(BaseFixedMacro, BaseArrayConstruct):
class TestArrayConstructSQLServer(BaseArrayConstruct):
pass

0 comments on commit e4a7869

Please sign in to comment.