def test_to_dicts_type_error(self): def key(d): raise TypeError() obj = DummyModel({'foo': 'bar'}) dicts = dutils.to_dicts([obj], key=key) assert dicts == [obj]
def test_to_dicts_with_key(self): collection = [DummyModel({'foo': 'bar', 'id': '1'})] dicts = dutils.to_dicts(collection, key=lambda d: {'super': d['foo']}) assert dicts == [{'super': 'bar'}]
def test_to_dicts_attr_error(self): obj = DummyModel({'foo': 'bar'}) dicts = dutils.to_dicts([obj, {'a': 'b'}]) assert dicts == [obj, {'a': 'b'}]
def test_to_dicts_regular_case(self): collection = [DummyModel({'foo': 'bar'})] dicts = dutils.to_dicts(collection) assert dicts == [{'foo': 'bar'}]