

def test_upper_level_mark_as_changed(self):

    class EmbeddedDoc(EmbeddedDocument):
        name = StringField()

    class MyDoc(Document):
        subs = MapField(EmbeddedDocumentField(EmbeddedDoc))
    MyDoc.drop_collection()
    MyDoc(subs={
        'a': EmbeddedDoc(name='foo'),
    }).save()
    mydoc = MyDoc.objects.first()
    subdoc = mydoc.subs['a']
    subdoc.name = 'bar'
    self.assertEqual(['name'], subdoc._get_changed_fields())
    self.assertEqual(['subs.a.name'], mydoc._get_changed_fields())
    mydoc.subs['a'] = EmbeddedDoc()
    self.assertEqual(['subs.a'], mydoc._get_changed_fields())
    mydoc.save()
    mydoc._clear_changed_fields()
    mydoc.assertEqual([], mydoc._get_changed_fields())

dataset/ETHPy150Open MongoEngine/mongoengine/tests/document/delta.py DeltaTest.test_upper_level_mark_as_changed/VarMisuse@168/239 `self`->`mydoc`