Exemple #1
0
 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]
Exemple #2
0
 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'}]
Exemple #3
0
 def test_to_dicts_attr_error(self):
     obj = DummyModel({'foo': 'bar'})
     dicts = dutils.to_dicts([obj, {'a': 'b'}])
     assert dicts == [obj, {'a': 'b'}]
Exemple #4
0
 def test_to_dicts_regular_case(self):
     collection = [DummyModel({'foo': 'bar'})]
     dicts = dutils.to_dicts(collection)
     assert dicts == [{'foo': 'bar'}]
Exemple #5
0
 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]
Exemple #6
0
 def test_to_dicts_attr_error(self):
     obj = DummyModel({'foo': 'bar'})
     dicts = dutils.to_dicts([obj, {'a': 'b'}])
     assert dicts == [obj, {'a': 'b'}]
Exemple #7
0
 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'}]
Exemple #8
0
 def test_to_dicts_regular_case(self):
     collection = [DummyModel({'foo': 'bar'})]
     dicts = dutils.to_dicts(collection)
     assert dicts == [{'foo': 'bar'}]