Skip to content

Commit 1432aa8

Browse files
fix: Forward **kwargs to _build_pipeline in ServiceBusAdministrationClient (#44999)
- Pass **kwargs from __init__ to _build_pipeline() in both sync and async ServiceBusAdministrationClient so transport kwargs (connection_verify, transport, policies, ssl_context) reach the transport layer - Add unit tests verifying kwargs forwarding for both sync and async clients - Matches pattern from #26015 fix for ServiceBusClient and azure-core base
1 parent 48bbe28 commit 1432aa8

3 files changed

Lines changed: 104 additions & 2 deletions

File tree

sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(
130130
self._config = ServiceBusManagementClientConfiguration(
131131
self._endpoint, credential=self._credential, api_version=api_version, **kwargs
132132
)
133-
self._pipeline = self._build_pipeline()
133+
self._pipeline = self._build_pipeline(**kwargs)
134134
self._impl = ServiceBusManagementClientImpl(
135135
endpoint=fully_qualified_namespace,
136136
credential=self._credential,

sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(
130130
self._config = ServiceBusManagementClientConfiguration(
131131
self._endpoint, credential=self._credential, api_version=api_version, **kwargs
132132
)
133-
self._pipeline = self._build_pipeline()
133+
self._pipeline = self._build_pipeline(**kwargs)
134134
self._impl = ServiceBusManagementClientImpl(
135135
endpoint=fully_qualified_namespace,
136136
credential=self._credential,
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
"""Unit tests verifying that ServiceBusAdministrationClient forwards
7+
**kwargs from __init__ to _build_pipeline (both sync and async).
8+
9+
Regression test for https://github.com/Azure/azure-sdk-for-python/issues/44999
10+
"""
11+
12+
import pytest
13+
from unittest.mock import patch, MagicMock
14+
15+
from azure.servicebus.management import ServiceBusAdministrationClient
16+
17+
18+
class TestServiceBusAdministrationClientKwargs:
19+
"""Verify kwargs like connection_verify and transport reach _build_pipeline."""
20+
21+
def test_sync_build_pipeline_receives_kwargs(self):
22+
"""Sync client should forward **kwargs to _build_pipeline."""
23+
credential = MagicMock()
24+
with patch.object(
25+
ServiceBusAdministrationClient,
26+
"_build_pipeline",
27+
return_value=MagicMock(),
28+
) as mock_build:
29+
ServiceBusAdministrationClient(
30+
"fake.servicebus.windows.net",
31+
credential,
32+
connection_verify="/path/to/ca-bundle.crt",
33+
)
34+
mock_build.assert_called_once()
35+
call_kwargs = mock_build.call_args.kwargs
36+
assert call_kwargs.get("connection_verify") == "/path/to/ca-bundle.crt"
37+
38+
def test_sync_build_pipeline_receives_custom_transport(self):
39+
"""Sync client should forward a custom transport kwarg to _build_pipeline."""
40+
credential = MagicMock()
41+
custom_transport = MagicMock()
42+
with patch.object(
43+
ServiceBusAdministrationClient,
44+
"_build_pipeline",
45+
return_value=MagicMock(),
46+
) as mock_build:
47+
ServiceBusAdministrationClient(
48+
"fake.servicebus.windows.net",
49+
credential,
50+
transport=custom_transport,
51+
)
52+
mock_build.assert_called_once()
53+
call_kwargs = mock_build.call_args.kwargs
54+
assert call_kwargs.get("transport") is custom_transport
55+
56+
57+
@pytest.mark.asyncio
58+
class TestServiceBusAdministrationClientKwargsAsync:
59+
"""Verify kwargs reach _build_pipeline on the async client."""
60+
61+
async def test_async_build_pipeline_receives_kwargs(self):
62+
"""Async client should forward **kwargs to _build_pipeline."""
63+
from azure.servicebus.aio.management import (
64+
ServiceBusAdministrationClient as AsyncClient,
65+
)
66+
67+
credential = MagicMock()
68+
with patch.object(
69+
AsyncClient,
70+
"_build_pipeline",
71+
return_value=MagicMock(),
72+
) as mock_build:
73+
AsyncClient(
74+
"fake.servicebus.windows.net",
75+
credential,
76+
connection_verify="/path/to/ca-bundle.crt",
77+
)
78+
mock_build.assert_called_once()
79+
call_kwargs = mock_build.call_args.kwargs
80+
assert call_kwargs.get("connection_verify") == "/path/to/ca-bundle.crt"
81+
82+
async def test_async_build_pipeline_receives_custom_transport(self):
83+
"""Async client should forward a custom transport kwarg to _build_pipeline."""
84+
from azure.servicebus.aio.management import (
85+
ServiceBusAdministrationClient as AsyncClient,
86+
)
87+
88+
credential = MagicMock()
89+
custom_transport = MagicMock()
90+
with patch.object(
91+
AsyncClient,
92+
"_build_pipeline",
93+
return_value=MagicMock(),
94+
) as mock_build:
95+
AsyncClient(
96+
"fake.servicebus.windows.net",
97+
credential,
98+
transport=custom_transport,
99+
)
100+
mock_build.assert_called_once()
101+
call_kwargs = mock_build.call_args.kwargs
102+
assert call_kwargs.get("transport") is custom_transport

0 commit comments

Comments
 (0)