diff options
author | Luke Sneeringer <luke@sneeringer.com> | 2019-02-23 15:43:06 -0800 |
---|---|---|
committer | Christopher Wilcox <crwilcox@google.com> | 2019-02-23 15:43:06 -0800 |
commit | 47a5723ef5444dd5415149af47d89d0337ed7d04 (patch) | |
tree | 97241f2d026b447b6a8afcc2efb57d91295171a0 /tests/unit/test_protobuf_helpers.py | |
parent | d9c3be106967426c1214bba3e28a0c1a7e970a67 (diff) | |
download | python-api-core-47a5723ef5444dd5415149af47d89d0337ed7d04.tar.gz |
Add support to unwrap Anys into wrapped pb2 objects. (#7430)
This commit adds support for unwrapping wrapped
pb2 objects from Anys (needed for LRO support with
wrapping).
Diffstat (limited to 'tests/unit/test_protobuf_helpers.py')
-rw-r--r-- | tests/unit/test_protobuf_helpers.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/unit/test_protobuf_helpers.py b/tests/unit/test_protobuf_helpers.py index ec761a0..db97238 100644 --- a/tests/unit/test_protobuf_helpers.py +++ b/tests/unit/test_protobuf_helpers.py @@ -38,6 +38,29 @@ def test_from_any_pb_success(): assert in_message == out_message +def test_from_any_pb_wrapped_success(): + # Declare a message class conforming to wrapped messages. + class WrappedDate(object): + def __init__(self, **kwargs): + self._pb = date_pb2.Date(**kwargs) + + def __eq__(self, other): + return self._pb == other + + @classmethod + def pb(cls, msg): + return msg._pb + + # Run the same test as `test_from_any_pb_success`, but using the + # wrapped class. + in_message = date_pb2.Date(year=1990) + in_message_any = any_pb2.Any() + in_message_any.Pack(in_message) + out_message = protobuf_helpers.from_any_pb(WrappedDate, in_message_any) + + assert out_message == in_message + + def test_from_any_pb_failure(): in_message = any_pb2.Any() in_message.Pack(date_pb2.Date(year=1990)) |