Skip to content

Commit 73abe3b

Browse files
committed
tests: fix unit test failure when auto_populated_fields is set
1 parent 76c0db3 commit 73abe3b

4 files changed

Lines changed: 109 additions & 0 deletions

File tree

packages/gapic-generator/tests/integration/goldens/storagebatchoperations/google/cloud/storagebatchoperations_v1/services/storage_batch_operations/async_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from collections import OrderedDict
1818
import re
1919
from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union
20+
import uuid
2021

2122
from google.cloud.storagebatchoperations_v1 import gapic_version as package_version
2223

@@ -620,6 +621,9 @@ async def sample_create_job():
620621
)),
621622
)
622623

624+
if not request.request_id:
625+
request.request_id = str(uuid.uuid4())
626+
623627
# Validate the universe domain.
624628
self._client._validate_universe_domain()
625629

@@ -724,6 +728,9 @@ async def sample_delete_job():
724728
)),
725729
)
726730

731+
if not request.request_id:
732+
request.request_id = str(uuid.uuid4())
733+
727734
# Validate the universe domain.
728735
self._client._validate_universe_domain()
729736

@@ -824,6 +831,9 @@ async def sample_cancel_job():
824831
)),
825832
)
826833

834+
if not request.request_id:
835+
request.request_id = str(uuid.uuid4())
836+
827837
# Validate the universe domain.
828838
self._client._validate_universe_domain()
829839

packages/gapic-generator/tests/integration/goldens/storagebatchoperations/google/cloud/storagebatchoperations_v1/services/storage_batch_operations/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121
import re
2222
from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast
23+
import uuid
2324
import warnings
2425

2526
from google.cloud.storagebatchoperations_v1 import gapic_version as package_version
@@ -1004,6 +1005,9 @@ def sample_create_job():
10041005
)),
10051006
)
10061007

1008+
if not request.request_id:
1009+
request.request_id = str(uuid.uuid4())
1010+
10071011
# Validate the universe domain.
10081012
self._validate_universe_domain()
10091013

@@ -1107,6 +1111,9 @@ def sample_delete_job():
11071111
)),
11081112
)
11091113

1114+
if not request.request_id:
1115+
request.request_id = str(uuid.uuid4())
1116+
11101117
# Validate the universe domain.
11111118
self._validate_universe_domain()
11121119

@@ -1206,6 +1213,9 @@ def sample_cancel_job():
12061213
)),
12071214
)
12081215

1216+
if not request.request_id:
1217+
request.request_id = str(uuid.uuid4())
1218+
12091219
# Validate the universe domain.
12101220
self._validate_universe_domain()
12111221

packages/gapic-generator/tests/integration/goldens/storagebatchoperations/tests/unit/gapic/storagebatchoperations_v1/test_storage_batch_operations.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515
#
1616
import os
17+
import re
1718
from unittest import mock
1819
from unittest.mock import AsyncMock
1920

@@ -1813,6 +1814,10 @@ def test_create_job(request_type, transport: str = 'grpc'):
18131814
# Everything is optional in proto3 as far as the runtime is concerned,
18141815
# and we are mocking out the actual API, so just send an empty request.
18151816
request = request_type()
1817+
if isinstance(request, dict):
1818+
request['request_id'] = "explicit value for autopopulate-able field"
1819+
else:
1820+
request.request_id = "explicit value for autopopulate-able field"
18161821

18171822
# Mock the actual call within the gRPC stub, and fake the request.
18181823
with mock.patch.object(
@@ -1826,6 +1831,7 @@ def test_create_job(request_type, transport: str = 'grpc'):
18261831
assert len(call.mock_calls) == 1
18271832
_, args, _ = call.mock_calls[0]
18281833
request = storage_batch_operations.CreateJobRequest()
1834+
request.request_id = "explicit value for autopopulate-able field"
18291835
assert args[0] == request
18301836

18311837
# Establish that the response is the type that we expect.
@@ -1856,6 +1862,10 @@ def test_create_job_non_empty_request_with_auto_populated_field():
18561862
client.create_job(request=request)
18571863
call.assert_called()
18581864
_, args, _ = call.mock_calls[0]
1865+
# Ensure that the uuid4 field is set according to AIP 4235
1866+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
1867+
# clear UUID field so that the check below succeeds
1868+
args[0].request_id = None
18591869
assert args[0] == storage_batch_operations.CreateJobRequest(
18601870
parent='parent_value',
18611871
job_id='job_id_value',
@@ -1947,6 +1957,10 @@ async def test_create_job_async(transport: str = 'grpc_asyncio', request_type=st
19471957
# Everything is optional in proto3 as far as the runtime is concerned,
19481958
# and we are mocking out the actual API, so just send an empty request.
19491959
request = request_type()
1960+
if isinstance(request, dict):
1961+
request['request_id'] = "explicit value for autopopulate-able field"
1962+
else:
1963+
request.request_id = "explicit value for autopopulate-able field"
19501964

19511965
# Mock the actual call within the gRPC stub, and fake the request.
19521966
with mock.patch.object(
@@ -1962,6 +1976,7 @@ async def test_create_job_async(transport: str = 'grpc_asyncio', request_type=st
19621976
assert len(call.mock_calls)
19631977
_, args, _ = call.mock_calls[0]
19641978
request = storage_batch_operations.CreateJobRequest()
1979+
request.request_id = "explicit value for autopopulate-able field"
19651980
assert args[0] == request
19661981

19671982
# Establish that the response is the type that we expect.
@@ -2152,6 +2167,10 @@ def test_delete_job(request_type, transport: str = 'grpc'):
21522167
# Everything is optional in proto3 as far as the runtime is concerned,
21532168
# and we are mocking out the actual API, so just send an empty request.
21542169
request = request_type()
2170+
if isinstance(request, dict):
2171+
request['request_id'] = "explicit value for autopopulate-able field"
2172+
else:
2173+
request.request_id = "explicit value for autopopulate-able field"
21552174

21562175
# Mock the actual call within the gRPC stub, and fake the request.
21572176
with mock.patch.object(
@@ -2165,6 +2184,7 @@ def test_delete_job(request_type, transport: str = 'grpc'):
21652184
assert len(call.mock_calls) == 1
21662185
_, args, _ = call.mock_calls[0]
21672186
request = storage_batch_operations.DeleteJobRequest()
2187+
request.request_id = "explicit value for autopopulate-able field"
21682188
assert args[0] == request
21692189

21702190
# Establish that the response is the type that we expect.
@@ -2194,6 +2214,10 @@ def test_delete_job_non_empty_request_with_auto_populated_field():
21942214
client.delete_job(request=request)
21952215
call.assert_called()
21962216
_, args, _ = call.mock_calls[0]
2217+
# Ensure that the uuid4 field is set according to AIP 4235
2218+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
2219+
# clear UUID field so that the check below succeeds
2220+
args[0].request_id = None
21972221
assert args[0] == storage_batch_operations.DeleteJobRequest(
21982222
name='name_value',
21992223
)
@@ -2274,6 +2298,10 @@ async def test_delete_job_async(transport: str = 'grpc_asyncio', request_type=st
22742298
# Everything is optional in proto3 as far as the runtime is concerned,
22752299
# and we are mocking out the actual API, so just send an empty request.
22762300
request = request_type()
2301+
if isinstance(request, dict):
2302+
request['request_id'] = "explicit value for autopopulate-able field"
2303+
else:
2304+
request.request_id = "explicit value for autopopulate-able field"
22772305

22782306
# Mock the actual call within the gRPC stub, and fake the request.
22792307
with mock.patch.object(
@@ -2287,6 +2315,7 @@ async def test_delete_job_async(transport: str = 'grpc_asyncio', request_type=st
22872315
assert len(call.mock_calls)
22882316
_, args, _ = call.mock_calls[0]
22892317
request = storage_batch_operations.DeleteJobRequest()
2318+
request.request_id = "explicit value for autopopulate-able field"
22902319
assert args[0] == request
22912320

22922321
# Establish that the response is the type that we expect.
@@ -2455,6 +2484,10 @@ def test_cancel_job(request_type, transport: str = 'grpc'):
24552484
# Everything is optional in proto3 as far as the runtime is concerned,
24562485
# and we are mocking out the actual API, so just send an empty request.
24572486
request = request_type()
2487+
if isinstance(request, dict):
2488+
request['request_id'] = "explicit value for autopopulate-able field"
2489+
else:
2490+
request.request_id = "explicit value for autopopulate-able field"
24582491

24592492
# Mock the actual call within the gRPC stub, and fake the request.
24602493
with mock.patch.object(
@@ -2469,6 +2502,7 @@ def test_cancel_job(request_type, transport: str = 'grpc'):
24692502
assert len(call.mock_calls) == 1
24702503
_, args, _ = call.mock_calls[0]
24712504
request = storage_batch_operations.CancelJobRequest()
2505+
request.request_id = "explicit value for autopopulate-able field"
24722506
assert args[0] == request
24732507

24742508
# Establish that the response is the type that we expect.
@@ -2498,6 +2532,10 @@ def test_cancel_job_non_empty_request_with_auto_populated_field():
24982532
client.cancel_job(request=request)
24992533
call.assert_called()
25002534
_, args, _ = call.mock_calls[0]
2535+
# Ensure that the uuid4 field is set according to AIP 4235
2536+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
2537+
# clear UUID field so that the check below succeeds
2538+
args[0].request_id = None
25012539
assert args[0] == storage_batch_operations.CancelJobRequest(
25022540
name='name_value',
25032541
)
@@ -2578,6 +2616,10 @@ async def test_cancel_job_async(transport: str = 'grpc_asyncio', request_type=st
25782616
# Everything is optional in proto3 as far as the runtime is concerned,
25792617
# and we are mocking out the actual API, so just send an empty request.
25802618
request = request_type()
2619+
if isinstance(request, dict):
2620+
request['request_id'] = "explicit value for autopopulate-able field"
2621+
else:
2622+
request.request_id = "explicit value for autopopulate-able field"
25812623

25822624
# Mock the actual call within the gRPC stub, and fake the request.
25832625
with mock.patch.object(
@@ -2592,6 +2634,7 @@ async def test_cancel_job_async(transport: str = 'grpc_asyncio', request_type=st
25922634
assert len(call.mock_calls)
25932635
_, args, _ = call.mock_calls[0]
25942636
request = storage_batch_operations.CancelJobRequest()
2637+
request.request_id = "explicit value for autopopulate-able field"
25952638
assert args[0] == request
25962639

25972640
# Establish that the response is the type that we expect.
@@ -5048,6 +5091,10 @@ def test_create_job_empty_call_grpc():
50485091
# Establish that the underlying stub method was called.
50495092
call.assert_called()
50505093
_, args, _ = call.mock_calls[0]
5094+
# Ensure that the uuid4 field is set according to AIP 4235
5095+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5096+
# clear UUID field so that the check below succeeds
5097+
args[0].request_id = None
50515098
request_msg = storage_batch_operations.CreateJobRequest()
50525099

50535100
assert args[0] == request_msg
@@ -5071,6 +5118,10 @@ def test_delete_job_empty_call_grpc():
50715118
# Establish that the underlying stub method was called.
50725119
call.assert_called()
50735120
_, args, _ = call.mock_calls[0]
5121+
# Ensure that the uuid4 field is set according to AIP 4235
5122+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5123+
# clear UUID field so that the check below succeeds
5124+
args[0].request_id = None
50745125
request_msg = storage_batch_operations.DeleteJobRequest()
50755126

50765127
assert args[0] == request_msg
@@ -5094,6 +5145,10 @@ def test_cancel_job_empty_call_grpc():
50945145
# Establish that the underlying stub method was called.
50955146
call.assert_called()
50965147
_, args, _ = call.mock_calls[0]
5148+
# Ensure that the uuid4 field is set according to AIP 4235
5149+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5150+
# clear UUID field so that the check below succeeds
5151+
args[0].request_id = None
50975152
request_msg = storage_batch_operations.CancelJobRequest()
50985153

50995154
assert args[0] == request_msg
@@ -5241,6 +5296,10 @@ async def test_create_job_empty_call_grpc_asyncio():
52415296
# Establish that the underlying stub method was called.
52425297
call.assert_called()
52435298
_, args, _ = call.mock_calls[0]
5299+
# Ensure that the uuid4 field is set according to AIP 4235
5300+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5301+
# clear UUID field so that the check below succeeds
5302+
args[0].request_id = None
52445303
request_msg = storage_batch_operations.CreateJobRequest()
52455304

52465305
assert args[0] == request_msg
@@ -5266,6 +5325,10 @@ async def test_delete_job_empty_call_grpc_asyncio():
52665325
# Establish that the underlying stub method was called.
52675326
call.assert_called()
52685327
_, args, _ = call.mock_calls[0]
5328+
# Ensure that the uuid4 field is set according to AIP 4235
5329+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5330+
# clear UUID field so that the check below succeeds
5331+
args[0].request_id = None
52695332
request_msg = storage_batch_operations.DeleteJobRequest()
52705333

52715334
assert args[0] == request_msg
@@ -5292,6 +5355,10 @@ async def test_cancel_job_empty_call_grpc_asyncio():
52925355
# Establish that the underlying stub method was called.
52935356
call.assert_called()
52945357
_, args, _ = call.mock_calls[0]
5358+
# Ensure that the uuid4 field is set according to AIP 4235
5359+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
5360+
# clear UUID field so that the check below succeeds
5361+
args[0].request_id = None
52955362
request_msg = storage_batch_operations.CancelJobRequest()
52965363

52975364
assert args[0] == request_msg
@@ -6546,6 +6613,10 @@ def test_create_job_empty_call_rest():
65466613
# Establish that the underlying stub method was called.
65476614
call.assert_called()
65486615
_, args, _ = call.mock_calls[0]
6616+
# Ensure that the uuid4 field is set according to AIP 4235
6617+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
6618+
# clear UUID field so that the check below succeeds
6619+
args[0].request_id = None
65496620
request_msg = storage_batch_operations.CreateJobRequest()
65506621

65516622
assert args[0] == request_msg
@@ -6568,6 +6639,10 @@ def test_delete_job_empty_call_rest():
65686639
# Establish that the underlying stub method was called.
65696640
call.assert_called()
65706641
_, args, _ = call.mock_calls[0]
6642+
# Ensure that the uuid4 field is set according to AIP 4235
6643+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
6644+
# clear UUID field so that the check below succeeds
6645+
args[0].request_id = None
65716646
request_msg = storage_batch_operations.DeleteJobRequest()
65726647

65736648
assert args[0] == request_msg
@@ -6590,6 +6665,10 @@ def test_cancel_job_empty_call_rest():
65906665
# Establish that the underlying stub method was called.
65916666
call.assert_called()
65926667
_, args, _ = call.mock_calls[0]
6668+
# Ensure that the uuid4 field is set according to AIP 4235
6669+
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
6670+
# clear UUID field so that the check below succeeds
6671+
args[0].request_id = None
65936672
request_msg = storage_batch_operations.CancelJobRequest()
65946673

65956674
assert args[0] == request_msg

packages/gapic-generator/tests/integration/storagebatchoperations_v1.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ authentication:
5656
https://www.googleapis.com/auth/cloud-platform
5757
5858
publishing:
59+
method_settings:
60+
- selector: google.cloud.storagebatchoperations.v1.StorageBatchOperations.CreateJob
61+
auto_populated_fields:
62+
- request_id
63+
- selector: google.cloud.storagebatchoperations.v1.StorageBatchOperations.CancelJob
64+
auto_populated_fields:
65+
- request_id
66+
- selector: google.cloud.storagebatchoperations.v1.StorageBatchOperations.DeleteJob
67+
auto_populated_fields:
68+
- request_id
5969
new_issue_uri: https://issuetracker.google.com/issues/new?component=815827&template=1395449
6070
documentation_uri: https://cloud.google.com/storage/docs/batch-operations/overview
6171
api_short_name: storagebatchoperations

0 commit comments

Comments
 (0)