Skip to content

Commit 668a2a1

Browse files
Test any to_dict (#63)
* Test any to_dict * Add test
1 parent d035288 commit 668a2a1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_any.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,33 @@ def test_any() -> None:
1111
new_any = Any().parse(bytes(any))
1212

1313
assert new_any.unpack() == person
14+
15+
16+
def test_any_to_dict() -> None:
17+
from tests.output_betterproto.any import Person
18+
from tests.output_betterproto.google.protobuf import Any
19+
20+
person = Person(first_name="John", last_name="Smith")
21+
22+
any = Any()
23+
24+
# TODO test with include defautl value
25+
assert any.to_dict() == {"@type": ""}
26+
27+
# Pack an object inside
28+
any.pack(person)
29+
30+
assert any.to_dict() == {
31+
"@type": "type.googleapis.com/any.Person",
32+
"firstName": "John",
33+
"lastName": "Smith",
34+
}
35+
36+
# Pack again in another Any
37+
any2 = Any()
38+
any2.pack(any)
39+
40+
assert any2.to_dict() == {
41+
"@type": "type.googleapis.com/google.protobuf.Any",
42+
"value": {"@type": "type.googleapis.com/any.Person", "firstName": "John", "lastName": "Smith"},
43+
}

0 commit comments

Comments
 (0)