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