

def circular_reference_deltas_2(self, DocClass1, DocClass2, dbref=True):

    class Person(DocClass1):
        name = StringField()
        owns = ListField(ReferenceField('Organization', dbref=dbref))
        employer = ReferenceField('Organization', dbref=dbref)

    class Organization(DocClass2):
        name = StringField()
        owner = ReferenceField('Person', dbref=dbref)
        employees = ListField(ReferenceField('Person', dbref=dbref))
    Person.drop_collection()
    Organization.drop_collection()
    person = Person(name='owner').save()
    employee = Person(name='employee').save()
    organization = Organization(name='company').save()
    person.owns.append(organization)
    organization.owner = person
    organization.employees.append(employee)
    employee.employer = organization
    person.save()
    organization.save()
    employee.save()
    p = Person.objects.get(name='owner')
    e = Person.objects.get(name='employee')
    o = Organization.objects.first()
    self.assertEqual(p.owns[0], o)
    self.assertEqual(o.owner, p)
    self.assertEqual(e.employer, o)
    return (person, organization, employee)

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