|
29 | 29 | from google.api_core import gapic_v1
|
30 | 30 | from google.api_core import grpc_helpers
|
31 | 31 | from google.api_core import grpc_helpers_async
|
| 32 | +from google.api_core import path_template |
32 | 33 | from google.auth import credentials as ga_credentials
|
33 | 34 | from google.auth.exceptions import MutualTLSChannelError
|
34 | 35 | from google.cloud.orgpolicy_v2.services.org_policy import OrgPolicyAsyncClient
|
@@ -2224,6 +2225,9 @@ def test_org_policy_base_transport():
|
2224 | 2225 | with pytest.raises(NotImplementedError):
|
2225 | 2226 | getattr(transport, method)(request=object())
|
2226 | 2227 |
|
| 2228 | + with pytest.raises(NotImplementedError): |
| 2229 | + transport.close() |
| 2230 | + |
2227 | 2231 |
|
2228 | 2232 | @requires_google_auth_gte_1_25_0
|
2229 | 2233 | def test_org_policy_base_transport_with_credentials_file():
|
@@ -2709,3 +2713,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
|
2709 | 2713 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
|
2710 | 2714 | )
|
2711 | 2715 | prep.assert_called_once_with(client_info)
|
| 2716 | + |
| 2717 | + |
| 2718 | +@pytest.mark.asyncio |
| 2719 | +async def test_transport_close_async(): |
| 2720 | + client = OrgPolicyAsyncClient( |
| 2721 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 2722 | + ) |
| 2723 | + with mock.patch.object( |
| 2724 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 2725 | + ) as close: |
| 2726 | + async with client: |
| 2727 | + close.assert_not_called() |
| 2728 | + close.assert_called_once() |
| 2729 | + |
| 2730 | + |
| 2731 | +def test_transport_close(): |
| 2732 | + transports = { |
| 2733 | + "grpc": "_grpc_channel", |
| 2734 | + } |
| 2735 | + |
| 2736 | + for transport, close_name in transports.items(): |
| 2737 | + client = OrgPolicyClient( |
| 2738 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 2739 | + ) |
| 2740 | + with mock.patch.object( |
| 2741 | + type(getattr(client.transport, close_name)), "close" |
| 2742 | + ) as close: |
| 2743 | + with client: |
| 2744 | + close.assert_not_called() |
| 2745 | + close.assert_called_once() |
| 2746 | + |
| 2747 | + |
| 2748 | +def test_client_ctx(): |
| 2749 | + transports = [ |
| 2750 | + "grpc", |
| 2751 | + ] |
| 2752 | + for transport in transports: |
| 2753 | + client = OrgPolicyClient( |
| 2754 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 2755 | + ) |
| 2756 | + # Test client calls underlying transport. |
| 2757 | + with mock.patch.object(type(client.transport), "close") as close: |
| 2758 | + close.assert_not_called() |
| 2759 | + with client: |
| 2760 | + pass |
| 2761 | + close.assert_called() |
0 commit comments