MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / test_circular_tree_reference

Method test_circular_tree_reference

tests/test_dereference.py:424–463  ·  view source on GitHub ↗

Ensure you can handle circular references with more than one level

(self)

Source from the content-addressed store, hash-verified

422 assert "[<Person: Mother>, <Person: Daughter>]" == "%s" % Person.objects()
423
424 def test_circular_tree_reference(self):
425 """Ensure you can handle circular references with more than one level"""
426
427 class Other(EmbeddedDocument):
428 name = StringField()
429 friends = ListField(ReferenceField("Person"))
430
431 class Person(Document):
432 name = StringField()
433 other = EmbeddedDocumentField(Other, default=lambda: Other())
434
435 def __repr__(self):
436 return "<Person: %s>" % self.name
437
438 Person.drop_collection()
439 paul = Person(name="Paul").save()
440 maria = Person(name="Maria").save()
441 julia = Person(name="Julia").save()
442 anna = Person(name="Anna").save()
443
444 paul.other.friends = [maria, julia, anna]
445 paul.other.name = "Paul's friends"
446 paul.save()
447
448 maria.other.friends = [paul, julia, anna]
449 maria.other.name = "Maria's friends"
450 maria.save()
451
452 julia.other.friends = [paul, maria, anna]
453 julia.other.name = "Julia's friends"
454 julia.save()
455
456 anna.other.friends = [paul, maria, julia]
457 anna.other.name = "Anna's friends"
458 anna.save()
459
460 assert (
461 "[<Person: Paul>, <Person: Maria>, <Person: Julia>, <Person: Anna>]"
462 == "%s" % Person.objects()
463 )
464
465 def test_generic_reference(self):
466 class UserA(Document):

Callers

nothing calls this directly

Calls 4

drop_collectionMethod · 0.80
PersonClass · 0.70
saveMethod · 0.45
objectsMethod · 0.45

Tested by

no test coverage detected