Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add operation name to x-goog-request-params #133

Merged
merged 2 commits into from Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions google/api_core/operations_v1/operations_client.py
Expand Up @@ -134,6 +134,11 @@ def get_operation(
subclass will be raised.
"""
request = operations_pb2.GetOperationRequest(name=name)

# Add routing header
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

return self._get_operation(request, retry=retry, timeout=timeout, metadata=metadata)

def list_operations(
Expand Down Expand Up @@ -196,6 +201,10 @@ def list_operations(
# Create the request object.
request = operations_pb2.ListOperationsRequest(name=name, filter=filter_)

# Add routing header
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

# Create the method used to fetch pages
method = functools.partial(self._list_operations, retry=retry, timeout=timeout, metadata=metadata)

Expand Down Expand Up @@ -260,6 +269,11 @@ def cancel_operation(
"""
# Create the request object.
request = operations_pb2.CancelOperationRequest(name=name)

# Add routing header
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

self._cancel_operation(request, retry=retry, timeout=timeout, metadata=metadata)

def delete_operation(
Expand Down Expand Up @@ -306,4 +320,9 @@ def delete_operation(
"""
# Create the request object.
request = operations_pb2.DeleteOperationRequest(name=name)

# Add routing header
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

self._delete_operation(request, retry=retry, timeout=timeout, metadata=metadata)
20 changes: 12 additions & 8 deletions tests/unit/operations_v1/test_operations_client.py
Expand Up @@ -24,9 +24,10 @@ def test_get_operation():
client = operations_v1.OperationsClient(channel)
channel.GetOperation.response = operations_pb2.Operation(name="meep")

response = client.get_operation("name", metadata=[("x-goog-request-params", "foo")])
response = client.get_operation("name", metadata=[("header", "foo")])

assert ("x-goog-request-params", "foo") in channel.GetOperation.calls[0].metadata
assert ("header", "foo") in channel.GetOperation.calls[0].metadata
assert ("x-goog-request-params", "name=name") in channel.GetOperation.calls[0].metadata
assert len(channel.GetOperation.requests) == 1
assert channel.GetOperation.requests[0].name == "name"
assert response == channel.GetOperation.response
Expand All @@ -42,12 +43,13 @@ def test_list_operations():
list_response = operations_pb2.ListOperationsResponse(operations=operations)
channel.ListOperations.response = list_response

response = client.list_operations("name", "filter", metadata=[("x-goog-request-params", "foo")])
response = client.list_operations("name", "filter", metadata=[("header", "foo")])

assert isinstance(response, page_iterator.Iterator)
assert list(response) == operations

assert ("x-goog-request-params", "foo") in channel.ListOperations.calls[0].metadata
assert ("header", "foo") in channel.ListOperations.calls[0].metadata
assert ("x-goog-request-params", "name=name") in channel.ListOperations.calls[0].metadata
assert len(channel.ListOperations.requests) == 1
request = channel.ListOperations.requests[0]
assert isinstance(request, operations_pb2.ListOperationsRequest)
Expand All @@ -60,9 +62,10 @@ def test_delete_operation():
client = operations_v1.OperationsClient(channel)
channel.DeleteOperation.response = empty_pb2.Empty()

client.delete_operation("name", metadata=[("x-goog-request-params", "foo")])
client.delete_operation("name", metadata=[("header", "foo")])

assert ("x-goog-request-params", "foo") in channel.DeleteOperation.calls[0].metadata
assert ("header", "foo") in channel.DeleteOperation.calls[0].metadata
assert ("x-goog-request-params", "name=name") in channel.DeleteOperation.calls[0].metadata
assert len(channel.DeleteOperation.requests) == 1
assert channel.DeleteOperation.requests[0].name == "name"

Expand All @@ -72,8 +75,9 @@ def test_cancel_operation():
client = operations_v1.OperationsClient(channel)
channel.CancelOperation.response = empty_pb2.Empty()

client.cancel_operation("name", metadata=[("x-goog-request-params", "foo")])
client.cancel_operation("name", metadata=[("header", "foo")])

assert ("x-goog-request-params", "foo") in channel.CancelOperation.calls[0].metadata
assert ("header", "foo") in channel.CancelOperation.calls[0].metadata
assert ("x-goog-request-params", "name=name") in channel.CancelOperation.calls[0].metadata
assert len(channel.CancelOperation.requests) == 1
assert channel.CancelOperation.requests[0].name == "name"