Skip to content

Commit 59f0761

Browse files
author
Taejun Lee
committed
Add ability to perform contains checks on BaseAPIJsonObject
1 parent baf536c commit 59f0761

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

boxsdk/object/base_api_json_object.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ def __getitem__(self, item):
9595
"""
9696
return self._response_object[item]
9797

98+
def __contains__(self, item):
99+
"""
100+
Does the response object contains this item attribute?
101+
102+
:param item:
103+
The attribute to check for in the API response object.
104+
:type item:
105+
`unicode`
106+
"""
107+
return item in self._response_object
108+
98109
def __repr__(self):
99110
"""Base class override. Return a human-readable representation using the Box ID or name of the object."""
100111
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
@@ -26,6 +26,13 @@ def test_getitem(base_api_json_object):
2626
assert test_object[key] == dictionary_response[key]
2727

2828

29+
def test_contains(base_api_json_object):
30+
dictionary_response, test_object = base_api_json_object
31+
for key in dictionary_response:
32+
assert key in test_object
33+
assert 'some_key_that_doesnt_exist' not in test_object
34+
35+
2936
def test_meta_registers_new_item_type_in_default_translator(default_translator, original_default_translator):
3037
item_type = u'ƒøø'
3138

0 commit comments

Comments
 (0)