Skip to content
Closed
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 @@ -418,6 +418,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
self._transport.operations_client,
{{ method.lro.response_type.ident }},
metadata_type={{ method.lro.metadata_type.ident }},
{%- if method.field_headers %}
grpc_metadata=metadata,
{%- endif %}
)
{%- elif method.paged_result_field %}

Expand Down
2 changes: 1 addition & 1 deletion gapic/ads-templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setuptools.setup(
platforms='Posix; MacOS X; Windows',
include_package_data=True,
install_requires=(
'google-api-core >= 1.22.2, < 2.0.0dev',
'google-api-core >= 1.25.0, < 2.0.0dev',
'googleapis-common-protos >= 1.5.8',
'grpcio >= 1.10.0',
'proto-plus >= 1.4.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ def test_{{ method.name|snake_case }}_field_headers():

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.{{ method.name|snake_case }}),
'__call__') as call:
type(client.transport.{{ method.name|snake_case }}), "__call__"
) as call, mock.patch("google.api_core.operation.from_gapic") as from_gapic:
{% if method.void -%}
call.return_value = None
{% elif method.lro -%}
Expand All @@ -373,6 +373,17 @@ def test_{{ method.name|snake_case }}_field_headers():
{%- if not loop.last %}&{% endif -%}
{%- endfor %}',
) in kw['metadata']

# Assert that the field header was also passed to the operations client
assert len(from_gapic.mock_calls) == 1
_, _, from_gapic_kw = from_gapic.mock_calls[0]
assert (
'x-goog-request-params',
'{% for field_header in method.field_headers -%}
{{ field_header }}={{ field_header }}/value
{%- if not loop.last %}&{% endif -%}
{%- endfor %}',
) in from_gapic_kw['metadata']
{% endif %}

{% if method.ident.package != method.input.ident.package %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
self._transport.operations_client,
{{ method.lro.response_type.ident }},
metadata_type={{ method.lro.metadata_type.ident }},
{%- if method.field_headers %}
grpc_metadata=metadata,
{%- endif %}
)
{%- elif method.paged_result_field %}

Expand Down
2 changes: 1 addition & 1 deletion gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setuptools.setup(
platforms='Posix; MacOS X; Windows',
include_package_data=True,
install_requires=(
'google-api-core[grpc] >= 1.22.2, < 2.0.0dev',
'google-api-core[grpc] >= 1.25.0, < 2.0.0dev',
'libcst >= 0.2.5',
'proto-plus >= 1.4.0',
{%- if api.requires_package(('google', 'iam', 'v1')) or opts.add_iam_methods %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ def test_{{ method.name|snake_case }}_field_headers():

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.{{ method.name|snake_case }}),
'__call__') as call:
type(client.transport.{{ method.name|snake_case }}), "__call__"
) as call, mock.patch("google.api_core.operation.from_gapic") as from_gapic:
{% if method.void -%}
call.return_value = None
{% elif method.lro -%}
Expand All @@ -604,6 +604,17 @@ def test_{{ method.name|snake_case }}_field_headers():
{%- endfor %}',
) in kw['metadata']

# Assert that the field header was also passed to the operations client
assert len(from_gapic.mock_calls) == 1
_, _, from_gapic_kw = from_gapic.mock_calls[0]
assert (
'x-goog-request-params',
'{% for field_header in method.field_headers -%}
{{ field_header }}={{ field_header }}/value
{%- if not loop.last %}&{% endif -%}
{%- endfor %}',
) in from_gapic_kw['metadata']


@pytest.mark.asyncio
async def test_{{ method.name|snake_case }}_field_headers_async():
Expand All @@ -621,8 +632,8 @@ async def test_{{ method.name|snake_case }}_field_headers_async():

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.{{ method.name|snake_case }}),
'__call__') as call:
type(client.transport.{{ method.name|snake_case }}), "__call__"
) as call, mock.patch("google.api_core.operation_async.from_gapic") as from_gapic:
{% if method.void -%}
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
{% elif method.lro -%}
Expand All @@ -649,6 +660,16 @@ async def test_{{ method.name|snake_case }}_field_headers_async():
{%- if not loop.last %}&{% endif -%}
{%- endfor %}',
) in kw['metadata']
# Assert that the field header was also passed to the operations client
assert len(from_gapic.mock_calls) == 1
_, _, from_gapic_kw = from_gapic.mock_calls[0]
assert (
'x-goog-request-params',
'{% for field_header in method.field_headers -%}
{{ field_header }}={{ field_header }}/value
{%- if not loop.last %}&{% endif -%}
{%- endfor %}',
) in from_gapic_kw['metadata']
{% endif %}

{% if method.ident.package != method.input.ident.package %}
Expand Down