gapic-generator-python
gapic-generator-python copied to clipboard
Generated unit tests fail when method signatures contain multiple nested fields
An RPC with the google.api.method_signature annotation indicates that an overload with a flattened method signature is desired where supported. The string contains comma-separated arguments, in order. If a field's name contains a period (.) character, this indicates a nested field
When there are multiple nested fields in the method signature, test*flattened unit tests fail with AssertionError. See the stack trace below from this build log in PR #1954 at commit b27c2d80f9b68c8baed1ccfe83474ad04d6759fc.
.......................F....................................... [100%]
=================================== FAILURES ===================================
___________________________ test_my_method_flattened ___________________________
def test_my_method_flattened():
client = MyServiceClient(
credentials=ga_credentials.AnonymousCredentials(),
)
# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
type(client.transport.my_method),
'__call__') as call:
# Designate an appropriate return value for the call.
call.return_value = test_flattened_value.MethodResponse()
# Call the method with a truthy value for each flattened field,
# using the keyword arguments to the method.
client.my_method(
parameter=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE),
items=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)],
some_message=test_flattened_value.MethodRequest.SomeNestedMessage(foo='foo_value'),
foo='foo_value',
bar='bar_value',
)
# Establish that the underlying call was made with the expected
# request object values.
assert len(call.mock_calls) == 1
_, args, _ = call.mock_calls[0]
arg = args[0].parameter
mock_val = struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)
from proto.marshal import Marshal
from proto.marshal.rules.struct import ValueRule
rule = ValueRule(marshal=Marshal(name="Test"))
mock_val = rule.to_python(mock_val)
assert arg == mock_val
arg = args[0].items
mock_val = [struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)]
assert arg == mock_val
arg = args[0].some_message
mock_val = test_flattened_value.MethodRequest.SomeNestedMessage(foo='foo_value')
> assert arg == mock_val
E assert foo: "foo_value"\nbar: "bar_value"\n == foo: "foo_value"\n
/tmp/tmp3su_4fjt/tests/unit/gapic/fragment/test_my_service.py:536: AssertionError
See b/326213033 and cl/606967264 where the issue was discovered
Bumping to p3 as we don't currently have any APIs that are blocked on https://github.com/googleapis/gapic-generator-python/issues/1955