aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/operations_v1/test_operations_client.py
diff options
context:
space:
mode:
authorchojoyce <chojoyce@google.com>2022-01-05 05:06:59 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-01-05 05:06:59 +0000
commite82c234cd2a425bd77dc184ad3003fd9c37e57fe (patch)
tree412a59ade78bcacc2449642d7cfd7ccb6a92d8e4 /tests/unit/operations_v1/test_operations_client.py
parentd4dcb747f8ac4df33c321b19ee1c511f6e47707e (diff)
parent01e15770edd19b8841f9f50204584e02749842d6 (diff)
downloadpython-api-core-e82c234cd2a425bd77dc184ad3003fd9c37e57fe.tar.gz
Merge platform/external/python/python-api-core v2.3.0 am: 4e81cd9cc2 am: 95950852f5 am: 01e15770ed
Original change: https://android-review.googlesource.com/c/platform/external/python/python-api-core/+/1931601 Change-Id: Ife443057153866c806b133c15ab2aa5020bd4e77
Diffstat (limited to 'tests/unit/operations_v1/test_operations_client.py')
-rw-r--r--tests/unit/operations_v1/test_operations_client.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/unit/operations_v1/test_operations_client.py b/tests/unit/operations_v1/test_operations_client.py
new file mode 100644
index 0000000..187f0be
--- /dev/null
+++ b/tests/unit/operations_v1/test_operations_client.py
@@ -0,0 +1,98 @@
+# Copyright 2017 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+
+try:
+ import grpc # noqa: F401
+except ImportError:
+ pytest.skip("No GRPC", allow_module_level=True)
+
+from google.api_core import grpc_helpers
+from google.api_core import operations_v1
+from google.api_core import page_iterator
+from google.longrunning import operations_pb2
+from google.protobuf import empty_pb2
+
+
+def test_get_operation():
+ channel = grpc_helpers.ChannelStub()
+ client = operations_v1.OperationsClient(channel)
+ channel.GetOperation.response = operations_pb2.Operation(name="meep")
+
+ response = client.get_operation("name", metadata=[("header", "foo")])
+
+ 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
+
+
+def test_list_operations():
+ channel = grpc_helpers.ChannelStub()
+ client = operations_v1.OperationsClient(channel)
+ operations = [
+ operations_pb2.Operation(name="1"),
+ operations_pb2.Operation(name="2"),
+ ]
+ list_response = operations_pb2.ListOperationsResponse(operations=operations)
+ channel.ListOperations.response = list_response
+
+ response = client.list_operations("name", "filter", metadata=[("header", "foo")])
+
+ assert isinstance(response, page_iterator.Iterator)
+ assert list(response) == operations
+
+ 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)
+ assert request.name == "name"
+ assert request.filter == "filter"
+
+
+def test_delete_operation():
+ channel = grpc_helpers.ChannelStub()
+ client = operations_v1.OperationsClient(channel)
+ channel.DeleteOperation.response = empty_pb2.Empty()
+
+ client.delete_operation("name", metadata=[("header", "foo")])
+
+ 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"
+
+
+def test_cancel_operation():
+ channel = grpc_helpers.ChannelStub()
+ client = operations_v1.OperationsClient(channel)
+ channel.CancelOperation.response = empty_pb2.Empty()
+
+ client.cancel_operation("name", metadata=[("header", "foo")])
+
+ 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"