Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/test_init_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import hashlib
import pathlib

# databricks/__init__.py lives one directory above this test, regardless
# of where pytest was invoked from.
_INIT_FILE = pathlib.Path(__file__).parent.parent / "databricks" / "__init__.py"


def test_init_file_contents():
Expand All @@ -7,7 +12,7 @@ def test_init_file_contents():

Also see https://github.com/databricks/databricks-sdk-py/issues/343#issuecomment-1866029118.
"""
with open("databricks/__init__.py") as f:
with open(_INIT_FILE) as f:
init_file_contents = f.read()

# This hash is the expected hash of the contents of `src/databricks/__init__.py`.
Expand Down
23 changes: 15 additions & 8 deletions tests/test_model_serving_auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pathlib
import threading
import time

Expand All @@ -8,6 +9,12 @@

from .conftest import raises

# Test fixture files live next to this test, regardless of where pytest
# was invoked from.
_TESTDATA = pathlib.Path(__file__).parent / "testdata"
_MODEL_SERVING_TEST_TOKEN = str(_TESTDATA / "model-serving-test-token")
_MODEL_SERVING_TEST_TOKEN_V2 = str(_TESTDATA / "model-serving-test-token-v2")

default_auth_base_error_message = (
"default auth: cannot configure default credentials, "
"please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication "
Expand All @@ -24,31 +31,31 @@
("DB_MODEL_SERVING_HOST_URL", "x"),
],
["DATABRICKS_MODEL_SERVING_HOST_URL"],
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
),
(
[
("IS_IN_DATABRICKS_MODEL_SERVING_ENV", "true"),
("DB_MODEL_SERVING_HOST_URL", "x"),
],
["DATABRICKS_MODEL_SERVING_HOST_URL"],
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
),
(
[
("IS_IN_DB_MODEL_SERVING_ENV", "true"),
("DATABRICKS_MODEL_SERVING_HOST_URL", "x"),
],
["DB_MODEL_SERVING_HOST_URL"],
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
),
(
[
("IS_IN_DATABRICKS_MODEL_SERVING_ENV", "true"),
("DATABRICKS_MODEL_SERVING_HOST_URL", "x"),
],
["DB_MODEL_SERVING_HOST_URL"],
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
),
],
)
Expand Down Expand Up @@ -92,7 +99,7 @@ def test_model_serving_auth(env_values, del_env_values, oauth_file_name, monkeyp
), # In Model Serving and Invalid File Name
(
[],
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
), # Not in Model Serving and Valid File Name
],
)
Expand Down Expand Up @@ -122,7 +129,7 @@ def test_model_serving_auth_refresh(monkeypatch, mocker):
# patch mlflow to read the file from the test directory
monkeypatch.setattr(
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
)
mocker.patch("databricks.sdk.config.Config._known_file_config_loader")

Expand All @@ -136,7 +143,7 @@ def test_model_serving_auth_refresh(monkeypatch, mocker):
# Simulate refreshing the token by patching to to a new file
monkeypatch.setattr(
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
"tests/testdata/model-serving-test-token-v2",
_MODEL_SERVING_TEST_TOKEN_V2,
)

monkeypatch.setattr(
Expand Down Expand Up @@ -172,7 +179,7 @@ def test_agent_user_credentials(monkeypatch, mocker):
monkeypatch.setenv("DB_MODEL_SERVING_HOST_URL", "x")
monkeypatch.setattr(
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
"tests/testdata/model-serving-test-token",
_MODEL_SERVING_TEST_TOKEN,
)

invokers_token_val = "databricks_invokers_token"
Expand Down
Loading