def resolve_with_non_iterable(self): field = List(Any) resolved_with = field.resolve(5) self.assertIsInstance(resolved_with, list) self.assertIn(5, resolved_with) self.assertEqual(1, resolved_with)
def test_resolve_map_objects_with_object_list(self): class TestMap(MapObject): test_field_1 = Any() field = List(TestMap) test_nested_list = [ TestMap(test_field_1=1), TestMap(test_field_1=2), TestMap(test_field_1=3), ] self.assertEqual(test_nested_list, field.resolve(test_nested_list))
class NestedMap(MapObject): test_field_1 = Any(default='test_default_1') test_field_2 = Any(param='test_param_2', required=True) test_field_3 = Any(param='test_param_3', default='test_default_3') test_field_4 = List(Any) test_double_nested = Nested(DoubleNested) def resolve_test_field_2(self, value, parameters): # resolvers should have access to other fields return self.test_field_1 def resolve_test_field_4(self, value, parameters): return [ 'list_item_1', 'list_item_2', 'list_item_3', ]
class NestedMap(MapObject): test_field_1 = Any(default='test_default_1') test_field_2 = Any( param='test_param_2', verbose_name='verbose_test_field_2_name' ) test_field_3 = Any(param='test_param_3', default='test_default_3') test_field_4 = List(Any) test_double_nested = Nested(DoubleNested) def resolve_test_field_2(self, value, parameters): # resolvers should have access to other fields return self.test_field_1 def resolve_test_field_3(self, value, parameters): return parameters.get('test_param_3') + '_the_resolver' def resolve_test_field_4(self, value, parameters): return [ 'list_item_1', 'list_item_2', 'list_item_3', ]
class TestMap(MapObject): nested_list = List(NestedListItem, param='nested_list_param')
class TestMap(MapObject): nested_list = List(NestedListItem)
def test_resolve_to_default(self): field = List(Any, default=[]) self.assertEqual(field.resolve(None), [])
def test_resolve_with_none(self): field = List(Any) self.assertIsNone(field.resolve(None))
def test_resolve_scalars_identity(self): field = List(Any) test_scalar_list = [1, 2, 3, 4, 5, 6, 'test_value'] self.assertEqual(test_scalar_list, field.resolve(test_scalar_list))