'Ensure that the list fields can handle the complex types.'

def test_list_field_complex(self):

    class SettingBase(EmbeddedDocument, ):
        meta = {'allow_inheritance': True}
    class StringSetting(SettingBase, ):
        value = StringField()
    class IntegerSetting(SettingBase, ):
        value = IntField()
    class Simple(Document, ):
        mapping = ListField()
    Simple.drop_collection()
    e = Simple()
    e.mapping.append(StringSetting(value='foo'))
    e.mapping.append(IntegerSetting(value=42))
    e.mapping.append({'number': 1, 'string': 'Hi!', 'float': 1.001, 'complex': IntegerSetting(value=42), 'list': [IntegerSetting(value=42), StringSetting(value='foo')]})
    e.save()
    e2 = Simple.objects.get(id=e.id)
    self.assertTrue(isinstance(e2.mapping[0], StringSetting))
    self.assertTrue(isinstance(e2.mapping[1], IntegerSetting))
    self.assertEqual(Simple.objects.filter(mapping__1__value=42).count(), 1)
    self.assertEqual(Simple.objects.filter(mapping__2__number=1).count(), 1)
    self.assertEqual(Simple.objects.filter(mapping__2__complex__value=42).count(), 1)
    self.assertEqual(Simple.objects.filter(mapping__2__list__0__value=42).count(), 1)
    self.assertEqual(Simple.objects.filter(mapping__2__list__1__value='foo').count(), 1)
    Simple.objects().update(set__mapping__1=IntegerSetting(value=10))
    self.assertEqual(Simple.objects.filter(mapping__1__value=10).count(), 1)
    Simple.objects().update(set__mapping__2__list__1=StringSetting(value='Boo'))
    self.assertEqual(Simple.objects.filter(mapping__2__list__1__value='foo').count(), 0)
    self.assertEqual(Simple.objects.filter(mapping__2__list__1__value='Boo').count(), 1)
