|
41 | 41 | from google.cloud.devtools.cloudbuild_v1.services.cloud_build import CloudBuildClient
|
42 | 42 | from google.cloud.devtools.cloudbuild_v1.services.cloud_build import pagers
|
43 | 43 | from google.cloud.devtools.cloudbuild_v1.services.cloud_build import transports
|
44 |
| -from google.cloud.devtools.cloudbuild_v1.services.cloud_build.transports.base import ( |
45 |
| - _API_CORE_VERSION, |
46 |
| -) |
47 | 44 | from google.cloud.devtools.cloudbuild_v1.services.cloud_build.transports.base import (
|
48 | 45 | _GOOGLE_AUTH_VERSION,
|
49 | 46 | )
|
|
56 | 53 | import google.auth
|
57 | 54 |
|
58 | 55 |
|
59 |
| -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: |
60 |
| -# - Delete all the api-core and auth "less than" test cases |
| 56 | +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively |
| 57 | +# through google-api-core: |
| 58 | +# - Delete the auth "less than" test cases |
61 | 59 | # - Delete these pytest markers (Make the "greater than or equal to" tests the default).
|
62 | 60 | requires_google_auth_lt_1_25_0 = pytest.mark.skipif(
|
63 | 61 | packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"),
|
|
68 | 66 | reason="This test requires google-auth >= 1.25.0",
|
69 | 67 | )
|
70 | 68 |
|
71 |
| -requires_api_core_lt_1_26_0 = pytest.mark.skipif( |
72 |
| - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), |
73 |
| - reason="This test requires google-api-core < 1.26.0", |
74 |
| -) |
75 |
| - |
76 |
| -requires_api_core_gte_1_26_0 = pytest.mark.skipif( |
77 |
| - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), |
78 |
| - reason="This test requires google-api-core >= 1.26.0", |
79 |
| -) |
80 |
| - |
81 | 69 |
|
82 | 70 | def client_cert_source_callback():
|
83 | 71 | return b"cert bytes", b"key bytes"
|
@@ -135,6 +123,16 @@ def test_cloud_build_client_from_service_account_info(client_class):
|
135 | 123 | assert client.transport._host == "cloudbuild.googleapis.com:443"
|
136 | 124 |
|
137 | 125 |
|
| 126 | +@pytest.mark.parametrize("client_class", [CloudBuildClient, CloudBuildAsyncClient,]) |
| 127 | +def test_cloud_build_client_service_account_always_use_jwt(client_class): |
| 128 | + with mock.patch.object( |
| 129 | + service_account.Credentials, "with_always_use_jwt_access", create=True |
| 130 | + ) as use_jwt: |
| 131 | + creds = service_account.Credentials(None, None, None) |
| 132 | + client = client_class(credentials=creds) |
| 133 | + use_jwt.assert_called_with(True) |
| 134 | + |
| 135 | + |
138 | 136 | @pytest.mark.parametrize("client_class", [CloudBuildClient, CloudBuildAsyncClient,])
|
139 | 137 | def test_cloud_build_client_from_service_account_file(client_class):
|
140 | 138 | creds = ga_credentials.AnonymousCredentials()
|
@@ -3494,7 +3492,6 @@ def test_cloud_build_transport_auth_adc_old_google_auth(transport_class):
|
3494 | 3492 | (transports.CloudBuildGrpcAsyncIOTransport, grpc_helpers_async),
|
3495 | 3493 | ],
|
3496 | 3494 | )
|
3497 |
| -@requires_api_core_gte_1_26_0 |
3498 | 3495 | def test_cloud_build_transport_create_channel(transport_class, grpc_helpers):
|
3499 | 3496 | # If credentials and host are not provided, the transport class should use
|
3500 | 3497 | # ADC credentials.
|
@@ -3523,79 +3520,6 @@ def test_cloud_build_transport_create_channel(transport_class, grpc_helpers):
|
3523 | 3520 | )
|
3524 | 3521 |
|
3525 | 3522 |
|
3526 |
| -@pytest.mark.parametrize( |
3527 |
| - "transport_class,grpc_helpers", |
3528 |
| - [ |
3529 |
| - (transports.CloudBuildGrpcTransport, grpc_helpers), |
3530 |
| - (transports.CloudBuildGrpcAsyncIOTransport, grpc_helpers_async), |
3531 |
| - ], |
3532 |
| -) |
3533 |
| -@requires_api_core_lt_1_26_0 |
3534 |
| -def test_cloud_build_transport_create_channel_old_api_core( |
3535 |
| - transport_class, grpc_helpers |
3536 |
| -): |
3537 |
| - # If credentials and host are not provided, the transport class should use |
3538 |
| - # ADC credentials. |
3539 |
| - with mock.patch.object( |
3540 |
| - google.auth, "default", autospec=True |
3541 |
| - ) as adc, mock.patch.object( |
3542 |
| - grpc_helpers, "create_channel", autospec=True |
3543 |
| - ) as create_channel: |
3544 |
| - creds = ga_credentials.AnonymousCredentials() |
3545 |
| - adc.return_value = (creds, None) |
3546 |
| - transport_class(quota_project_id="octopus") |
3547 |
| - |
3548 |
| - create_channel.assert_called_with( |
3549 |
| - "cloudbuild.googleapis.com:443", |
3550 |
| - credentials=creds, |
3551 |
| - credentials_file=None, |
3552 |
| - quota_project_id="octopus", |
3553 |
| - scopes=("https://www.googleapis.com/auth/cloud-platform",), |
3554 |
| - ssl_credentials=None, |
3555 |
| - options=[ |
3556 |
| - ("grpc.max_send_message_length", -1), |
3557 |
| - ("grpc.max_receive_message_length", -1), |
3558 |
| - ], |
3559 |
| - ) |
3560 |
| - |
3561 |
| - |
3562 |
| -@pytest.mark.parametrize( |
3563 |
| - "transport_class,grpc_helpers", |
3564 |
| - [ |
3565 |
| - (transports.CloudBuildGrpcTransport, grpc_helpers), |
3566 |
| - (transports.CloudBuildGrpcAsyncIOTransport, grpc_helpers_async), |
3567 |
| - ], |
3568 |
| -) |
3569 |
| -@requires_api_core_lt_1_26_0 |
3570 |
| -def test_cloud_build_transport_create_channel_user_scopes( |
3571 |
| - transport_class, grpc_helpers |
3572 |
| -): |
3573 |
| - # If credentials and host are not provided, the transport class should use |
3574 |
| - # ADC credentials. |
3575 |
| - with mock.patch.object( |
3576 |
| - google.auth, "default", autospec=True |
3577 |
| - ) as adc, mock.patch.object( |
3578 |
| - grpc_helpers, "create_channel", autospec=True |
3579 |
| - ) as create_channel: |
3580 |
| - creds = ga_credentials.AnonymousCredentials() |
3581 |
| - adc.return_value = (creds, None) |
3582 |
| - |
3583 |
| - transport_class(quota_project_id="octopus", scopes=["1", "2"]) |
3584 |
| - |
3585 |
| - create_channel.assert_called_with( |
3586 |
| - "cloudbuild.googleapis.com:443", |
3587 |
| - credentials=creds, |
3588 |
| - credentials_file=None, |
3589 |
| - quota_project_id="octopus", |
3590 |
| - scopes=["1", "2"], |
3591 |
| - ssl_credentials=None, |
3592 |
| - options=[ |
3593 |
| - ("grpc.max_send_message_length", -1), |
3594 |
| - ("grpc.max_receive_message_length", -1), |
3595 |
| - ], |
3596 |
| - ) |
3597 |
| - |
3598 |
| - |
3599 | 3523 | @pytest.mark.parametrize(
|
3600 | 3524 | "transport_class",
|
3601 | 3525 | [transports.CloudBuildGrpcTransport, transports.CloudBuildGrpcAsyncIOTransport],
|
|
0 commit comments