Skip to content

Commit

Permalink
Merge pull request #135 from przemekwitek/patch-1
Browse files Browse the repository at this point in the history
Fix 'IncludeFields' method.
  • Loading branch information
cherba29 authored Nov 2, 2016
2 parents ff4c9f0 + 529614a commit 58dfc18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions apitools/base/py/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ def _GetField(message, field_path):

def _SetField(dictblob, field_path, value):
for field in field_path[:-1]:
dictblob[field] = {}
dictblob = dictblob[field]
dictblob = dictblob.setdefault(field, {})
dictblob[field_path[-1]] = value


Expand Down
9 changes: 6 additions & 3 deletions apitools/base/py/encoding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,12 @@ def testNestedIncludeFields(self):
self.assertEqual(
'{"nested": {"nested": null}}',
encoding.MessageToJson(msg, include_fields=['nested.nested']))
self.assertEqual(
'{"nested": {"nested_list": []}}',
encoding.MessageToJson(msg, include_fields=['nested.nested_list']))
# When clearing 'nested.nested_list', its sibling ('nested.nested')
# should remain unaffected.
self.assertIn(
encoding.MessageToJson(msg, include_fields=['nested.nested_list']),
['{"nested": {"nested": {}, "nested_list": []}}',
'{"nested": {"nested_list": [], "nested": {}}}'])
self.assertEqual(
'{"nested": {"nested": {"additional_properties": []}}}',
encoding.MessageToJson(
Expand Down

0 comments on commit 58dfc18

Please sign in to comment.