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"
async def test_list_operations(): operations = [ operations_pb2.Operation(name="1"), operations_pb2.Operation(name="2"), ] list_response = operations_pb2.ListOperationsResponse( operations=operations) mocked_channel, method, fake_call = _mock_grpc_objects(list_response) client = operations_v1.OperationsAsyncClient(mocked_channel) pager = await client.list_operations("name", "filter", metadata=[("header", "foo")]) assert isinstance(pager, page_iterator_async.AsyncIterator) responses = [] async for response in pager: responses.append(response) assert responses == operations assert method.call_count == 1 assert ("header", "foo") in tuple(method.call_args_list[0])[1]["metadata"] assert ("x-goog-request-params", "name=name") in tuple(method.call_args_list[0])[1]["metadata"] request = tuple(method.call_args_list[0])[0][0] assert isinstance(request, operations_pb2.ListOperationsRequest) assert request.name == "name" assert request.filter == "filter"
def test_set_list(): list_ops_response = operations_pb2.ListOperationsResponse() protobuf_helpers.set(list_ops_response, 'operations', [ { 'name': 'foo' }, operations_pb2.Operation(name='bar'), ]) assert len(list_ops_response.operations) == 2 for operation in list_ops_response.operations: assert isinstance(operation, operations_pb2.Operation) assert list_ops_response.operations[0].name == 'foo' assert list_ops_response.operations[1].name == 'bar'
def test_set_list(): list_ops_response = operations_pb2.ListOperationsResponse() protobuf_helpers.set( list_ops_response, "operations", [{ "name": "foo" }, operations_pb2.Operation(name="bar")], ) assert len(list_ops_response.operations) == 2 for operation in list_ops_response.operations: assert isinstance(operation, operations_pb2.Operation) assert list_ops_response.operations[0].name == "foo" assert list_ops_response.operations[1].name == "bar"
def test_list_operations(operations_stub): client = operations_v1.OperationsClient(mock.sentinel.channel) operations = [ operations_pb2.Operation(name='1'), operations_pb2.Operation(name='2') ] list_response = operations_pb2.ListOperationsResponse( operations=operations) client.operations_stub.ListOperations.return_value = list_response response = client.list_operations('name', 'filter') assert isinstance(response, page_iterator.Iterator) assert list(response) == operations request = client.operations_stub.ListOperations.call_args[0][0] assert isinstance(request, operations_pb2.ListOperationsRequest) assert request.name == 'name' assert request.filter == 'filter'
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') assert isinstance(response, page_iterator.Iterator) assert list(response) == operations 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 _list_operations( self, request: operations_pb2.ListOperationsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. Args: request (~.operations_pb2.ListOperationsRequest): The request object. The request message for [Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations]. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.operations_pb2.ListOperationsResponse: The response message for [Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations]. """ http_options = [ { "method": "get", "uri": "/v1/{name=operations}" }, ] if "google.longrunning.Operations.ListOperations" in self._http_options: http_options = self._http_options[ "google.longrunning.Operations.ListOperations"] request_kwargs = json_format.MessageToDict( request, preserving_proto_field_name=True, including_default_value_fields=True, ) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params_request = operations_pb2.ListOperationsRequest() json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response api_response = operations_pb2.ListOperationsResponse() json_format.Parse(response.content, api_response, ignore_unknown_fields=False) return api_response