'Ensure you can handle circular references'

def test_circular_reference(self):

    class Relation(EmbeddedDocument, ):
        name = StringField()
        person = ReferenceField('Person')
    class Person(Document, ):
        name = StringField()
        relations = ListField(EmbeddedDocumentField('Relation'))
        def __repr__(self):
            return ('<Person:    %s>' % self.name)
    Person.drop_collection()
    mother = Person(name='Mother')
    daughter = Person(name='Daughter')
    mother.save()
    daughter.save()
    daughter_rel = Relation(name='Daughter', person=daughter)
    mother.relations.append(daughter_rel)
    mother.save()
    mother_rel = Relation(name='Daughter', person=mother)
    self_rel = Relation(name='Self', person=daughter)
    daughter.relations.append(mother_rel)
    daughter.relations.append(self_rel)
    daughter.save()
    self.assertEqual('[<Person:    Mother>,    <Person:    Daughter>]', ('%s' % Person.objects()))
