Luke Sneeringer | acb6e3e | 2017-10-31 08:57:09 -0700 | [diff] [blame] | 1 | # Copyright 2017 Google LLC |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 15 | from google.api_core import grpc_helpers |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 16 | from google.api_core import operations_v1 |
| 17 | from google.api_core import page_iterator |
| 18 | from google.longrunning import operations_pb2 |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 19 | from google.protobuf import empty_pb2 |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 20 | |
| 21 | |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 22 | def test_get_operation(): |
| 23 | channel = grpc_helpers.ChannelStub() |
| 24 | client = operations_v1.OperationsClient(channel) |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 25 | channel.GetOperation.response = operations_pb2.Operation(name="meep") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 26 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 27 | response = client.get_operation("name", metadata=[("header", "foo")]) |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 28 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 29 | assert ("header", "foo") in channel.GetOperation.calls[0].metadata |
| 30 | assert ("x-goog-request-params", "name=name") in channel.GetOperation.calls[0].metadata |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 31 | assert len(channel.GetOperation.requests) == 1 |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 32 | assert channel.GetOperation.requests[0].name == "name" |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 33 | assert response == channel.GetOperation.response |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 34 | |
| 35 | |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 36 | def test_list_operations(): |
| 37 | channel = grpc_helpers.ChannelStub() |
| 38 | client = operations_v1.OperationsClient(channel) |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 39 | operations = [ |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 40 | operations_pb2.Operation(name="1"), |
| 41 | operations_pb2.Operation(name="2"), |
| 42 | ] |
| 43 | list_response = operations_pb2.ListOperationsResponse(operations=operations) |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 44 | channel.ListOperations.response = list_response |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 45 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 46 | response = client.list_operations("name", "filter", metadata=[("header", "foo")]) |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 47 | |
| 48 | assert isinstance(response, page_iterator.Iterator) |
| 49 | assert list(response) == operations |
| 50 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 51 | assert ("header", "foo") in channel.ListOperations.calls[0].metadata |
| 52 | assert ("x-goog-request-params", "name=name") in channel.ListOperations.calls[0].metadata |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 53 | assert len(channel.ListOperations.requests) == 1 |
| 54 | request = channel.ListOperations.requests[0] |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 55 | assert isinstance(request, operations_pb2.ListOperationsRequest) |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 56 | assert request.name == "name" |
| 57 | assert request.filter == "filter" |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 58 | |
| 59 | |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 60 | def test_delete_operation(): |
| 61 | channel = grpc_helpers.ChannelStub() |
| 62 | client = operations_v1.OperationsClient(channel) |
| 63 | channel.DeleteOperation.response = empty_pb2.Empty() |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 64 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 65 | client.delete_operation("name", metadata=[("header", "foo")]) |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 66 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 67 | assert ("header", "foo") in channel.DeleteOperation.calls[0].metadata |
| 68 | assert ("x-goog-request-params", "name=name") in channel.DeleteOperation.calls[0].metadata |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 69 | assert len(channel.DeleteOperation.requests) == 1 |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 70 | assert channel.DeleteOperation.requests[0].name == "name" |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 71 | |
| 72 | |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 73 | def test_cancel_operation(): |
| 74 | channel = grpc_helpers.ChannelStub() |
| 75 | client = operations_v1.OperationsClient(channel) |
| 76 | channel.CancelOperation.response = empty_pb2.Empty() |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 77 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 78 | client.cancel_operation("name", metadata=[("header", "foo")]) |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 79 | |
Bu Sun Kim | 97cef4a | 2021-01-25 12:49:39 -0700 | [diff] [blame^] | 80 | assert ("header", "foo") in channel.CancelOperation.calls[0].metadata |
| 81 | assert ("x-goog-request-params", "name=name") in channel.CancelOperation.calls[0].metadata |
Jon Wayne Parrott | 37658c1 | 2018-01-05 14:54:49 -0800 | [diff] [blame] | 82 | assert len(channel.CancelOperation.requests) == 1 |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 83 | assert channel.CancelOperation.requests[0].name == "name" |