Skip to content

Commit 0ecaf3a

Browse files
Fix test + exceptions
1 parent a282354 commit 0ecaf3a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

databricks/sdk/oidc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,19 @@ def id_token(self) -> IdToken:
110110
"""
111111
if not self.path:
112112
raise ValueError("Missing path")
113+
114+
token = None
113115
try:
114116
with open(self.path, "r") as f:
115117
token = f.read().strip()
116-
if not token:
117-
raise ValueError(f"File {self.path!r} is empty")
118-
return IdToken(jwt=token)
119118
except FileNotFoundError:
120119
raise ValueError(f"File {self.path!r} does not exist")
121120
except Exception as e:
122121
raise ValueError(f"Error reading token file: {str(e)}")
122+
123+
if not token:
124+
raise ValueError(f"File {self.path!r} is empty")
125+
return IdToken(jwt=token)
123126

124127

125128
class GitHubIdTokenSource(IdTokenSource):

tests/test_credentials_provider.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_external_browser_refresh_success(mocker):
2626

2727
# Inject the mock implementations.
2828
mocker.patch(
29-
"databricks.sdk.credentials_provider.TokenCache",
29+
"databricks.sdk.oauth.TokenCache",
3030
return_value=mock_token_cache,
3131
)
3232

@@ -66,11 +66,11 @@ def test_external_browser_refresh_failure_new_oauth_flow(mocker):
6666

6767
# Inject the mock implementations.
6868
mocker.patch(
69-
"databricks.sdk.credentials_provider.TokenCache",
69+
"databricks.sdk.oauth.TokenCache",
7070
return_value=mock_token_cache,
7171
)
7272
mocker.patch(
73-
"databricks.sdk.credentials_provider.OAuthClient",
73+
"databricks.sdk.oauth.OAuthClient",
7474
return_value=mock_oauth_client,
7575
)
7676

@@ -112,11 +112,11 @@ def test_external_browser_no_cached_credentials(mocker):
112112

113113
# Inject the mock implementations.
114114
mocker.patch(
115-
"databricks.sdk.credentials_provider.TokenCache",
115+
"databricks.sdk.oauth.TokenCache",
116116
return_value=mock_token_cache,
117117
)
118118
mocker.patch(
119-
"databricks.sdk.credentials_provider.OAuthClient",
119+
"databricks.sdk.oauth.OAuthClient",
120120
return_value=mock_oauth_client,
121121
)
122122

@@ -150,11 +150,11 @@ def test_external_browser_consent_fails(mocker):
150150

151151
# Inject the mock implementations.
152152
mocker.patch(
153-
"databricks.sdk.credentials_provider.TokenCache",
153+
"databricks.sdk.oauth.TokenCache",
154154
return_value=mock_token_cache,
155155
)
156156
mocker.patch(
157-
"databricks.sdk.credentials_provider.OAuthClient",
157+
"databricks.sdk.oauth.OAuthClient",
158158
return_value=mock_oauth_client,
159159
)
160160

0 commit comments

Comments
 (0)