Skip to content

Commit

Permalink
fix: type error for compute client(s) tests (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Apr 26, 2024
1 parent c95cd22 commit 61f50f7
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def test_{{ method_name }}_empty_call():
with mock.patch.object(
type(client.transport.{{ method.transport_safe_name|snake_case }}),
'__call__') as call:
call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string.
client.{{ method_name }}()
call.assert_called()
_, args, _ = call.mock_calls[0]
Expand Down Expand Up @@ -176,6 +177,7 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
with mock.patch.object(
type(client.transport.{{ method.transport_safe_name|snake_case }}),
'__call__') as call:
call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string.
client.{{ method_name }}(request=request)
call.assert_called()
_, args, _ = call.mock_calls[0]
Expand Down Expand Up @@ -214,8 +216,8 @@ def test_{{ method_name }}_use_cached_wrapped_rpc():

# Replace cached wrapped function with mock
mock_rpc = mock.Mock()
mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string.
client._transport._wrapped_methods[client._transport.{{method.transport_safe_name|snake_case}}] = mock_rpc

{% if method.client_streaming %}
request = [{}]
client.{{ method.safe_name|snake_case }}(request)
Expand Down Expand Up @@ -1338,6 +1340,7 @@ def test_{{ method_name }}_rest_use_cached_wrapped_rpc():

# Replace cached wrapped function with mock
mock_rpc = mock.Mock()
mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string.
client._transport._wrapped_methods[client._transport.{{method.transport_safe_name|snake_case}}] = mock_rpc

{% if method.client_streaming %}
Expand Down
108 changes: 108 additions & 0 deletions tests/fragments/test_compute_operation.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (C) 2023 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.

syntax = "proto3";

package google.fragment;

import "google/api/annotations.proto";
import "google/cloud/extended_operations.proto";
import "google/protobuf/struct.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";


message GetRegionOperationRequest {
// Name of the Operations resource to return.
string operation = 52090215 [
(google.api.field_behavior) = REQUIRED,
(google.cloud.operation_response_field) = "name"
];

// Project ID for this request.
string project = 227560217 [(google.api.field_behavior) = REQUIRED];

// Name of the region for this request.
string region = 138946292 [(google.api.field_behavior) = REQUIRED];
}

// A request message for Addresses.Insert. See the method description for details.
message InsertAddressRequest {
// The body resource for this request
Address address_resource = 483888121;

// Project ID for this request.
string project = 227560217;

// Name of the region for this request.
string region = 138946292;

}

message Address {
// The static IP address represented by this resource.
optional string address = 462920692;
}

message Operation {

// [Output Only] The status of the operation, which can be one of the following: `PENDING`, `RUNNING`, or `DONE`.
enum Status {
DONE = 0;
}

// [Output Only] Name of the operation.
optional string name = 3373707 [(google.cloud.operation_field) = NAME];

// [Output Only] If the operation fails, this field contains the HTTP error message that was returned, such as `NOT FOUND`.
optional string http_error_message = 202521945 [(google.cloud.operation_field) = ERROR_MESSAGE];

// [Output Only] If the operation fails, this field contains the HTTP error status code that was returned. For example, a `404` means the resource was not found.
optional int32 http_error_status_code = 312345196 [(google.cloud.operation_field) = ERROR_CODE];

// [Output Only] The status of the operation, which can be one of the following: `PENDING`, `RUNNING`, or `DONE`.
optional Status status = 181260274 [(google.cloud.operation_field) = STATUS];
}

// The RegionOperations API.
service RegionOperations {
option (google.api.default_host) =
"compute.googleapis.com";

// Retrieves the specified region-specific Operations resource.
rpc Get(GetRegionOperationRequest) returns (Operation) {
option (google.api.http) = {
get: "/compute/v1/projects/{project}/regions/{region}/operations/{operation}"
};
option (google.api.method_signature) = "project,region,operation";
option (google.cloud.operation_polling_method) = true;
}
}

// The Addresses API.
service Addresses {
option (google.api.default_host) =
"compute.googleapis.com";

// Creates an address resource in the specified project by using the data included in the request.
rpc Insert(InsertAddressRequest) returns (Operation) {
option (google.api.http) = {
body: "address_resource"
post: "/compute/v1/projects/{project}/regions/{region}/addresses"
};
option (google.api.method_signature) = "project,region,address_resource";
option (google.cloud.operation_service) = "RegionOperations";
}
}

Loading

0 comments on commit 61f50f7

Please sign in to comment.