Skip to content

Commit

Permalink
Add test for invalid message decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
khtg authored and vilasj committed Mar 6, 2018
1 parent b11884f commit ac71613
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apitools/base/protorpclite/protojson_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Nested(messages.Message):

nested_value = messages.StringField(1)

class NestedDatetime(messages.Message):

nested_dt_value = message_types.DateTimeField(1)

a_string = messages.StringField(2)
an_integer = messages.IntegerField(3)
a_float = messages.FloatField(4)
Expand All @@ -63,6 +67,7 @@ class Nested(messages.Message):
a_repeated_datetime = message_types.DateTimeField(11, repeated=True)
a_custom = CustomField(12)
a_repeated_custom = CustomField(13, repeated=True)
a_nested_datetime = messages.MessageField(NestedDatetime, 14)


class ModuleInterfaceTest(test_util.ModuleInterfaceTest,
Expand Down Expand Up @@ -368,6 +373,16 @@ def testDecodeInvalidDateTime(self):
self.assertRaises(messages.DecodeError, protojson.decode_message,
MyMessage, '{"a_datetime": "invalid"}')

def testDecodeInvalidMessage(self):
encoded = """{
"a_nested_datetime": {
"nested_dt_value": "invalid"
}
}
"""
self.assertRaises(messages.DecodeError, protojson.decode_message,
MyMessage, encoded)

def testEncodeDateTime(self):
for datetime_string, datetime_vals in (
('2012-09-30T15:31:50.262000',
Expand Down

0 comments on commit ac71613

Please sign in to comment.