Skip to content

Commit

Permalink
passing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db committed Feb 14, 2025
1 parent 5086064 commit 722c758
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
14 changes: 6 additions & 8 deletions dbt/adapters/databricks/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@
)
from dbt.adapters.databricks.__version__ import version as __version__
from dbt.adapters.databricks.api_client import DatabricksApiClient
from dbt.adapters.databricks.connections import (
ConnectionCreate,
ConnectionCreateError,
ConnectionIdleCheck,
ConnectionIdleClose,
ConnectionRetrieve,
ConnectionReuse,
)
from dbt.adapters.databricks.credentials import (
DatabricksCredentialManager,
DatabricksCredentials,
)
from dbt.adapters.databricks.events.connection_events import (
ConnectionAcquire,
ConnectionCreate,
ConnectionCreateError,
ConnectionIdleCheck,
ConnectionIdleClose,
ConnectionRelease,
ConnectionReset,
ConnectionRetrieve,
ConnectionReuse,
)
from dbt.adapters.databricks.events.other_events import QueryError
from dbt.adapters.databricks.handle import CursorWrapper, DatabricksHandle, SqlUtils
Expand Down
6 changes: 3 additions & 3 deletions dbt/adapters/databricks/handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dbt.adapters.contracts.connection import AdapterResponse
from dbt.adapters.databricks import utils
from dbt.adapters.databricks.__version__ import version as __version__
from dbt.adapters.databricks.credentials import DatabricksCredentials, TCredentialProvider
from dbt.adapters.databricks.credentials import DatabricksCredentialManager, DatabricksCredentials
from dbt.adapters.databricks.logging import logger

if TYPE_CHECKING:
Expand Down Expand Up @@ -297,7 +297,7 @@ def clean_sql(sql: str) -> str:

@staticmethod
def prepare_connection_arguments(
creds: DatabricksCredentials, creds_provider: TCredentialProvider, http_path: str
creds: DatabricksCredentials, creds_manager: DatabricksCredentialManager, http_path: str
) -> dict[str, Any]:
invocation_env = creds.get_invocation_env()
user_agent_entry = SqlUtils.user_agent
Expand All @@ -313,7 +313,7 @@ def prepare_connection_arguments(
return {
"server_hostname": creds.host,
"http_path": http_path,
"credentials_provider": creds_provider,
"credentials_provider": creds_manager.credentials_provider,
"http_headers": http_headers if http_headers else None,
"session_configuration": creds.session_properties,
"catalog": creds.database,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)


class TestConstraint(TypedConstraint):
class FakeConstraint(TypedConstraint):
str_type = "unique"

def _render_suffix(self):
Expand All @@ -34,10 +34,10 @@ def _render_suffix(self):
class TestTypedConstraint:
def test_typed_constraint_from_dict__invalid_type(self):
with pytest.raises(AssertionError, match="Mismatched constraint type"):
TestConstraint.from_dict({"type": "custom"})
FakeConstraint.from_dict({"type": "custom"})

def test_render__with_name(self):
constraint = TestConstraint(type=ConstraintType.check, name="my_constraint")
constraint = FakeConstraint(type=ConstraintType.check, name="my_constraint")
assert constraint.render() == "CONSTRAINT my_constraint test"


Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_query_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from unittest.mock import Mock

import pytest
from dbt_common.exceptions import DbtRuntimeError

from dbt.adapters.databricks import connections
from dbt.adapters.databricks.connections import QueryConfigUtils, QueryContextWrapper
from dbt.adapters.databricks.credentials import DatabricksCredentials


class TestQueryConfigUtils:
Expand All @@ -22,7 +23,7 @@ def path(self):

@pytest.fixture
def creds(self, path):
return DatabricksCredentials(http_path=path)
return Mock(http_path=path, compute={}, connect_max_idle=None)

def test_get_http_path__empty(self, path, creds):
assert QueryConfigUtils.get_http_path(QueryContextWrapper(), creds) == path
Expand Down

0 comments on commit 722c758

Please sign in to comment.