Skip to content

Commit ef0883c

Browse files
committed
chore: use mock.ANY instead of None in empty request tests to cater for AIP-4235
1 parent 9b99fa1 commit ef0883c

14 files changed

Lines changed: 29 additions & 482 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def test_{{ method_name }}_empty_call():
694694
# Ensure that the uuid4 field is set according to AIP 4235
695695
assert re.match(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
696696
# clear UUID field so that the check below succeeds
697-
args[0].{{ auto_populated_field }} = None
697+
args[0].{{ auto_populated_field }} = ""
698698
{% endfor %}
699699
{% endif %}{# if method_settings is not none #}
700700
{% endwith %}{# method_settings #}
@@ -732,7 +732,7 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
732732
# Ensure that the uuid4 field is set according to AIP 4235
733733
assert re.match(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
734734
# clear UUID field so that the check below succeeds
735-
args[0].{{ auto_populated_field }} = None
735+
args[0].{{ auto_populated_field }} = ""
736736
{% endfor %}
737737
{% endif %}{# if method_settings is not none #}
738738
{% endwith %}{# method_settings #}

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,20 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
152152
{% for auto_populated_field in method_settings.auto_populated_fields %}
153153
# Ensure that the uuid4 field is set according to AIP 4235
154154
assert re.match(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
155-
# clear UUID field so that the check below succeeds
156-
args[0].{{ auto_populated_field }} = None
157155
{% endfor %}
158156
{% endif %}{# if method_settings is not none #}
159157
{% endwith %}{# method_settings #}
160158
assert args[0] == {{ method.input.ident }}(
161159
{% for field in method.input.fields.values() if field.ident|string() == "str" and not field.uuid4 %}
162160
{{ field.name }}={{ field.mock_value }},
163161
{% endfor %}
162+
{% with method_settings = api.all_method_settings.get(method.meta.address.proto) %}
163+
{% if method_settings is not none %}
164+
{% for auto_populated_field in method_settings.auto_populated_fields %}
165+
{{ auto_populated_field }}=mock.ANY,
166+
{% endfor %}
167+
{% endif %}
168+
{% endwith %}
164169
)
165170
{% endif %}
166171

@@ -1577,16 +1582,21 @@ def test_{{ method_name }}_rest_no_http_options():
15771582
{% for auto_populated_field in method_settings.auto_populated_fields %}
15781583
# Ensure that the uuid4 field is set according to AIP 4235
15791584
assert re.match(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
1580-
# clear UUID field so that the check below succeeds
1581-
args[0].{{ auto_populated_field }} = None
15821585
{% endfor %}{# for auto_populated_field in method_settings.auto_populated_fields #}
15831586
{% endif %}{# if method_settings is not none #}
15841587
{% endwith %}{# method_settings #}
15851588
{% if request_dict %}
15861589
request_msg = {{ method.input.ident }}(**{{ request_dict }})
15871590
{% else %}
15881591
request_msg = {{ method.input.ident }}()
1589-
{% endif %}{# request_dict #}
1592+
{% endif %}{# request_dict #}
1593+
{% with method_settings = api.all_method_settings.get(method.meta.address.proto) %}
1594+
{% if method_settings is not none %}
1595+
{% for auto_populated_field in method_settings.auto_populated_fields %}
1596+
request_msg.{{ auto_populated_field }} = mock.ANY
1597+
{% endfor %}
1598+
{% endif %}
1599+
{% endwith %}
15901600
assert args[0] == request_msg
15911601

15921602
{% if routing_param %}

0 commit comments

Comments
 (0)