From c3902a51007532eee94d8542e5e13b29cfe67e7b Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Wed, 8 Dec 2021 17:26:25 -0800 Subject: [PATCH 1/4] fix: syntax fix for required_fields struct in rest transport --- .../%name_%version/%sub/services/%service/transports/rest.py.j2 | 2 +- .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index 64aa67213b..a94ce42c53 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -170,7 +170,7 @@ class {{service.name}}RestTransport({{service.name}}Transport): {% if method.input.required_fields %} __{{ method.name | snake_case }}_required_fields_default_values = { {% for req_field in method.input.required_fields if req_field.is_primitive %} - "{{ req_field.name | camel_case }}" : {% if req_field.field_pb.default_value is string %}"{{req_field.field_pb.default_value }}"{% else %}{{ req_field.field_pb.default_value }}{% endif %}{# default is str #} + "{{ req_field.name | camel_case }}" : {% if req_field.field_pb.default_value is string %}"{{req_field.field_pb.default_value }}"{% else %}{{ req_field.field_pb.default_value }}{% endif %},{# default is str #} {% endfor %} } diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index b31ff4df9b..94218959a0 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -7,7 +7,9 @@ import mock import grpc from grpc.experimental import aio +{% if "rest" in opts.transport %} import json +{% endif %} import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule From b491210b37297d14d30e9127fef99a32c44fcedd Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Thu, 9 Dec 2021 10:27:23 -0800 Subject: [PATCH 2/4] Tweak the golden files --- .../asset/tests/unit/gapic/asset_v1/test_asset_service.py | 1 - .../tests/unit/gapic/credentials_v1/test_iam_credentials.py | 1 - .../tests/unit/gapic/logging_v2/test_config_service_v2.py | 1 - .../tests/unit/gapic/logging_v2/test_logging_service_v2.py | 1 - .../tests/unit/gapic/logging_v2/test_metrics_service_v2.py | 1 - .../goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py | 1 - 6 files changed, 6 deletions(-) diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 95115e9d14..8b0f15491d 100644 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -18,7 +18,6 @@ import grpc from grpc.experimental import aio -import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule diff --git a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py index 2bd38142f6..54bebbee75 100644 --- a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -18,7 +18,6 @@ import grpc from grpc.experimental import aio -import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index e8bd895fb8..f8c963c4af 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -18,7 +18,6 @@ import grpc from grpc.experimental import aio -import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 84911953c1..47cc2177ef 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -18,7 +18,6 @@ import grpc from grpc.experimental import aio -import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 9c97b20308..7d8951e95a 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -18,7 +18,6 @@ import grpc from grpc.experimental import aio -import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index 8e60bc092e..d6a487d8dc 100644 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -18,7 +18,6 @@ import grpc from grpc.experimental import aio -import json import math import pytest from proto.marshal.rules.dates import DurationRule, TimestampRule From d42ce50deb34daa22196e935fda35d5fb3546971 Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Thu, 9 Dec 2021 10:36:02 -0800 Subject: [PATCH 3/4] Yet more tweaking --- .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 4 +++- .../asset/tests/unit/gapic/asset_v1/test_asset_service.py | 1 - .../redis/tests/unit/gapic/redis_v1/test_cloud_redis.py | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 94218959a0..a2421219fc 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -42,8 +42,10 @@ from google.api_core import future from google.api_core import operation from google.api_core import operations_v1 from google.longrunning import operations_pb2 +{% if "rest" in opts.transport %} from google.protobuf import json_format -{% endif %} +{% endif %}{# rest transport #} +{% endif %}{# lro #} from google.api_core import gapic_v1 {% for method in service.methods.values() %} {% for ref_type in method.ref_types diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 8b0f15491d..d9e81815ec 100644 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -45,7 +45,6 @@ from google.oauth2 import service_account from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import json_format from google.protobuf import timestamp_pb2 # type: ignore from google.type import expr_pb2 # type: ignore import google.auth diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index d6a487d8dc..8bc3b3801a 100644 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -43,7 +43,6 @@ from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import json_format from google.protobuf import timestamp_pb2 # type: ignore import google.auth From e4c2d22580ef7dc53088c11498adb6847376003d Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Thu, 9 Dec 2021 13:31:29 -0800 Subject: [PATCH 4/4] More tweaks --- .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 1 - .../asset/tests/unit/gapic/asset_v1/test_asset_service.py | 1 - .../goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py | 1 - 3 files changed, 3 deletions(-) diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index a2421219fc..cd9a7c34f0 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -39,7 +39,6 @@ from google.api_core import grpc_helpers_async from google.api_core import path_template {% if service.has_lro %} from google.api_core import future -from google.api_core import operation from google.api_core import operations_v1 from google.longrunning import operations_pb2 {% if "rest" in opts.transport %} diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index d9e81815ec..ae6fd2a5e6 100644 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -29,7 +29,6 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index 8bc3b3801a..160dcfc35a 100644 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -29,7 +29,6 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async -from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template