'Test deleting a dynamic field works'

def test_delete_dynamic_field(self):

    self.Person.drop_collection()
    p = self.Person()
    p.name = 'Dean'
    p.misc = 22
    p.save()
    p = self.Person.objects.get()
    p.misc = {'hello': 'world'}
    p.save()
    p = self.Person.objects.get()
    self.assertEqual(p.misc, {'hello': 'world'})
    collection = self.db[self.Person._get_collection_name()]
    obj = collection.find_one()
    self.assertEqual(sorted(obj.keys()), ['_cls', '_id', 'misc', 'name'])
    del p.misc
    p.save()
    p = self.Person.objects.get()
    self.assertFalse(hasattr(p, 'misc'))
    obj = collection.find_one()
    self.assertEqual(sorted(obj.keys()), ['_cls', '_id', 'name'])
