Skip to content

Commit e353e61

Browse files
authored
Tweak ads tests (#509)
1 parent 4900b3c commit e353e61

File tree

1 file changed

+14
-3
lines changed
  • packages/gapic-generator/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub

1 file changed

+14
-3
lines changed

packages/gapic-generator/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,15 @@ def test_{{ method.name|snake_case }}(transport: str = 'grpc'):
217217
call.return_value = iter([{{ method.output.ident }}()])
218218
{% else -%}
219219
call.return_value = {{ method.output.ident }}(
220-
{%- for field in method.output.fields.values() | rejectattr('message') %}
220+
{%- for field in method.output.fields.values() | rejectattr('message') %}{%- for field in method.output.fields.values() | rejectattr('message')%}{% if not field.oneof or field.proto3_optional %}
221221
{{ field.name }}={{ field.mock_value }},
222222
{%- endfor %}
223+
{#- This is a hack to only pick one field #}
224+
{%- for oneof_fields in method.output.oneof_fields().values() %}
225+
{% with field = oneof_fields[0] %}
226+
{{ field.name }}={{ field.mock_value }},
227+
{%- endwith %}
228+
{%- endfor %}
223229
)
224230
{% endif -%}
225231
{% if method.client_streaming %}
@@ -364,9 +370,14 @@ def test_{{ method.name|snake_case }}_flattened():
364370
# request object values.
365371
assert len(call.mock_calls) == 1
366372
_, args, _ = call.mock_calls[0]
367-
{% for key, field in method.flattened_fields.items() -%}
373+
{% for key, field in method.flattened_fields.items() -%}{%- if not field.oneof or field.proto3_optional %}
368374
assert args[0].{{ key }} == {{ field.mock_value }}
369-
{% endfor %}
375+
{% endif %}{% endfor %}
376+
{%- for oneofs in method.flattened_oneof_fields().values() %}
377+
{%- with field = oneofs[-1] %}
378+
assert args[0].{{ method.flattened_field_to_key[field.name] }} == {{ field.mock_value }}
379+
{%- endwith %}
380+
{%- endfor %}
370381

371382

372383
def test_{{ method.name|snake_case }}_flattened_error():

0 commit comments

Comments
 (0)