'Ensure that the MapField can handle complex declared types.'

def test_complex_mapfield(self):

    class SettingBase(EmbeddedDocument, ):
        meta = {'allow_inheritance': True}
    class StringSetting(SettingBase, ):
        value = StringField()
    class IntegerSetting(SettingBase, ):
        value = IntField()
    class Extensible(Document, ):
        mapping = MapField(EmbeddedDocumentField(SettingBase))
    Extensible.drop_collection()
    e = Extensible()
    e.mapping['somestring'] = StringSetting(value='foo')
    e.mapping['someint'] = IntegerSetting(value=42)
    e.save()
    e2 = Extensible.objects.get(id=e.id)
    self.assertTrue(isinstance(e2.mapping['somestring'], StringSetting))
    self.assertTrue(isinstance(e2.mapping['someint'], IntegerSetting))
    with self.assertRaises(ValidationError):
        e.mapping['someint'] = 123
        e.save()
