diff --git a/tests/test_iterator.py b/tests/test_iterator.py index 055db17..8d218d2 100644 --- a/tests/test_iterator.py +++ b/tests/test_iterator.py @@ -55,7 +55,10 @@ def iterator_response(httpserver): 'id': 'dummy_id_4', 'type': 'dummy_type', 'attributes': {'order': 0} - }] + }, { + 'id': 'dummy_id_5', + 'type': 'dummy_type', + 'error': {'code': 'NotFoundError', 'message': 'item not found.'}}] }) @@ -79,11 +82,16 @@ def test_next(httpserver, iterator_response): last = None for i, obj in enumerate(it): assert obj.id == f'dummy_id_{i+3}' + if obj.id == 'dummy_id_5': + assert obj.error['code'] == 'NotFoundError' + else: + assert obj.order == 0 + assert obj.error is None last = obj - assert last.id == 'dummy_id_4' - assert it._count == 4 - assert it._batch_cursor == 1 + assert last.id == 'dummy_id_5' + assert it._count == 5 + assert it._batch_cursor == 2 with pytest.raises(StopIteration): # there shouldn't be more available elements after the for loop @@ -141,9 +149,9 @@ async def test_anext(httpserver, iterator_response): last = obj i += 1 - assert last.id == 'dummy_id_4' - assert it._count == 4 - assert it._batch_cursor == 1 + assert last.id == 'dummy_id_5' + assert it._count == 5 + assert it._batch_cursor == 2 with pytest.raises(StopAsyncIteration): # there shouldn't be more available elements after the for loop diff --git a/vt/object.py b/vt/object.py index 247b80e..1429ace 100644 --- a/vt/object.py +++ b/vt/object.py @@ -105,6 +105,9 @@ def from_dict(cls, obj_dict): if 'relationships' in obj_dict: obj._relationships = obj_dict['relationships'] + if 'error' in obj_dict: + obj._error = obj_dict['error'] + return obj def __init__(self, obj_type, obj_id=None, obj_attributes=None): @@ -125,6 +128,7 @@ def __init__(self, obj_type, obj_id=None, obj_attributes=None): self._modified_attrs = [] self._modified_data = {} + self._error = None def __on_attr_change(self, attr): if hasattr(self, '_modified_attrs'): @@ -178,6 +182,10 @@ def relationships(self): return self._relationships return {} + @property + def error(self): + return self._error + def get(self, attr_name, default=None): """Returns an attribute by name. diff --git a/vt/version.py b/vt/version.py index 1139861..ef91994 100644 --- a/vt/version.py +++ b/vt/version.py @@ -1 +1 @@ -__version__ = '0.13.2' +__version__ = '0.14.0'