

def test_delta_for_dynamic_documents(self):

    class Person(DynamicDocument):
        name = StringField()
        meta = {
            'allow_inheritance': True,
        }
    Person.drop_collection()
    p = Person(name='James', age=34)
    self.assertEqual(p._delta(), (SON([('_cls', 'Person'), ('name', 'James'), ('age', 34)]), {
        
    }))
    p.doc = 123
    del p.doc
    self.assertEqual(p._delta(), (SON([('_cls', 'Person'), ('name', 'James'), ('age', 34)]), {
        
    }))
    p = Person()
    p.name = 'Dean'
    p.age = 22
    p.save()
    p.age = 24
    self.assertEqual(p.age, 24)
    self.assertEqual(p._get_changed_fields(), ['age'])
    self.assertEqual(p._delta(), ({
        'age': 24,
    }, {
        
    }))
    p = Person.objects(age=22).get()
    p.age = 24
    self.assertEqual(p.age, 24)
    self.assertEqual(p._get_changed_fields(), ['age'])
    self.assertEqual(p._delta(), ({
        'age': 24,
    }, {
        
    }))
    p.save()
    self.assertEqual(1, Person.objects(age=24).count())

dataset/ETHPy150Open MongoEngine/mongoengine/tests/document/delta.py DeltaTest.test_delta_for_dynamic_documents/original