diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index dd98abbd..a934f1e0 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,5 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:08e34975760f002746b1d8c86fdc90660be45945ee6d9db914d1508acdf9a547 + digest: sha256:4f9b3b106ad0beafc2c8a415e3f62c1a0cc23cabea115dbe841b848f581cfe99 # created: 2023-10-09T14:06:13.397766266Z diff --git a/.kokoro/requirements.txt b/.kokoro/requirements.txt index 0332d326..16170d0c 100644 --- a/.kokoro/requirements.txt +++ b/.kokoro/requirements.txt @@ -467,9 +467,9 @@ typing-extensions==4.4.0 \ --hash=sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa \ --hash=sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e # via -r requirements.in -urllib3==1.26.17 \ - --hash=sha256:24d6a242c28d29af46c3fae832c36db3bbebcc533dd1bb549172cd739c82df21 \ - --hash=sha256:94a757d178c9be92ef5539b8840d48dc9cf1b2709c9d6b588232a055c524458b +urllib3==1.26.18 \ + --hash=sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07 \ + --hash=sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0 # via # requests # twine diff --git a/docs/index.rst b/docs/index.rst index 393c884c..1cfea1f3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,8 +8,8 @@ API Reference .. toctree:: :maxdepth: 2 - kms_v1/services - kms_v1/types + kms_v1/services_ + kms_v1/types_ Migration Guide diff --git a/docs/kms_v1/services.rst b/docs/kms_v1/services_.rst similarity index 100% rename from docs/kms_v1/services.rst rename to docs/kms_v1/services_.rst diff --git a/docs/kms_v1/types.rst b/docs/kms_v1/types_.rst similarity index 100% rename from docs/kms_v1/types.rst rename to docs/kms_v1/types_.rst diff --git a/tests/unit/gapic/kms_v1/test_ekm_service.py b/tests/unit/gapic/kms_v1/test_ekm_service.py index 5785b86f..046632b9 100644 --- a/tests/unit/gapic/kms_v1/test_ekm_service.py +++ b/tests/unit/gapic/kms_v1/test_ekm_service.py @@ -2722,8 +2722,9 @@ def test_list_ekm_connections_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.ListEkmConnectionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.ListEkmConnectionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -2808,8 +2809,9 @@ def test_list_ekm_connections_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.ListEkmConnectionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.ListEkmConnectionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -2944,8 +2946,9 @@ def test_list_ekm_connections_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.ListEkmConnectionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.ListEkmConnectionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3070,8 +3073,9 @@ def test_get_ekm_connection_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3152,8 +3156,9 @@ def test_get_ekm_connection_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3280,8 +3285,9 @@ def test_get_ekm_connection_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3364,6 +3370,73 @@ def test_create_ekm_connection_rest(request_type): "key_management_mode": 1, "crypto_space_path": "crypto_space_path_value", } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = ekm_service.CreateEkmConnectionRequest.meta.fields["ekm_connection"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["ekm_connection"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["ekm_connection"][field])): + del request_init["ekm_connection"][field][i][subfield] + else: + del request_init["ekm_connection"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -3379,8 +3452,9 @@ def test_create_ekm_connection_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3471,8 +3545,9 @@ def test_create_ekm_connection_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3575,36 +3650,6 @@ def test_create_ekm_connection_rest_bad_request( # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["ekm_connection"] = { - "name": "name_value", - "create_time": {"seconds": 751, "nanos": 543}, - "service_resolvers": [ - { - "service_directory_service": "service_directory_service_value", - "endpoint_filter": "endpoint_filter_value", - "hostname": "hostname_value", - "server_certificates": [ - { - "raw_der": b"raw_der_blob", - "parsed": True, - "issuer": "issuer_value", - "subject": "subject_value", - "subject_alternative_dns_names": [ - "subject_alternative_dns_names_value1", - "subject_alternative_dns_names_value2", - ], - "not_before_time": {}, - "not_after_time": {}, - "serial_number": "serial_number_value", - "sha256_fingerprint": "sha256_fingerprint_value", - } - ], - } - ], - "etag": "etag_value", - "key_management_mode": 1, - "crypto_space_path": "crypto_space_path_value", - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -3644,8 +3689,9 @@ def test_create_ekm_connection_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3734,6 +3780,73 @@ def test_update_ekm_connection_rest(request_type): "key_management_mode": 1, "crypto_space_path": "crypto_space_path_value", } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = ekm_service.UpdateEkmConnectionRequest.meta.fields["ekm_connection"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["ekm_connection"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["ekm_connection"][field])): + del request_init["ekm_connection"][field][i][subfield] + else: + del request_init["ekm_connection"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -3749,8 +3862,9 @@ def test_update_ekm_connection_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3829,8 +3943,9 @@ def test_update_ekm_connection_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -3930,36 +4045,6 @@ def test_update_ekm_connection_rest_bad_request( "name": "projects/sample1/locations/sample2/ekmConnections/sample3" } } - request_init["ekm_connection"] = { - "name": "projects/sample1/locations/sample2/ekmConnections/sample3", - "create_time": {"seconds": 751, "nanos": 543}, - "service_resolvers": [ - { - "service_directory_service": "service_directory_service_value", - "endpoint_filter": "endpoint_filter_value", - "hostname": "hostname_value", - "server_certificates": [ - { - "raw_der": b"raw_der_blob", - "parsed": True, - "issuer": "issuer_value", - "subject": "subject_value", - "subject_alternative_dns_names": [ - "subject_alternative_dns_names_value1", - "subject_alternative_dns_names_value2", - ], - "not_before_time": {}, - "not_after_time": {}, - "serial_number": "serial_number_value", - "sha256_fingerprint": "sha256_fingerprint_value", - } - ], - } - ], - "etag": "etag_value", - "key_management_mode": 1, - "crypto_space_path": "crypto_space_path_value", - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -4002,8 +4087,9 @@ def test_update_ekm_connection_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConnection.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConnection.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4070,8 +4156,9 @@ def test_get_ekm_config_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4147,8 +4234,9 @@ def test_get_ekm_config_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4273,8 +4361,9 @@ def test_get_ekm_config_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4332,6 +4421,73 @@ def test_update_ekm_config_rest(request_type): "name": "projects/sample1/locations/sample2/ekmConfig", "default_ekm_connection": "default_ekm_connection_value", } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = ekm_service.UpdateEkmConfigRequest.meta.fields["ekm_config"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["ekm_config"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["ekm_config"][field])): + del request_init["ekm_config"][field][i][subfield] + else: + del request_init["ekm_config"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -4345,8 +4501,9 @@ def test_update_ekm_config_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4420,8 +4577,9 @@ def test_update_ekm_config_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4519,10 +4677,6 @@ def test_update_ekm_config_rest_bad_request( request_init = { "ekm_config": {"name": "projects/sample1/locations/sample2/ekmConfig"} } - request_init["ekm_config"] = { - "name": "projects/sample1/locations/sample2/ekmConfig", - "default_ekm_connection": "default_ekm_connection_value", - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -4563,8 +4717,9 @@ def test_update_ekm_config_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.EkmConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.EkmConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4628,8 +4783,9 @@ def test_verify_connectivity_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.VerifyConnectivityResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.VerifyConnectivityResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4703,8 +4859,9 @@ def test_verify_connectivity_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.VerifyConnectivityResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.VerifyConnectivityResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -4831,8 +4988,9 @@ def test_verify_connectivity_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = ekm_service.VerifyConnectivityResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = ekm_service.VerifyConnectivityResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value diff --git a/tests/unit/gapic/kms_v1/test_key_management_service.py b/tests/unit/gapic/kms_v1/test_key_management_service.py index c1adba77..06fe60ef 100644 --- a/tests/unit/gapic/kms_v1/test_key_management_service.py +++ b/tests/unit/gapic/kms_v1/test_key_management_service.py @@ -8680,8 +8680,9 @@ def test_list_key_rings_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListKeyRingsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListKeyRingsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -8764,8 +8765,9 @@ def test_list_key_rings_rest_required_fields(request_type=service.ListKeyRingsRe response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListKeyRingsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListKeyRingsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -8898,8 +8900,9 @@ def test_list_key_rings_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListKeyRingsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListKeyRingsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9019,8 +9022,9 @@ def test_list_crypto_keys_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListCryptoKeysResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListCryptoKeysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9106,8 +9110,9 @@ def test_list_crypto_keys_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListCryptoKeysResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListCryptoKeysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9243,8 +9248,9 @@ def test_list_crypto_keys_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListCryptoKeysResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListCryptoKeysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9369,8 +9375,9 @@ def test_list_crypto_key_versions_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListCryptoKeyVersionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListCryptoKeyVersionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9456,8 +9463,9 @@ def test_list_crypto_key_versions_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListCryptoKeyVersionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListCryptoKeyVersionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9597,8 +9605,9 @@ def test_list_crypto_key_versions_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListCryptoKeyVersionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListCryptoKeyVersionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9723,8 +9732,9 @@ def test_list_import_jobs_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListImportJobsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListImportJobsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9809,8 +9819,9 @@ def test_list_import_jobs_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListImportJobsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListImportJobsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -9945,8 +9956,9 @@ def test_list_import_jobs_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.ListImportJobsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.ListImportJobsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10068,8 +10080,9 @@ def test_get_key_ring_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.KeyRing.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.KeyRing.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10142,8 +10155,9 @@ def test_get_key_ring_rest_required_fields(request_type=service.GetKeyRingReques response_value = Response() response_value.status_code = 200 - pb_return_value = resources.KeyRing.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.KeyRing.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10264,8 +10278,9 @@ def test_get_key_ring_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.KeyRing.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.KeyRing.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10334,8 +10349,9 @@ def test_get_crypto_key_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10411,8 +10427,9 @@ def test_get_crypto_key_rest_required_fields(request_type=service.GetCryptoKeyRe response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10537,8 +10554,9 @@ def test_get_crypto_key_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10613,8 +10631,9 @@ def test_get_crypto_key_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10706,8 +10725,9 @@ def test_get_crypto_key_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10836,8 +10856,9 @@ def test_get_crypto_key_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10907,8 +10928,9 @@ def test_get_public_key_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.PublicKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.PublicKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -10987,8 +11009,9 @@ def test_get_public_key_rest_required_fields(request_type=service.GetPublicKeyRe response_value = Response() response_value.status_code = 200 - pb_return_value = resources.PublicKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.PublicKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11113,8 +11136,9 @@ def test_get_public_key_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.PublicKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.PublicKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11184,8 +11208,9 @@ def test_get_import_job_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.ImportJob.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.ImportJob.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11264,8 +11289,9 @@ def test_get_import_job_rest_required_fields(request_type=service.GetImportJobRe response_value = Response() response_value.status_code = 200 - pb_return_value = resources.ImportJob.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.ImportJob.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11390,8 +11416,9 @@ def test_get_import_job_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.ImportJob.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.ImportJob.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11448,6 +11475,73 @@ def test_create_key_ring_rest(request_type): "name": "name_value", "create_time": {"seconds": 751, "nanos": 543}, } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateKeyRingRequest.meta.fields["key_ring"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["key_ring"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["key_ring"][field])): + del request_init["key_ring"][field][i][subfield] + else: + del request_init["key_ring"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -11460,8 +11554,9 @@ def test_create_key_ring_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.KeyRing.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.KeyRing.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11546,8 +11641,9 @@ def test_create_key_ring_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.KeyRing.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.KeyRing.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11646,10 +11742,6 @@ def test_create_key_ring_rest_bad_request( # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2"} - request_init["key_ring"] = { - "name": "name_value", - "create_time": {"seconds": 751, "nanos": 543}, - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -11689,8 +11781,9 @@ def test_create_key_ring_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.KeyRing.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.KeyRing.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11791,6 +11884,73 @@ def test_create_crypto_key_rest(request_type): "destroy_scheduled_duration": {}, "crypto_key_backend": "crypto_key_backend_value", } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateCryptoKeyRequest.meta.fields["crypto_key"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["crypto_key"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["crypto_key"][field])): + del request_init["crypto_key"][field][i][subfield] + else: + del request_init["crypto_key"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -11806,8 +11966,9 @@ def test_create_crypto_key_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -11900,8 +12061,9 @@ def test_create_crypto_key_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12005,53 +12167,6 @@ def test_create_crypto_key_rest_bad_request( # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2/keyRings/sample3"} - request_init["crypto_key"] = { - "name": "name_value", - "primary": { - "name": "name_value", - "state": 5, - "protection_level": 1, - "algorithm": 1, - "attestation": { - "format": 3, - "content": b"content_blob", - "cert_chains": { - "cavium_certs": ["cavium_certs_value1", "cavium_certs_value2"], - "google_card_certs": [ - "google_card_certs_value1", - "google_card_certs_value2", - ], - "google_partition_certs": [ - "google_partition_certs_value1", - "google_partition_certs_value2", - ], - }, - }, - "create_time": {"seconds": 751, "nanos": 543}, - "generate_time": {}, - "destroy_time": {}, - "destroy_event_time": {}, - "import_job": "import_job_value", - "import_time": {}, - "import_failure_reason": "import_failure_reason_value", - "generation_failure_reason": "generation_failure_reason_value", - "external_destruction_failure_reason": "external_destruction_failure_reason_value", - "external_protection_level_options": { - "external_key_uri": "external_key_uri_value", - "ekm_connection_key_path": "ekm_connection_key_path_value", - }, - "reimport_eligible": True, - }, - "purpose": 1, - "create_time": {}, - "next_rotation_time": {}, - "rotation_period": {"seconds": 751, "nanos": 543}, - "version_template": {"protection_level": 1, "algorithm": 1}, - "labels": {}, - "import_only": True, - "destroy_scheduled_duration": {}, - "crypto_key_backend": "crypto_key_backend_value", - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -12093,8 +12208,9 @@ def test_create_crypto_key_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12186,6 +12302,73 @@ def test_create_crypto_key_version_rest(request_type): }, "reimport_eligible": True, } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateCryptoKeyVersionRequest.meta.fields["crypto_key_version"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["crypto_key_version"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["crypto_key_version"][field])): + del request_init["crypto_key_version"][field][i][subfield] + else: + del request_init["crypto_key_version"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -12206,8 +12389,9 @@ def test_create_crypto_key_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12300,8 +12484,9 @@ def test_create_crypto_key_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12399,41 +12584,6 @@ def test_create_crypto_key_version_rest_bad_request( request_init = { "parent": "projects/sample1/locations/sample2/keyRings/sample3/cryptoKeys/sample4" } - request_init["crypto_key_version"] = { - "name": "name_value", - "state": 5, - "protection_level": 1, - "algorithm": 1, - "attestation": { - "format": 3, - "content": b"content_blob", - "cert_chains": { - "cavium_certs": ["cavium_certs_value1", "cavium_certs_value2"], - "google_card_certs": [ - "google_card_certs_value1", - "google_card_certs_value2", - ], - "google_partition_certs": [ - "google_partition_certs_value1", - "google_partition_certs_value2", - ], - }, - }, - "create_time": {"seconds": 751, "nanos": 543}, - "generate_time": {}, - "destroy_time": {}, - "destroy_event_time": {}, - "import_job": "import_job_value", - "import_time": {}, - "import_failure_reason": "import_failure_reason_value", - "generation_failure_reason": "generation_failure_reason_value", - "external_destruction_failure_reason": "external_destruction_failure_reason_value", - "external_protection_level_options": { - "external_key_uri": "external_key_uri_value", - "ekm_connection_key_path": "ekm_connection_key_path_value", - }, - "reimport_eligible": True, - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -12474,8 +12624,9 @@ def test_create_crypto_key_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12551,8 +12702,9 @@ def test_import_crypto_key_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12649,8 +12801,9 @@ def test_import_crypto_key_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12810,6 +12963,73 @@ def test_create_import_job_rest(request_type): }, }, } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.CreateImportJobRequest.meta.fields["import_job"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["import_job"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["import_job"][field])): + del request_init["import_job"][field][i][subfield] + else: + del request_init["import_job"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -12825,8 +13045,9 @@ def test_create_import_job_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.ImportJob.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.ImportJob.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -12917,8 +13138,9 @@ def test_create_import_job_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.ImportJob.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.ImportJob.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13017,32 +13239,6 @@ def test_create_import_job_rest_bad_request( # send a request that will satisfy transcoding request_init = {"parent": "projects/sample1/locations/sample2/keyRings/sample3"} - request_init["import_job"] = { - "name": "name_value", - "import_method": 1, - "protection_level": 1, - "create_time": {"seconds": 751, "nanos": 543}, - "generate_time": {}, - "expire_time": {}, - "expire_event_time": {}, - "state": 1, - "public_key": {"pem": "pem_value"}, - "attestation": { - "format": 3, - "content": b"content_blob", - "cert_chains": { - "cavium_certs": ["cavium_certs_value1", "cavium_certs_value2"], - "google_card_certs": [ - "google_card_certs_value1", - "google_card_certs_value2", - ], - "google_partition_certs": [ - "google_partition_certs_value1", - "google_partition_certs_value2", - ], - }, - }, - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13084,8 +13280,9 @@ def test_create_import_job_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.ImportJob.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.ImportJob.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13191,6 +13388,73 @@ def test_update_crypto_key_rest(request_type): "destroy_scheduled_duration": {}, "crypto_key_backend": "crypto_key_backend_value", } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.UpdateCryptoKeyRequest.meta.fields["crypto_key"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["crypto_key"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["crypto_key"][field])): + del request_init["crypto_key"][field][i][subfield] + else: + del request_init["crypto_key"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -13206,8 +13470,9 @@ def test_update_crypto_key_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13283,8 +13548,9 @@ def test_update_crypto_key_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13380,53 +13646,6 @@ def test_update_crypto_key_rest_bad_request( "name": "projects/sample1/locations/sample2/keyRings/sample3/cryptoKeys/sample4" } } - request_init["crypto_key"] = { - "name": "projects/sample1/locations/sample2/keyRings/sample3/cryptoKeys/sample4", - "primary": { - "name": "name_value", - "state": 5, - "protection_level": 1, - "algorithm": 1, - "attestation": { - "format": 3, - "content": b"content_blob", - "cert_chains": { - "cavium_certs": ["cavium_certs_value1", "cavium_certs_value2"], - "google_card_certs": [ - "google_card_certs_value1", - "google_card_certs_value2", - ], - "google_partition_certs": [ - "google_partition_certs_value1", - "google_partition_certs_value2", - ], - }, - }, - "create_time": {"seconds": 751, "nanos": 543}, - "generate_time": {}, - "destroy_time": {}, - "destroy_event_time": {}, - "import_job": "import_job_value", - "import_time": {}, - "import_failure_reason": "import_failure_reason_value", - "generation_failure_reason": "generation_failure_reason_value", - "external_destruction_failure_reason": "external_destruction_failure_reason_value", - "external_protection_level_options": { - "external_key_uri": "external_key_uri_value", - "ekm_connection_key_path": "ekm_connection_key_path_value", - }, - "reimport_eligible": True, - }, - "purpose": 1, - "create_time": {}, - "next_rotation_time": {}, - "rotation_period": {"seconds": 751, "nanos": 543}, - "version_template": {"protection_level": 1, "algorithm": 1}, - "labels": {}, - "import_only": True, - "destroy_scheduled_duration": {}, - "crypto_key_backend": "crypto_key_backend_value", - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13469,8 +13688,9 @@ def test_update_crypto_key_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13563,6 +13783,73 @@ def test_update_crypto_key_version_rest(request_type): }, "reimport_eligible": True, } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = service.UpdateCryptoKeyVersionRequest.meta.fields["crypto_key_version"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["crypto_key_version"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["crypto_key_version"][field])): + del request_init["crypto_key_version"][field][i][subfield] + else: + del request_init["crypto_key_version"][field][subfield] request = request_type(**request_init) # Mock the http request call within the method and fake a response. @@ -13583,8 +13870,9 @@ def test_update_crypto_key_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13674,8 +13962,9 @@ def test_update_crypto_key_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13775,41 +14064,6 @@ def test_update_crypto_key_version_rest_bad_request( "name": "projects/sample1/locations/sample2/keyRings/sample3/cryptoKeys/sample4/cryptoKeyVersions/sample5" } } - request_init["crypto_key_version"] = { - "name": "projects/sample1/locations/sample2/keyRings/sample3/cryptoKeys/sample4/cryptoKeyVersions/sample5", - "state": 5, - "protection_level": 1, - "algorithm": 1, - "attestation": { - "format": 3, - "content": b"content_blob", - "cert_chains": { - "cavium_certs": ["cavium_certs_value1", "cavium_certs_value2"], - "google_card_certs": [ - "google_card_certs_value1", - "google_card_certs_value2", - ], - "google_partition_certs": [ - "google_partition_certs_value1", - "google_partition_certs_value2", - ], - }, - }, - "create_time": {"seconds": 751, "nanos": 543}, - "generate_time": {}, - "destroy_time": {}, - "destroy_event_time": {}, - "import_job": "import_job_value", - "import_time": {}, - "import_failure_reason": "import_failure_reason_value", - "generation_failure_reason": "generation_failure_reason_value", - "external_destruction_failure_reason": "external_destruction_failure_reason_value", - "external_protection_level_options": { - "external_key_uri": "external_key_uri_value", - "ekm_connection_key_path": "ekm_connection_key_path_value", - }, - "reimport_eligible": True, - } request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. @@ -13852,8 +14106,9 @@ def test_update_crypto_key_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -13924,8 +14179,9 @@ def test_update_crypto_key_primary_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14008,8 +14264,9 @@ def test_update_crypto_key_primary_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14149,8 +14406,9 @@ def test_update_crypto_key_primary_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKey.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14228,8 +14486,9 @@ def test_destroy_crypto_key_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14322,8 +14581,9 @@ def test_destroy_crypto_key_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14453,8 +14713,9 @@ def test_destroy_crypto_key_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14529,8 +14790,9 @@ def test_restore_crypto_key_version_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14623,8 +14885,9 @@ def test_restore_crypto_key_version_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14754,8 +15017,9 @@ def test_restore_crypto_key_version_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = resources.CryptoKeyVersion.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = resources.CryptoKeyVersion.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14826,8 +15090,9 @@ def test_encrypt_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.EncryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.EncryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -14909,8 +15174,9 @@ def test_encrypt_rest_required_fields(request_type=service.EncryptRequest): response_value = Response() response_value.status_code = 200 - pb_return_value = service.EncryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.EncryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15046,8 +15312,9 @@ def test_encrypt_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.EncryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.EncryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15117,8 +15384,9 @@ def test_decrypt_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.DecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.DecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15198,8 +15466,9 @@ def test_decrypt_rest_required_fields(request_type=service.DecryptRequest): response_value = Response() response_value.status_code = 200 - pb_return_value = service.DecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.DecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15335,8 +15604,9 @@ def test_decrypt_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.DecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.DecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15411,8 +15681,9 @@ def test_raw_encrypt_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.RawEncryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.RawEncryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15497,8 +15768,9 @@ def test_raw_encrypt_rest_required_fields(request_type=service.RawEncryptRequest response_value = Response() response_value.status_code = 200 - pb_return_value = service.RawEncryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.RawEncryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15647,8 +15919,9 @@ def test_raw_decrypt_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.RawDecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.RawDecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15734,8 +16007,9 @@ def test_raw_decrypt_rest_required_fields(request_type=service.RawDecryptRequest response_value = Response() response_value.status_code = 200 - pb_return_value = service.RawDecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.RawDecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15885,8 +16159,9 @@ def test_asymmetric_sign_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.AsymmetricSignResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.AsymmetricSignResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -15966,8 +16241,9 @@ def test_asymmetric_sign_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = service.AsymmetricSignResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.AsymmetricSignResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16095,8 +16371,9 @@ def test_asymmetric_sign_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.AsymmetricSignResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.AsymmetricSignResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16166,8 +16443,9 @@ def test_asymmetric_decrypt_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.AsymmetricDecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.AsymmetricDecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16249,8 +16527,9 @@ def test_asymmetric_decrypt_rest_required_fields( response_value = Response() response_value.status_code = 200 - pb_return_value = service.AsymmetricDecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.AsymmetricDecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16388,8 +16667,9 @@ def test_asymmetric_decrypt_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.AsymmetricDecryptResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.AsymmetricDecryptResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16460,8 +16740,9 @@ def test_mac_sign_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.MacSignResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.MacSignResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16542,8 +16823,9 @@ def test_mac_sign_rest_required_fields(request_type=service.MacSignRequest): response_value = Response() response_value.status_code = 200 - pb_return_value = service.MacSignResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.MacSignResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16679,8 +16961,9 @@ def test_mac_sign_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.MacSignResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.MacSignResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16753,8 +17036,9 @@ def test_mac_verify_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.MacVerifyResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.MacVerifyResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16841,8 +17125,9 @@ def test_mac_verify_rest_required_fields(request_type=service.MacVerifyRequest): response_value = Response() response_value.status_code = 200 - pb_return_value = service.MacVerifyResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.MacVerifyResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -16980,8 +17265,9 @@ def test_mac_verify_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.MacVerifyResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.MacVerifyResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -17048,8 +17334,9 @@ def test_generate_random_bytes_rest(request_type): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.GenerateRandomBytesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.GenerateRandomBytesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value @@ -17166,8 +17453,9 @@ def test_generate_random_bytes_rest_flattened(): # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - pb_return_value = service.GenerateRandomBytesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) + # Convert return value to protobuf type + return_value = service.GenerateRandomBytesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value