|
1 | | -{% macro grpc_required_tests(method, service, full_extended_lro=False) %} |
| 1 | +{% macro grpc_required_tests(method, service, api, full_extended_lro=False) %} |
2 | 2 | {% with method_name = method.safe_name|snake_case + "_unary" if method.extended_lro and not full_extended_lro else method.safe_name|snake_case, method_output = method.extended_lro.operation_type if method.extended_lro and not full_extended_lro else method.output %} |
3 | 3 | @pytest.mark.parametrize("request_type", [ |
4 | 4 | {{ method.input.ident }}, |
@@ -58,7 +58,19 @@ def test_{{ method_name }}(request_type, transport: str = 'grpc'): |
58 | 58 | {% if method.client_streaming %} |
59 | 59 | assert next(args[0]) == request |
60 | 60 | {% else %} |
61 | | - assert args[0] == {{ method.input.ident }}() |
| 61 | + request = {{ method.input.ident }}() |
| 62 | +{% with method_settings = api.all_method_settings.get(method.meta.address.proto) %} |
| 63 | +{% if method_settings is not none %} |
| 64 | +{% for auto_populated_field in method_settings.auto_populated_fields %} |
| 65 | + # Ensure that the uuid4 field is set according to AIP 4235 |
| 66 | + re.match(r"[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z", args[0].{{ auto_populated_field }}) |
| 67 | + # clear UUID field so that the check below succeeds |
| 68 | + args[0].{{ auto_populated_field }} = "" |
| 69 | +{% endfor %} |
| 70 | +{% endif %}{# if method_settings is not none #} |
| 71 | +{% endwith %}{# method_settings #} |
| 72 | + |
| 73 | + assert args[0] == request |
62 | 74 | {% endif %} |
63 | 75 |
|
64 | 76 | # Establish that the response is the type that we expect. |
@@ -119,6 +131,16 @@ def test_{{ method_name }}_empty_call(): |
119 | 131 | {% if method.client_streaming %} |
120 | 132 | assert next(args[0]) == request |
121 | 133 | {% else %} |
| 134 | +{% with method_settings = api.all_method_settings.get(method.meta.address.proto) %} |
| 135 | +{% if method_settings is not none %} |
| 136 | +{% for auto_populated_field in method_settings.auto_populated_fields %} |
| 137 | + # Ensure that the uuid4 field is set according to AIP 4235 |
| 138 | + re.match(r"[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z", args[0].{{ auto_populated_field }}) |
| 139 | + # clear UUID field so that the check below succeeds |
| 140 | + args[0].{{ auto_populated_field }} = "" |
| 141 | +{% endfor %} |
| 142 | +{% endif %}{# if method_settings is not none #} |
| 143 | +{% endwith %}{# method_settings #} |
122 | 144 | assert args[0] == {{ method.input.ident }}() |
123 | 145 | {% endif %} |
124 | 146 | {% endif %} |
@@ -182,6 +204,16 @@ async def test_{{ method_name }}_async(transport: str = 'grpc_asyncio', request_ |
182 | 204 | {% if method.client_streaming %} |
183 | 205 | assert next(args[0]) == request |
184 | 206 | {% else %} |
| 207 | +{% with method_settings = api.all_method_settings.get(method.meta.address.proto) %} |
| 208 | +{% if method_settings is not none %} |
| 209 | +{% for auto_populated_field in method_settings.auto_populated_fields %} |
| 210 | + # Ensure that the uuid4 field is set according to AIP 4235 |
| 211 | + re.match(r"[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z", args[0].{{ auto_populated_field }}) |
| 212 | + # clear UUID field so that the check below succeeds |
| 213 | + args[0].{{ auto_populated_field }} = "" |
| 214 | +{% endfor %} |
| 215 | +{% endif %}{# if method_settings is not none #} |
| 216 | +{% endwith %}{# method_settings #} |
185 | 217 | assert args[0] == {{ method.input.ident }}() |
186 | 218 | {% endif %} |
187 | 219 |
|
|
0 commit comments