blob: 69d4dfc2831f9aaf89afaf67311ae367f4978d79 [file] [log] [blame]
Luke Sneeringeracb6e3e2017-10-31 08:57:09 -07001# Copyright 2017 Google LLC
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -07002#
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 Parrott37658c12018-01-05 14:54:49 -080015from google.api_core import grpc_helpers
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070016from google.api_core import operations_v1
17from google.api_core import page_iterator
18from google.longrunning import operations_pb2
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080019from google.protobuf import empty_pb2
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070020
21
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080022def test_get_operation():
23 channel = grpc_helpers.ChannelStub()
24 client = operations_v1.OperationsClient(channel)
25 channel.GetOperation.response = operations_pb2.Operation(name='meep')
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070026
27 response = client.get_operation('name')
28
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080029 assert len(channel.GetOperation.requests) == 1
30 assert channel.GetOperation.requests[0].name == 'name'
31 assert response == channel.GetOperation.response
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070032
33
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080034def test_list_operations():
35 channel = grpc_helpers.ChannelStub()
36 client = operations_v1.OperationsClient(channel)
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070037 operations = [
38 operations_pb2.Operation(name='1'),
39 operations_pb2.Operation(name='2')]
40 list_response = operations_pb2.ListOperationsResponse(
41 operations=operations)
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080042 channel.ListOperations.response = list_response
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070043
44 response = client.list_operations('name', 'filter')
45
46 assert isinstance(response, page_iterator.Iterator)
47 assert list(response) == operations
48
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080049 assert len(channel.ListOperations.requests) == 1
50 request = channel.ListOperations.requests[0]
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070051 assert isinstance(request, operations_pb2.ListOperationsRequest)
52 assert request.name == 'name'
53 assert request.filter == 'filter'
54
55
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080056def test_delete_operation():
57 channel = grpc_helpers.ChannelStub()
58 client = operations_v1.OperationsClient(channel)
59 channel.DeleteOperation.response = empty_pb2.Empty()
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070060
61 client.delete_operation('name')
62
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080063 assert len(channel.DeleteOperation.requests) == 1
64 assert channel.DeleteOperation.requests[0].name == 'name'
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070065
66
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080067def test_cancel_operation():
68 channel = grpc_helpers.ChannelStub()
69 client = operations_v1.OperationsClient(channel)
70 channel.CancelOperation.response = empty_pb2.Empty()
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070071
72 client.cancel_operation('name')
73
Jon Wayne Parrott37658c12018-01-05 14:54:49 -080074 assert len(channel.CancelOperation.requests) == 1
75 assert channel.CancelOperation.requests[0].name == 'name'