Skip to content

Commit 1b2feb6

Browse files
vuanhphungIsaac
andcommitted
test: cover the Azure SP and circuit-breaker uses of the lazy names
The new tests reached OAuthManager and the plain telemetry push client, but not get_token_source's ClientCredentialsTokenSource or the circuit-breaker branch of TelemetryClient, so a mistyped lazy-name key there would only fail at runtime. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent cbdae71 commit 1b2feb6

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎tests/unit/test_lazy_http_import.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,51 @@ def test_patching_a_moved_name_reaches_where_it_is_used():
180180
http_client.assert_called_once_with(context)
181181

182182

183+
def test_patched_token_source_reaches_the_azure_sp_provider():
184+
from unittest.mock import MagicMock, patch
185+
186+
from databricks.sql.auth.authenticators import (
187+
AzureServicePrincipalCredentialProvider,
188+
)
189+
190+
provider = AzureServicePrincipalCredentialProvider(
191+
hostname="adb-1.azuredatabricks.net",
192+
azure_client_id="client",
193+
azure_client_secret="secret",
194+
http_client=MagicMock(),
195+
azure_tenant_id="tenant",
196+
)
197+
with patch(
198+
"databricks.sql.auth.authenticators.ClientCredentialsTokenSource"
199+
) as source:
200+
assert provider.get_token_source(resource="r") is source.return_value
201+
assert source.call_args.kwargs["extra_params"] == {"resource": "r"}
202+
203+
204+
def test_patched_push_clients_reach_the_circuit_breaker_branch():
205+
from unittest.mock import MagicMock, patch
206+
207+
from databricks.sql.telemetry.telemetry_client import TelemetryClient
208+
209+
module = "databricks.sql.telemetry.telemetry_client"
210+
context = MagicMock(telemetry_circuit_breaker_enabled=True)
211+
with patch(f"{module}.UnifiedHttpClient") as http_client, patch(
212+
f"{module}.TelemetryPushClient"
213+
) as push, patch(f"{module}.CircuitBreakerTelemetryPushClient") as breaker:
214+
client = TelemetryClient(
215+
telemetry_enabled=True,
216+
session_id_hex="01ef",
217+
auth_provider=None,
218+
host_url="example.cloud.databricks.com",
219+
executor=MagicMock(),
220+
batch_size=10,
221+
client_context=context,
222+
)
223+
push.assert_called_once_with(http_client.return_value)
224+
breaker.assert_called_once_with(push.return_value, "example.cloud.databricks.com")
225+
assert client._telemetry_push_client is breaker.return_value
226+
227+
183228
def test_token_federation_check_does_not_import_it():
184229
script = """
185230
import sys

0 commit comments

Comments
 (0)