Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,15 @@ def test_{{ method_name }}(request_type, transport: str = 'grpc'):
{% if not field.oneof or field.proto3_optional %}
{{ field.name }}={{ field.mock_value }},
{% endif %}{% endfor %}
{# This is a hack to only pick one field #}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% with field = oneof_fields[0] %}
{# Take the first non-message oneof field. In the corner case when all the fields of a oneof are messages, the oneof will not be populated #}
{# Use an outer if-statement here because `first` raises an error if called on an empty sequence #}
{% if (oneof_fields | rejectattr('message') | list) %}
{% with field = (oneof_fields | rejectattr('message') | first) %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endif %}
{% endfor %}
)
{% endif %}
Expand Down Expand Up @@ -959,11 +963,13 @@ def test_{{ method_name }}_rest(request_type, transport: str = 'rest'):
{% if not field.oneof or field.proto3_optional %}
{{ field.name }}={{ field.mock_value }},
{% endif %}{% endfor %}
{# This is a hack to only pick one field #}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% with field = oneof_fields[0] %}
{% if (oneof_fields | rejectattr('message') | list) %}
{% with field = (oneof_fields | rejectattr('message') | first) %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endif %}
{% endfor %}
)
{% endif %}
Expand Down Expand Up @@ -1029,11 +1035,13 @@ def test_{{ method.name|snake_case }}_rest(request_type):
{% if not field.oneof or field.proto3_optional %}
{{ field.name }}={{ field.mock_value }},
{% endif %}{% endfor %}
{# This is a hack to only pick one field #}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% with field = oneof_fields[0] %}
{% if (oneof_fields | rejectattr('message') | list) %}
{% with field = (oneof_fields | rejectattr('message') | first) %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endif %}
{% endfor %}
)
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ def test_{{ method_name }}(request_type, transport: str = 'grpc'):
{% if not field.oneof or field.proto3_optional %}
{{ field.name }}={{ field.mock_value }},
{% endif %}{% endfor %}
{# This is a hack to only pick one field #}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% with field = oneof_fields[0] %}
{# Take the first non-message oneof field. In the corner case when all the fields of a oneof are messages, the oneof will not be populated #}
{# Use an outer if-statement here because `first` raises an error if called on an empty sequence #}
{% if (oneof_fields | rejectattr('message') | list) %}
{% with field = (oneof_fields | rejectattr('message') | first) %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endif %}
{% endfor %}
)
{% endif %}
Expand Down Expand Up @@ -903,11 +907,13 @@ def test_{{ method_name }}_rest(request_type):
{% if not field.oneof or field.proto3_optional %}
{{ field.name }}={{ field.mock_value }},
{% endif %}{% endfor %}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.extended_lro.operation_type.oneof_fields().values() %}
{% with field = oneof_fields[0] %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% if (oneof_fields | rejectattr('message') | list) %}
{% with field = (oneof_fields | rejectattr('message') | first) %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endif %}
{% endfor %}
)
{% else %}
Expand All @@ -916,12 +922,14 @@ def test_{{ method_name }}_rest(request_type):
{% if not field.oneof or field.proto3_optional %}
{{ field.name }}={{ field.mock_value }},
{% endif %}{% endfor %}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% with field = oneof_fields[0] %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endfor %}
{# This is a hack to only pick one field #}
{% for oneof_fields in method.output.oneof_fields().values() %}
{% if (oneof_fields | rejectattr('message') | list) %}
{% with field = (oneof_fields | rejectattr('message') | first) %}
{{ field.name }}={{ field.mock_value }},
{% endwith %}
{% endif %}
{% endfor %}
)
{% endif %}

Expand Down
41 changes: 41 additions & 0 deletions tests/fragments/test_oneof_imported_response.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2021 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/client.proto";
import "import.proto";

service MyService {
option (google.api.default_host) = "my.example.com";
rpc MyMethod(MethodRequest) returns (MethodResponse) {}
}

message MethodRequest {
string input = 1;
}

message Container {
Import import = 1;
}

message MethodResponse {
string parent = 1;
oneof format {
Container container = 2;
string name = 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,6 @@ def test_get_sink(request_type, transport: str = 'grpc'):
output_version_format=logging_config.LogSink.VersionFormat.V2,
writer_identity='writer_identity_value',
include_children=True,
bigquery_options=logging_config.BigQueryOptions(use_partitioned_tables=True),
)
response = client.get_sink(request)

Expand Down Expand Up @@ -3509,7 +3508,6 @@ def test_create_sink(request_type, transport: str = 'grpc'):
output_version_format=logging_config.LogSink.VersionFormat.V2,
writer_identity='writer_identity_value',
include_children=True,
bigquery_options=logging_config.BigQueryOptions(use_partitioned_tables=True),
)
response = client.create_sink(request)

Expand Down Expand Up @@ -3780,7 +3778,6 @@ def test_update_sink(request_type, transport: str = 'grpc'):
output_version_format=logging_config.LogSink.VersionFormat.V2,
writer_identity='writer_identity_value',
include_children=True,
bigquery_options=logging_config.BigQueryOptions(use_partitioned_tables=True),
)
response = client.update_sink(request)

Expand Down Expand Up @@ -8546,7 +8543,6 @@ def test_get_sink_rest(request_type):
output_version_format=logging_config.LogSink.VersionFormat.V2,
writer_identity='writer_identity_value',
include_children=True,
bigquery_options=logging_config.BigQueryOptions(use_partitioned_tables=True),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -8794,7 +8790,6 @@ def test_create_sink_rest(request_type):
output_version_format=logging_config.LogSink.VersionFormat.V2,
writer_identity='writer_identity_value',
include_children=True,
bigquery_options=logging_config.BigQueryOptions(use_partitioned_tables=True),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -9048,7 +9043,6 @@ def test_update_sink_rest(request_type):
output_version_format=logging_config.LogSink.VersionFormat.V2,
writer_identity='writer_identity_value',
include_children=True,
bigquery_options=logging_config.BigQueryOptions(use_partitioned_tables=True),
)

# Wrap the value into a proper Response obj
Expand Down