Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,10 @@ def test_{{ service.client_name|snake_case }}_create_channel_credentials_file(cl

{% for method in service.methods.values() if 'rest' in opts.transport %}
{% if method.extended_lro %}
{{ test_macros.rest_required_tests(method, service, numeric_enums=opts.rest_numeric_enums, full_extended_lro=True) }}
{{ test_macros.rest_required_tests(api, method, service, numeric_enums=opts.rest_numeric_enums, full_extended_lro=True) }}

{% endif %}
{{ test_macros.rest_required_tests(method, service, numeric_enums=opts.rest_numeric_enums) }}
{{ test_macros.rest_required_tests(api, method, service, numeric_enums=opts.rest_numeric_enums) }}

{% endfor -%} {#- method in methods for rest #}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def test_{{ method_name }}_raw_page_lro():
{% endif %}{# method.paged_result_field #}{% endwith %}
{% endmacro %}

{% macro rest_required_tests(method, service, numeric_enums=False, full_extended_lro=False) %}
{% macro rest_required_tests(api, method, service, numeric_enums=False, full_extended_lro=False) %}
{% with method_name = method.client_method_name|snake_case + "_unary" if method.extended_lro and not full_extended_lro else method.client_method_name|snake_case, method_output = method.extended_lro.operation_type if method.extended_lro and not full_extended_lro else method.output %}{% if method.http_options %}
{# TODO(kbandes): remove this if condition when lro and client streaming are supported. #}
{% if not method.client_streaming %}
Expand Down Expand Up @@ -1218,6 +1218,24 @@ def test_{{ method_name }}_rest_required_fields(request_type={{ method.input.ide
('$alt', 'json;enum-encoding=int')
{% endif %}
]
{% with method_settings = api.all_method_settings.get(method.meta.address.proto) %}
{% if method_settings is not none %}
{% for auto_populated_field in method_settings.auto_populated_fields %}
# Ensure that the uuid4 field is set according to AIP 4235
# and remove it so the expected/actual comparison succeeds.
# Otherwise, the actual will differ from the expected since
# this field was automatically populated.
found_field = None
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
if key == "{{ auto_populated_field|camel_case }}":
assert re.match(r"{{ get_uuid4_re() }}", value)
found_field = i
break
if found_field is not None:
del req.call_args.kwargs['params'][found_field]
{% endfor %}
{% endif %}
{% endwith %}
actual_params = req.call_args.kwargs['params']
assert expected_params == actual_params

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from collections import OrderedDict
import re
from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union
import uuid

from google.cloud.storagebatchoperations_v1 import gapic_version as package_version

Expand Down Expand Up @@ -620,6 +621,9 @@ async def sample_create_job():
)),
)

if not request.request_id:
request.request_id = str(uuid.uuid4())

# Validate the universe domain.
self._client._validate_universe_domain()

Expand Down Expand Up @@ -724,6 +728,9 @@ async def sample_delete_job():
)),
)

if not request.request_id:
request.request_id = str(uuid.uuid4())

# Validate the universe domain.
self._client._validate_universe_domain()

Expand Down Expand Up @@ -824,6 +831,9 @@ async def sample_cancel_job():
)),
)

if not request.request_id:
request.request_id = str(uuid.uuid4())

# Validate the universe domain.
self._client._validate_universe_domain()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import re
from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast
import uuid
import warnings

from google.cloud.storagebatchoperations_v1 import gapic_version as package_version
Expand Down Expand Up @@ -1004,6 +1005,9 @@ def sample_create_job():
)),
)

if not request.request_id:
request.request_id = str(uuid.uuid4())
Comment on lines +1008 to +1009
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to AIP-4235, auto-population of fields should be handled by the client library's RPC methods. If the generator is updated to support auto_populated_fields, this logic should ideally be placed within the generated RPC methods rather than the sample code. This keeps the samples clean and ensures the feature is available to all users of the library, not just those following the samples.

References
  1. According to AIP-4235, auto-population of fields should be handled by the client library's RPC methods. (link)


# Validate the universe domain.
self._validate_universe_domain()

Expand Down Expand Up @@ -1107,6 +1111,9 @@ def sample_delete_job():
)),
)

if not request.request_id:
request.request_id = str(uuid.uuid4())

# Validate the universe domain.
self._validate_universe_domain()

Expand Down Expand Up @@ -1206,6 +1213,9 @@ def sample_cancel_job():
)),
)

if not request.request_id:
request.request_id = str(uuid.uuid4())

# Validate the universe domain.
self._validate_universe_domain()

Expand Down
Loading
Loading