|
35 | 35 | from google.cloud.orgpolicy_v2.services.org_policy import OrgPolicyClient
|
36 | 36 | from google.cloud.orgpolicy_v2.services.org_policy import pagers
|
37 | 37 | from google.cloud.orgpolicy_v2.services.org_policy import transports
|
38 |
| -from google.cloud.orgpolicy_v2.services.org_policy.transports.base import ( |
39 |
| - _API_CORE_VERSION, |
40 |
| -) |
41 | 38 | from google.cloud.orgpolicy_v2.services.org_policy.transports.base import (
|
42 | 39 | _GOOGLE_AUTH_VERSION,
|
43 | 40 | )
|
|
49 | 46 | import google.auth
|
50 | 47 |
|
51 | 48 |
|
52 |
| -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: |
53 |
| -# - Delete all the api-core and auth "less than" test cases |
| 49 | +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively |
| 50 | +# through google-api-core: |
| 51 | +# - Delete the auth "less than" test cases |
54 | 52 | # - Delete these pytest markers (Make the "greater than or equal to" tests the default).
|
55 | 53 | requires_google_auth_lt_1_25_0 = pytest.mark.skipif(
|
56 | 54 | packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"),
|
|
61 | 59 | reason="This test requires google-auth >= 1.25.0",
|
62 | 60 | )
|
63 | 61 |
|
64 |
| -requires_api_core_lt_1_26_0 = pytest.mark.skipif( |
65 |
| - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), |
66 |
| - reason="This test requires google-api-core < 1.26.0", |
67 |
| -) |
68 |
| - |
69 |
| -requires_api_core_gte_1_26_0 = pytest.mark.skipif( |
70 |
| - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), |
71 |
| - reason="This test requires google-api-core >= 1.26.0", |
72 |
| -) |
73 |
| - |
74 | 62 |
|
75 | 63 | def client_cert_source_callback():
|
76 | 64 | return b"cert bytes", b"key bytes"
|
@@ -126,6 +114,16 @@ def test_org_policy_client_from_service_account_info(client_class):
|
126 | 114 | assert client.transport._host == "orgpolicy.googleapis.com:443"
|
127 | 115 |
|
128 | 116 |
|
| 117 | +@pytest.mark.parametrize("client_class", [OrgPolicyClient, OrgPolicyAsyncClient,]) |
| 118 | +def test_org_policy_client_service_account_always_use_jwt(client_class): |
| 119 | + with mock.patch.object( |
| 120 | + service_account.Credentials, "with_always_use_jwt_access", create=True |
| 121 | + ) as use_jwt: |
| 122 | + creds = service_account.Credentials(None, None, None) |
| 123 | + client = client_class(credentials=creds) |
| 124 | + use_jwt.assert_called_with(True) |
| 125 | + |
| 126 | + |
129 | 127 | @pytest.mark.parametrize("client_class", [OrgPolicyClient, OrgPolicyAsyncClient,])
|
130 | 128 | def test_org_policy_client_from_service_account_file(client_class):
|
131 | 129 | creds = ga_credentials.AnonymousCredentials()
|
@@ -2321,7 +2319,6 @@ def test_org_policy_transport_auth_adc_old_google_auth(transport_class):
|
2321 | 2319 | (transports.OrgPolicyGrpcAsyncIOTransport, grpc_helpers_async),
|
2322 | 2320 | ],
|
2323 | 2321 | )
|
2324 |
| -@requires_api_core_gte_1_26_0 |
2325 | 2322 | def test_org_policy_transport_create_channel(transport_class, grpc_helpers):
|
2326 | 2323 | # If credentials and host are not provided, the transport class should use
|
2327 | 2324 | # ADC credentials.
|
@@ -2350,77 +2347,6 @@ def test_org_policy_transport_create_channel(transport_class, grpc_helpers):
|
2350 | 2347 | )
|
2351 | 2348 |
|
2352 | 2349 |
|
2353 |
| -@pytest.mark.parametrize( |
2354 |
| - "transport_class,grpc_helpers", |
2355 |
| - [ |
2356 |
| - (transports.OrgPolicyGrpcTransport, grpc_helpers), |
2357 |
| - (transports.OrgPolicyGrpcAsyncIOTransport, grpc_helpers_async), |
2358 |
| - ], |
2359 |
| -) |
2360 |
| -@requires_api_core_lt_1_26_0 |
2361 |
| -def test_org_policy_transport_create_channel_old_api_core( |
2362 |
| - transport_class, grpc_helpers |
2363 |
| -): |
2364 |
| - # If credentials and host are not provided, the transport class should use |
2365 |
| - # ADC credentials. |
2366 |
| - with mock.patch.object( |
2367 |
| - google.auth, "default", autospec=True |
2368 |
| - ) as adc, mock.patch.object( |
2369 |
| - grpc_helpers, "create_channel", autospec=True |
2370 |
| - ) as create_channel: |
2371 |
| - creds = ga_credentials.AnonymousCredentials() |
2372 |
| - adc.return_value = (creds, None) |
2373 |
| - transport_class(quota_project_id="octopus") |
2374 |
| - |
2375 |
| - create_channel.assert_called_with( |
2376 |
| - "orgpolicy.googleapis.com:443", |
2377 |
| - credentials=creds, |
2378 |
| - credentials_file=None, |
2379 |
| - quota_project_id="octopus", |
2380 |
| - scopes=("https://www.googleapis.com/auth/cloud-platform",), |
2381 |
| - ssl_credentials=None, |
2382 |
| - options=[ |
2383 |
| - ("grpc.max_send_message_length", -1), |
2384 |
| - ("grpc.max_receive_message_length", -1), |
2385 |
| - ], |
2386 |
| - ) |
2387 |
| - |
2388 |
| - |
2389 |
| -@pytest.mark.parametrize( |
2390 |
| - "transport_class,grpc_helpers", |
2391 |
| - [ |
2392 |
| - (transports.OrgPolicyGrpcTransport, grpc_helpers), |
2393 |
| - (transports.OrgPolicyGrpcAsyncIOTransport, grpc_helpers_async), |
2394 |
| - ], |
2395 |
| -) |
2396 |
| -@requires_api_core_lt_1_26_0 |
2397 |
| -def test_org_policy_transport_create_channel_user_scopes(transport_class, grpc_helpers): |
2398 |
| - # If credentials and host are not provided, the transport class should use |
2399 |
| - # ADC credentials. |
2400 |
| - with mock.patch.object( |
2401 |
| - google.auth, "default", autospec=True |
2402 |
| - ) as adc, mock.patch.object( |
2403 |
| - grpc_helpers, "create_channel", autospec=True |
2404 |
| - ) as create_channel: |
2405 |
| - creds = ga_credentials.AnonymousCredentials() |
2406 |
| - adc.return_value = (creds, None) |
2407 |
| - |
2408 |
| - transport_class(quota_project_id="octopus", scopes=["1", "2"]) |
2409 |
| - |
2410 |
| - create_channel.assert_called_with( |
2411 |
| - "orgpolicy.googleapis.com:443", |
2412 |
| - credentials=creds, |
2413 |
| - credentials_file=None, |
2414 |
| - quota_project_id="octopus", |
2415 |
| - scopes=["1", "2"], |
2416 |
| - ssl_credentials=None, |
2417 |
| - options=[ |
2418 |
| - ("grpc.max_send_message_length", -1), |
2419 |
| - ("grpc.max_receive_message_length", -1), |
2420 |
| - ], |
2421 |
| - ) |
2422 |
| - |
2423 |
| - |
2424 | 2350 | @pytest.mark.parametrize(
|
2425 | 2351 | "transport_class",
|
2426 | 2352 | [transports.OrgPolicyGrpcTransport, transports.OrgPolicyGrpcAsyncIOTransport],
|
|
0 commit comments