Skip to content

Commit 3d23b11

Browse files
author
Taejun Lee
committed
Also define __iter__ for BaseAPIJsonObject
1 parent 59f0761 commit 3d23b11

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

boxsdk/object/base_api_json_object.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ def __contains__(self, item):
106106
"""
107107
return item in self._response_object
108108

109+
def __iter__(self):
110+
"""
111+
Get all of the keys of the API response object.
112+
"""
113+
return iter(self._response_object)
114+
109115
def __repr__(self):
110116
"""Base class override. Return a human-readable representation using the Box ID or name of the object."""
111117
extra_description = ' - {0}'.format(self._description) if self._description else ''

test/unit/object/test_base_api_json_object.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def test_contains(base_api_json_object):
3333
assert 'some_key_that_doesnt_exist' not in test_object
3434

3535

36+
def test_iter(base_api_json_object):
37+
dictionary_response, test_object = base_api_json_object
38+
all_test_object_keys = [key for key in test_object]
39+
all_dictionary_response_keys = [key for key in dictionary_response]
40+
assert set(all_test_object_keys) == set(all_dictionary_response_keys)
41+
42+
3643
def test_meta_registers_new_item_type_in_default_translator(default_translator, original_default_translator):
3744
item_type = u'ƒøø'
3845

0 commit comments

Comments
 (0)