|
32 | 32 | from google.api_core import grpc_helpers_async
|
33 | 33 | from google.api_core import operation_async # type: ignore
|
34 | 34 | from google.api_core import operations_v1
|
| 35 | +from google.api_core import path_template |
35 | 36 | from google.auth import credentials as ga_credentials
|
36 | 37 | from google.auth.exceptions import MutualTLSChannelError
|
37 | 38 | from google.cloud.managedidentities_v1.services.managed_identities_service import (
|
@@ -3047,6 +3048,9 @@ def test_managed_identities_service_base_transport():
|
3047 | 3048 | with pytest.raises(NotImplementedError):
|
3048 | 3049 | getattr(transport, method)(request=object())
|
3049 | 3050 |
|
| 3051 | + with pytest.raises(NotImplementedError): |
| 3052 | + transport.close() |
| 3053 | + |
3050 | 3054 | # Additionally, the LRO client (a property) should
|
3051 | 3055 | # also raise NotImplementedError
|
3052 | 3056 | with pytest.raises(NotImplementedError):
|
@@ -3564,3 +3568,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
|
3564 | 3568 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
|
3565 | 3569 | )
|
3566 | 3570 | prep.assert_called_once_with(client_info)
|
| 3571 | + |
| 3572 | + |
| 3573 | +@pytest.mark.asyncio |
| 3574 | +async def test_transport_close_async(): |
| 3575 | + client = ManagedIdentitiesServiceAsyncClient( |
| 3576 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 3577 | + ) |
| 3578 | + with mock.patch.object( |
| 3579 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 3580 | + ) as close: |
| 3581 | + async with client: |
| 3582 | + close.assert_not_called() |
| 3583 | + close.assert_called_once() |
| 3584 | + |
| 3585 | + |
| 3586 | +def test_transport_close(): |
| 3587 | + transports = { |
| 3588 | + "grpc": "_grpc_channel", |
| 3589 | + } |
| 3590 | + |
| 3591 | + for transport, close_name in transports.items(): |
| 3592 | + client = ManagedIdentitiesServiceClient( |
| 3593 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 3594 | + ) |
| 3595 | + with mock.patch.object( |
| 3596 | + type(getattr(client.transport, close_name)), "close" |
| 3597 | + ) as close: |
| 3598 | + with client: |
| 3599 | + close.assert_not_called() |
| 3600 | + close.assert_called_once() |
| 3601 | + |
| 3602 | + |
| 3603 | +def test_client_ctx(): |
| 3604 | + transports = [ |
| 3605 | + "grpc", |
| 3606 | + ] |
| 3607 | + for transport in transports: |
| 3608 | + client = ManagedIdentitiesServiceClient( |
| 3609 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 3610 | + ) |
| 3611 | + # Test client calls underlying transport. |
| 3612 | + with mock.patch.object(type(client.transport), "close") as close: |
| 3613 | + close.assert_not_called() |
| 3614 | + with client: |
| 3615 | + pass |
| 3616 | + close.assert_called() |
0 commit comments