Skip to content
Open
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 @@ -6,6 +6,7 @@
import os
{% if api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|list %}
Comment thread
parthea marked this conversation as resolved.
import re
_UUID4_RE = re.compile(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}")
Comment thread
parthea marked this conversation as resolved.
{% endif %}
from unittest import mock
from unittest.mock import AsyncMock
Expand Down Expand Up @@ -71,7 +72,7 @@ from google.iam.v1 import policy_pb2 # type: ignore
{{ shared_macros.add_google_api_core_version_header_import(service.version) }}


{% with uuid4_re = "[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}" %}


def client_cert_source_callback():
return b"cert bytes", b"key bytes"
Expand Down Expand Up @@ -692,7 +693,7 @@ def test_{{ method_name }}_empty_call():
{% if method_settings is not none %}
{% for auto_populated_field in method_settings.auto_populated_fields %}
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
assert _UUID4_RE.match(args[0].{{ auto_populated_field }})
# clear UUID field so that the check below succeeds
args[0].{{ auto_populated_field }} = None
{% endfor %}
Expand Down Expand Up @@ -730,7 +731,7 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
{% if method_settings is not none %}
{% for auto_populated_field in method_settings.auto_populated_fields %}
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"{{ uuid4_re }}", args[0].{{ auto_populated_field }})
assert _UUID4_RE.match(args[0].{{ auto_populated_field }})
# clear UUID field so that the check below succeeds
args[0].{{ auto_populated_field }} = None
{% endfor %}
Expand Down Expand Up @@ -2488,5 +2489,5 @@ def test_client_ctx():
pass
close.assert_called()

{% endwith %}{# uuid4_re #}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
{% if api.all_method_settings.values()|map(attribute="auto_populated_fields", default=[])|list %}
Comment thread
parthea marked this conversation as resolved.
import re
_UUID4_RE = re.compile(r"{{ test_macros.get_uuid4_re() }}")
{% endif %}
from unittest import mock
from unittest.mock import AsyncMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_{{ method_name }}_non_empty_request_with_auto_populated_field():
{% if method_settings is not none %}
{% for auto_populated_field in method_settings.auto_populated_fields %}
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
assert _UUID4_RE.match(args[0].{{ auto_populated_field }})
# clear UUID field so that the check below succeeds
args[0].{{ auto_populated_field }} = None
{% endfor %}
Expand Down Expand Up @@ -1228,7 +1228,7 @@ def test_{{ method_name }}_rest_required_fields(request_type={{ method.input.ide
found_field = None
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
if key == "{{ auto_populated_field|camel_case }}":
assert re.match(r"{{ get_uuid4_re() }}", value)
assert _UUID4_RE.match(value)
found_field = i
break
if found_field is not None:
Expand Down Expand Up @@ -1577,7 +1577,7 @@ def test_{{ method_name }}_rest_no_http_options():
{% if method_settings is not none %}
{% for auto_populated_field in method_settings.auto_populated_fields %}
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"{{ get_uuid4_re() }}", args[0].{{ auto_populated_field }})
assert _UUID4_RE.match(args[0].{{ auto_populated_field }})
# clear UUID field so that the check below succeeds
args[0].{{ auto_populated_field }} = None
{% endfor %}{# for auto_populated_field in method_settings.auto_populated_fields #}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
import os
import re
_UUID4_RE = re.compile(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}")
from unittest import mock
from unittest.mock import AsyncMock

Expand Down Expand Up @@ -1863,7 +1864,7 @@ def test_create_job_non_empty_request_with_auto_populated_field():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
assert args[0] == storage_batch_operations.CreateJobRequest(
Expand Down Expand Up @@ -2215,7 +2216,7 @@ def test_delete_job_non_empty_request_with_auto_populated_field():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
assert args[0] == storage_batch_operations.DeleteJobRequest(
Expand Down Expand Up @@ -2533,7 +2534,7 @@ def test_cancel_job_non_empty_request_with_auto_populated_field():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
assert args[0] == storage_batch_operations.CancelJobRequest(
Expand Down Expand Up @@ -4139,7 +4140,7 @@ def test_create_job_rest_required_fields(request_type=storage_batch_operations.C
found_field = None
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
if key == "requestId":
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
assert _UUID4_RE.match(value)
found_field = i
break
if found_field is not None:
Expand Down Expand Up @@ -4318,7 +4319,7 @@ def test_delete_job_rest_required_fields(request_type=storage_batch_operations.D
found_field = None
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
if key == "requestId":
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
assert _UUID4_RE.match(value)
found_field = i
break
if found_field is not None:
Expand Down Expand Up @@ -4495,7 +4496,7 @@ def test_cancel_job_rest_required_fields(request_type=storage_batch_operations.C
found_field = None
for i, (key, value) in enumerate(req.call_args.kwargs['params']):
if key == "requestId":
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", value)
assert _UUID4_RE.match(value)
found_field = i
break
if found_field is not None:
Expand Down Expand Up @@ -5128,7 +5129,7 @@ def test_create_job_empty_call_grpc():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.CreateJobRequest()
Expand All @@ -5155,7 +5156,7 @@ def test_delete_job_empty_call_grpc():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.DeleteJobRequest()
Expand All @@ -5182,7 +5183,7 @@ def test_cancel_job_empty_call_grpc():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.CancelJobRequest()
Expand Down Expand Up @@ -5333,7 +5334,7 @@ async def test_create_job_empty_call_grpc_asyncio():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.CreateJobRequest()
Expand Down Expand Up @@ -5362,7 +5363,7 @@ async def test_delete_job_empty_call_grpc_asyncio():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.DeleteJobRequest()
Expand Down Expand Up @@ -5392,7 +5393,7 @@ async def test_cancel_job_empty_call_grpc_asyncio():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.CancelJobRequest()
Expand Down Expand Up @@ -6650,7 +6651,7 @@ def test_create_job_empty_call_rest():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.CreateJobRequest()
Expand All @@ -6676,7 +6677,7 @@ def test_delete_job_empty_call_rest():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.DeleteJobRequest()
Expand All @@ -6702,7 +6703,7 @@ def test_cancel_job_empty_call_rest():
call.assert_called()
_, args, _ = call.mock_calls[0]
# Ensure that the uuid4 field is set according to AIP 4235
assert re.match(r"[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", args[0].request_id)
assert _UUID4_RE.match(args[0].request_id)
# clear UUID field so that the check below succeeds
args[0].request_id = None
request_msg = storage_batch_operations.CancelJobRequest()
Expand Down