Skip to content

Commit 3fa067a

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 3fa067a

3 files changed

Lines changed: 105 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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
from unittest.mock import patch, MagicMock
13+
14+
import pytest
15+
16+
from azure.servicebus.management import ServiceBusAdministrationClient
17+
18+
19+
class TestServiceBusAdministrationClientKwargs:
20+
"""Verify kwargs like connection_verify and transport reach _build_pipeline."""
21+
22+
def test_sync_build_pipeline_receives_kwargs(self):
23+
"""Sync client should forward **kwargs to _build_pipeline."""
24+
credential = MagicMock()
25+
with patch.object(
26+
ServiceBusAdministrationClient,
27+
"_build_pipeline",
28+
return_value=MagicMock(),
29+
) as mock_build:
30+
ServiceBusAdministrationClient(
31+
"fake.servicebus.windows.net",
32+
credential,
33+
connection_verify="/path/to/ca-bundle.crt",
34+
)
35+
mock_build.assert_called_once()
36+
call_kwargs = mock_build.call_args.kwargs
37+
assert call_kwargs.get("connection_verify") == "/path/to/ca-bundle.crt"
38+
39+
def test_sync_build_pipeline_receives_custom_transport(self):
40+
"""Sync client should forward a custom transport kwarg to _build_pipeline."""
41+
credential = MagicMock()
42+
custom_transport = MagicMock()
43+
with patch.object(
44+
ServiceBusAdministrationClient,
45+
"_build_pipeline",
46+
return_value=MagicMock(),
47+
) as mock_build:
48+
ServiceBusAdministrationClient(
49+
"fake.servicebus.windows.net",
50+
credential,
51+
transport=custom_transport,
52+
)
53+
mock_build.assert_called_once()
54+
call_kwargs = mock_build.call_args.kwargs
55+
assert call_kwargs.get("transport") is custom_transport
56+
57+
58+
@pytest.mark.asyncio
59+
class TestServiceBusAdministrationClientKwargsAsync:
60+
"""Verify kwargs reach _build_pipeline on the async client."""
61+
62+
async def test_async_build_pipeline_receives_kwargs(self):
63+
"""Async client should forward **kwargs to _build_pipeline."""
64+
from azure.servicebus.aio.management import (
65+
ServiceBusAdministrationClient as AsyncClient,
66+
)
67+
68+
credential = MagicMock()
69+
with patch.object(
70+
AsyncClient,
71+
"_build_pipeline",
72+
return_value=MagicMock(),
73+
) as mock_build:
74+
AsyncClient(
75+
"fake.servicebus.windows.net",
76+
credential,
77+
connection_verify="/path/to/ca-bundle.crt",
78+
)
79+
mock_build.assert_called_once()
80+
call_kwargs = mock_build.call_args.kwargs
81+
assert call_kwargs.get("connection_verify") == "/path/to/ca-bundle.crt"
82+
83+
async def test_async_build_pipeline_receives_custom_transport(self):
84+
"""Async client should forward a custom transport kwarg to _build_pipeline."""
85+
from azure.servicebus.aio.management import (
86+
ServiceBusAdministrationClient as AsyncClient,
87+
)
88+
89+
credential = MagicMock()
90+
custom_transport = MagicMock()
91+
with patch.object(
92+
AsyncClient,
93+
"_build_pipeline",
94+
return_value=MagicMock(),
95+
) as mock_build:
96+
AsyncClient(
97+
"fake.servicebus.windows.net",
98+
credential,
99+
transport=custom_transport,
100+
)
101+
mock_build.assert_called_once()
102+
call_kwargs = mock_build.call_args.kwargs
103+
assert call_kwargs.get("transport") is custom_transport

0 commit comments

Comments
 (0)