|
35 | 35 | from google.cloud.dlp_v2.services.dlp_service import DlpServiceClient |
36 | 36 | from google.cloud.dlp_v2.services.dlp_service import pagers |
37 | 37 | from google.cloud.dlp_v2.services.dlp_service import transports |
38 | | -from google.cloud.dlp_v2.services.dlp_service.transports.base import _API_CORE_VERSION |
39 | 38 | from google.cloud.dlp_v2.services.dlp_service.transports.base import ( |
40 | 39 | _GOOGLE_AUTH_VERSION, |
41 | 40 | ) |
|
53 | 52 | import google.auth |
54 | 53 |
|
55 | 54 |
|
56 | | -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: |
57 | | -# - Delete all the api-core and auth "less than" test cases |
| 55 | +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively |
| 56 | +# through google-api-core: |
| 57 | +# - Delete the auth "less than" test cases |
58 | 58 | # - Delete these pytest markers (Make the "greater than or equal to" tests the default). |
59 | 59 | requires_google_auth_lt_1_25_0 = pytest.mark.skipif( |
60 | 60 | packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), |
|
65 | 65 | reason="This test requires google-auth >= 1.25.0", |
66 | 66 | ) |
67 | 67 |
|
68 | | -requires_api_core_lt_1_26_0 = pytest.mark.skipif( |
69 | | - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), |
70 | | - reason="This test requires google-api-core < 1.26.0", |
71 | | -) |
72 | | - |
73 | | -requires_api_core_gte_1_26_0 = pytest.mark.skipif( |
74 | | - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), |
75 | | - reason="This test requires google-api-core >= 1.26.0", |
76 | | -) |
77 | | - |
78 | 68 |
|
79 | 69 | def client_cert_source_callback(): |
80 | 70 | return b"cert bytes", b"key bytes" |
@@ -132,6 +122,16 @@ def test_dlp_service_client_from_service_account_info(client_class): |
132 | 122 | assert client.transport._host == "dlp.googleapis.com:443" |
133 | 123 |
|
134 | 124 |
|
| 125 | +@pytest.mark.parametrize("client_class", [DlpServiceClient, DlpServiceAsyncClient,]) |
| 126 | +def test_dlp_service_client_service_account_always_use_jwt(client_class): |
| 127 | + with mock.patch.object( |
| 128 | + service_account.Credentials, "with_always_use_jwt_access", create=True |
| 129 | + ) as use_jwt: |
| 130 | + creds = service_account.Credentials(None, None, None) |
| 131 | + client = client_class(credentials=creds) |
| 132 | + use_jwt.assert_called_with(True) |
| 133 | + |
| 134 | + |
135 | 135 | @pytest.mark.parametrize("client_class", [DlpServiceClient, DlpServiceAsyncClient,]) |
136 | 136 | def test_dlp_service_client_from_service_account_file(client_class): |
137 | 137 | creds = ga_credentials.AnonymousCredentials() |
@@ -8221,7 +8221,6 @@ def test_dlp_service_transport_auth_adc_old_google_auth(transport_class): |
8221 | 8221 | (transports.DlpServiceGrpcAsyncIOTransport, grpc_helpers_async), |
8222 | 8222 | ], |
8223 | 8223 | ) |
8224 | | -@requires_api_core_gte_1_26_0 |
8225 | 8224 | def test_dlp_service_transport_create_channel(transport_class, grpc_helpers): |
8226 | 8225 | # If credentials and host are not provided, the transport class should use |
8227 | 8226 | # ADC credentials. |
@@ -8250,79 +8249,6 @@ def test_dlp_service_transport_create_channel(transport_class, grpc_helpers): |
8250 | 8249 | ) |
8251 | 8250 |
|
8252 | 8251 |
|
8253 | | -@pytest.mark.parametrize( |
8254 | | - "transport_class,grpc_helpers", |
8255 | | - [ |
8256 | | - (transports.DlpServiceGrpcTransport, grpc_helpers), |
8257 | | - (transports.DlpServiceGrpcAsyncIOTransport, grpc_helpers_async), |
8258 | | - ], |
8259 | | -) |
8260 | | -@requires_api_core_lt_1_26_0 |
8261 | | -def test_dlp_service_transport_create_channel_old_api_core( |
8262 | | - transport_class, grpc_helpers |
8263 | | -): |
8264 | | - # If credentials and host are not provided, the transport class should use |
8265 | | - # ADC credentials. |
8266 | | - with mock.patch.object( |
8267 | | - google.auth, "default", autospec=True |
8268 | | - ) as adc, mock.patch.object( |
8269 | | - grpc_helpers, "create_channel", autospec=True |
8270 | | - ) as create_channel: |
8271 | | - creds = ga_credentials.AnonymousCredentials() |
8272 | | - adc.return_value = (creds, None) |
8273 | | - transport_class(quota_project_id="octopus") |
8274 | | - |
8275 | | - create_channel.assert_called_with( |
8276 | | - "dlp.googleapis.com:443", |
8277 | | - credentials=creds, |
8278 | | - credentials_file=None, |
8279 | | - quota_project_id="octopus", |
8280 | | - scopes=("https://www.googleapis.com/auth/cloud-platform",), |
8281 | | - ssl_credentials=None, |
8282 | | - options=[ |
8283 | | - ("grpc.max_send_message_length", -1), |
8284 | | - ("grpc.max_receive_message_length", -1), |
8285 | | - ], |
8286 | | - ) |
8287 | | - |
8288 | | - |
8289 | | -@pytest.mark.parametrize( |
8290 | | - "transport_class,grpc_helpers", |
8291 | | - [ |
8292 | | - (transports.DlpServiceGrpcTransport, grpc_helpers), |
8293 | | - (transports.DlpServiceGrpcAsyncIOTransport, grpc_helpers_async), |
8294 | | - ], |
8295 | | -) |
8296 | | -@requires_api_core_lt_1_26_0 |
8297 | | -def test_dlp_service_transport_create_channel_user_scopes( |
8298 | | - transport_class, grpc_helpers |
8299 | | -): |
8300 | | - # If credentials and host are not provided, the transport class should use |
8301 | | - # ADC credentials. |
8302 | | - with mock.patch.object( |
8303 | | - google.auth, "default", autospec=True |
8304 | | - ) as adc, mock.patch.object( |
8305 | | - grpc_helpers, "create_channel", autospec=True |
8306 | | - ) as create_channel: |
8307 | | - creds = ga_credentials.AnonymousCredentials() |
8308 | | - adc.return_value = (creds, None) |
8309 | | - |
8310 | | - transport_class(quota_project_id="octopus", scopes=["1", "2"]) |
8311 | | - |
8312 | | - create_channel.assert_called_with( |
8313 | | - "dlp.googleapis.com:443", |
8314 | | - credentials=creds, |
8315 | | - credentials_file=None, |
8316 | | - quota_project_id="octopus", |
8317 | | - scopes=["1", "2"], |
8318 | | - ssl_credentials=None, |
8319 | | - options=[ |
8320 | | - ("grpc.max_send_message_length", -1), |
8321 | | - ("grpc.max_receive_message_length", -1), |
8322 | | - ], |
8323 | | - ) |
8324 | | - |
8325 | | - |
8326 | 8252 | @pytest.mark.parametrize( |
8327 | 8253 | "transport_class", |
8328 | 8254 | [transports.DlpServiceGrpcTransport, transports.DlpServiceGrpcAsyncIOTransport], |
|
0 commit comments