Skip to content

Commit

Permalink
all tests passing locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Ty Schlichenmeyer committed Jan 25, 2024
1 parent 9e84072 commit b36e242
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 22 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "2.7.1",
"resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:f6a73ee06601d703db7d95d03e415cab229e78df92bb5002e8559bcfc047fec6",
"integrity": "sha256:f6a73ee06601d703db7d95d03e415cab229e78df92bb5002e8559bcfc047fec6"
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ venv/
ENV/
env.bak/
venv.bak/
.mise.toml
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.10
python: python3.10.8
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.4.0
Expand Down Expand Up @@ -62,7 +62,7 @@ repos:
- manual
args:
- '--line-length=99'
- '--target-version=py39'
- '--target-version=py310'
- '--check'
- '--diff'
- repo: 'https://github.com/pycqa/flake8'
Expand Down Expand Up @@ -94,4 +94,5 @@ repos:
- '--show-error-codes'
- '--pretty'
- '--ignore-missing-imports'
- '--explicit-package-bases'
files: '^dbt/adapters'
4 changes: 3 additions & 1 deletion dbt/adapters/sqlserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from dbt.adapters.sqlserver.sql_server_adapter import SQLServerAdapter
from dbt.adapters.sqlserver.sql_server_column import SQLServerColumn
from dbt.adapters.sqlserver.sql_server_configs import SQLServerConfigs
from dbt.adapters.sqlserver.sql_server_connection_manager import SQLServerConnectionManager
from dbt.adapters.sqlserver.sql_server_connection_manager import (
SQLServerConnectionManager,
)
from dbt.adapters.sqlserver.sql_server_credentials import SQLServerCredentials
from dbt.include import sqlserver

Expand Down
4 changes: 3 additions & 1 deletion dbt/adapters/sqlserver/sql_server_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from dbt.adapters.sqlserver.sql_server_column import SQLServerColumn
from dbt.adapters.sqlserver.sql_server_configs import SQLServerConfigs
from dbt.adapters.sqlserver.sql_server_connection_manager import SQLServerConnectionManager
from dbt.adapters.sqlserver.sql_server_connection_manager import (
SQLServerConnectionManager,
)

# from dbt.adapters.capability import Capability, CapabilityDict, CapabilitySupport, Support

Expand Down
4 changes: 3 additions & 1 deletion dbt/adapters/sqlserver/sql_server_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def get_sp_access_token(credentials: SQLServerCredentials) -> AccessToken:
The access token.
"""
token = ClientSecretCredential(
str(credentials.tenant_id), str(credentials.client_id), str(credentials.client_secret)
str(credentials.tenant_id),
str(credentials.client_id),
str(credentials.client_secret),
).get_token(AZURE_CREDENTIAL_SCOPE)
return token

Expand Down
1 change: 1 addition & 0 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ wheel==0.42
pre-commit==3.5.0
pytest-dotenv==0.5.2
dbt-tests-adapter==1.7.2
dbt-fabric==1.7.2
flaky==3.7.0
pytest-xdist==3.5.0
-e .
4 changes: 3 additions & 1 deletion tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
BaseIncrementalNotSchemaChange,
)
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import BaseSingularTestsEphemeral
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
Expand Down
7 changes: 6 additions & 1 deletion tests/functional/adapter/test_changing_relation_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from dbt.tests.adapter.relations.test_changing_relation_type import BaseChangeRelationTypeValidator
import pytest

from dbt.tests.adapter.relations.test_changing_relation_type import (
BaseChangeRelationTypeValidator,
)


@pytest.mark.skip(reason="CTAS is not supported without a underlying table definition.")
class TestChangeRelationTypesSQLServer(BaseChangeRelationTypeValidator):
pass
5 changes: 4 additions & 1 deletion tests/functional/adapter/test_concurrency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from dbt.tests.adapter.concurrency.test_concurrency import BaseConcurrency, seeds__update_csv
from dbt.tests.adapter.concurrency.test_concurrency import (
BaseConcurrency,
seeds__update_csv,
)
from dbt.tests.util import (
check_relations_equal,
check_table_does_not_exist,
Expand Down
5 changes: 4 additions & 1 deletion tests/functional/adapter/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
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.adapter.dbt_debug.test_dbt_debug import (
BaseDebug,
BaseDebugProfileVariable,
)
from dbt.tests.util import run_dbt


Expand Down
4 changes: 2 additions & 2 deletions tests/functional/adapter/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def expected_catalog(self, project):
role=os.getenv("DBT_TEST_USER_1"),
id_type="int",
text_type="varchar",
time_type="datetime",
time_type="datetime2",
view_type="VIEW",
table_type="BASE TABLE",
model_stats=no_stats(),
Expand All @@ -49,7 +49,7 @@ def expected_catalog(self, project):
role=os.getenv("DBT_TEST_USER_1"),
id_type="int",
text_type="varchar",
time_type="datetime",
time_type="datetime2",
bigint_type="int",
view_type="VIEW",
table_type="BASE TABLE",
Expand Down
15 changes: 12 additions & 3 deletions tests/functional/adapter/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
from dbt.tests.adapter.incremental.test_incremental_on_schema_change import (
BaseIncrementalOnSchemaChange,
)
from dbt.tests.adapter.incremental.test_incremental_predicates import BaseIncrementalPredicates
from dbt.tests.adapter.incremental.test_incremental_unique_id import BaseIncrementalUniqueKey
from dbt.tests.adapter.incremental.test_incremental_predicates import (
BaseIncrementalPredicates,
)
from dbt.tests.adapter.incremental.test_incremental_unique_id import (
BaseIncrementalUniqueKey,
)

_MODELS__INCREMENTAL_IGNORE = """
{{
Expand Down Expand Up @@ -117,4 +121,9 @@ class TestIncrementalPredicatesDeleteInsertSQLServer(BaseIncrementalPredicates):
class TestPredicatesDeleteInsertSQLServer(BaseIncrementalPredicates):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"models": {"+predicates": ["id != 2"], "+incremental_strategy": "delete+insert"}}
return {
"models": {
"+predicates": ["id != 2"],
"+incremental_strategy": "delete+insert",
}
}
80 changes: 76 additions & 4 deletions tests/functional/adapter/test_seed.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import os

import pytest
from dbt.tests.adapter.simple_seed.seeds import seeds__expected_sql
from dbt.tests.adapter.simple_seed.seeds import seeds__expected_sql, seed__actual_csv
from dbt.tests.adapter.simple_seed.fixtures import models__downstream_from_seed_actual
from dbt.tests.adapter.simple_seed.test_seed import SeedConfigBase
from dbt.tests.adapter.simple_seed.test_seed import TestBasicSeedTests as BaseBasicSeedTests
from dbt.tests.adapter.simple_seed.test_seed import (
TestBasicSeedTests as BaseBasicSeedTests,
)
from dbt.tests.adapter.simple_seed.test_seed import (
TestSeedConfigFullRefreshOff as BaseSeedConfigFullRefreshOff,
)
from dbt.tests.adapter.simple_seed.test_seed import (
TestSeedConfigFullRefreshOn as BaseSeedConfigFullRefreshOn,
)
from dbt.tests.adapter.simple_seed.test_seed import TestSeedCustomSchema as BaseSeedCustomSchema
from dbt.tests.adapter.simple_seed.test_seed import (
TestSeedCustomSchema as BaseSeedCustomSchema,
)
from dbt.tests.adapter.simple_seed.test_seed import TestSeedParsing as BaseSeedParsing
from dbt.tests.adapter.simple_seed.test_seed import (
TestSeedSpecificFormats as BaseSeedSpecificFormats,
Expand All @@ -23,7 +28,13 @@
seeds__disabled_in_config_csv,
seeds__enabled_in_config_csv,
)
from dbt.tests.util import get_connection, run_dbt
from dbt.tests.util import (
get_connection,
run_dbt,
check_relations_equal,
check_table_does_exist,
check_table_does_not_exist,
)

from dbt.adapters.sqlserver import SQLServerAdapter

Expand Down Expand Up @@ -145,6 +156,20 @@ class TestBasicSeedTestsSQLServer(BaseBasicSeedTests):
def setUp(self, project):
project.run_sql(fixed_setup_sql)

def test_simple_seed(self, project):
"""Build models and observe that run truncates a seed and re-inserts rows"""
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)

def test_simple_seed_full_refresh_flag(self, project):
"""Drop the seed_actual table and re-create.
Verifies correct behavior by the absence of the
model which depends on seed_actual."""
self._build_relations_for_test(project)
self._check_relation_end_state(
run_result=run_dbt(["seed", "--full-refresh"]), project=project, exists=True
)


class TestSeedConfigFullRefreshOnSQLServer(BaseSeedConfigFullRefreshOn):
@pytest.fixture(scope="class", autouse=True)
Expand Down Expand Up @@ -220,3 +245,50 @@ def test_custom_batch_size(self, project, logs_dir):
# 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


class SeedConfigBase:
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {
"quote_columns": False,
},
}


class SeedTestBase(SeedConfigBase):
@pytest.fixture(scope="class", autouse=True)
def setUp(self, project):
"""Create table for ensuring seeds and models used in tests build correctly"""
project.run_sql(seeds__expected_sql)

@pytest.fixture(scope="class")
def seeds(self, test_data_dir):
return {"seed_actual.csv": seed__actual_csv}

@pytest.fixture(scope="class")
def models(self):
return {
"models__downstream_from_seed_actual.sql": models__downstream_from_seed_actual,
}

def _build_relations_for_test(self, project):
"""The testing environment needs seeds and models to interact with"""
seed_result = run_dbt(["seed"])
assert len(seed_result) == 1
check_relations_equal(project.adapter, ["seed_expected", "seed_actual"])

run_result = run_dbt()
assert len(run_result) == 1
check_relations_equal(
project.adapter, ["models__downstream_from_seed_actual", "seed_expected"]
)

def _check_relation_end_state(self, run_result, project, exists: bool):
assert len(run_result) == 1
check_relations_equal(project.adapter, ["seed_actual", "seed_expected"])
if exists:
check_table_does_exist(project.adapter, "models__downstream_from_seed_actual")
else:
check_table_does_not_exist(project.adapter, "models__downstream_from_seed_actual")
5 changes: 4 additions & 1 deletion tests/functional/adapter/test_sources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest
from dbt.tests.adapter.basic.files import config_materialized_table, config_materialized_view
from dbt.tests.adapter.basic.files import (
config_materialized_table,
config_materialized_view,
)
from dbt.tests.util import run_dbt

source_regular = """
Expand Down
8 changes: 6 additions & 2 deletions tests/functional/adapter/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from dbt.tests.adapter.utils.fixture_cast_bool_to_text import models__test_cast_bool_to_text_yml
from dbt.tests.adapter.utils.fixture_cast_bool_to_text import (
models__test_cast_bool_to_text_yml,
)
from dbt.tests.adapter.utils.fixture_listagg import (
models__test_listagg_yml,
seeds__data_listagg_csv,
Expand All @@ -15,7 +17,9 @@
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_escape_single_quotes import BaseEscapeSingleQuotesQuote
from dbt.tests.adapter.utils.test_escape_single_quotes import (
BaseEscapeSingleQuotesQuote,
)
from dbt.tests.adapter.utils.test_except import BaseExcept
from dbt.tests.adapter.utils.test_hash import BaseHash
from dbt.tests.adapter.utils.test_intersect import BaseIntersect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def test_get_pyodbc_attrs_before_empty_dict_when_service_principal(


@pytest.mark.parametrize(
"key, value, expected", [("somekey", False, "somekey=No"), ("somekey", True, "somekey=Yes")]
"key, value, expected",
[("somekey", False, "somekey=No"), ("somekey", True, "somekey=Yes")],
)
def test_bool_to_connection_string_arg(key: str, value: bool, expected: str) -> None:
assert bool_to_connection_string_arg(key, value) == expected
Expand Down

0 comments on commit b36e242

Please sign in to comment.