'Ensure a DictField can handle another document\'s dump.'

def test_dictfield_dump_document(self):

    class Doc(Document, ):
        field = DictField()
    class ToEmbed(Document, ):
        id = IntField(primary_key=True, default=1)
        recursive = DictField()
    class ToEmbedParent(Document, ):
        id = IntField(primary_key=True, default=1)
        recursive = DictField()
        meta = {'allow_inheritance': True}
    class ToEmbedChild(ToEmbedParent, ):
        pass
    to_embed_recursive = ToEmbed(id=1).save()
    to_embed = ToEmbed(id=2, recursive=to_embed_recursive.to_mongo().to_dict()).save()
    doc = Doc(field=to_embed.to_mongo().to_dict())
    doc.save()
    assert isinstance(doc.field, dict)
    assert (doc.field == {'_id': 2, 'recursive': {'_id': 1, 'recursive': {}}})
    to_embed_recursive = ToEmbedChild(id=1).save()
    to_embed_child = ToEmbedChild(id=2, recursive=to_embed_recursive.to_mongo().to_dict()).save()
    doc = Doc(field=to_embed_child.to_mongo().to_dict())
    doc.save()
    assert isinstance(doc.field, dict)
    assert (doc.field == {'_id': 2, '_cls': 'ToEmbedParent.ToEmbedChild', 'recursive': {'_id': 1, '_cls': 'ToEmbedParent.ToEmbedChild', 'recursive': {}}})
