MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_generic_reference_list

Method test_generic_reference_list

tests/fields/test_fields.py:1629–1657  ·  view source on GitHub ↗

Ensure that a ListField properly dereferences generic references.

(self)

Source from the content-addressed store, hash-verified

1627 assert isinstance(bm.bookmark_object, Link)
1628
1629 def test_generic_reference_list(self):
1630 """Ensure that a ListField properly dereferences generic references."""
1631
1632 class Link(Document):
1633 title = StringField()
1634
1635 class Post(Document):
1636 title = StringField()
1637
1638 class User(Document):
1639 bookmarks = ListField(GenericReferenceField())
1640
1641 Link.drop_collection()
1642 Post.drop_collection()
1643 User.drop_collection()
1644
1645 link_1 = Link(title="Pitchfork")
1646 link_1.save()
1647
1648 post_1 = Post(title="Behind the Scenes of the Pavement Reunion")
1649 post_1.save()
1650
1651 user = User(bookmarks=[post_1, link_1])
1652 user.save()
1653
1654 user = User.objects(bookmarks__all=[post_1, link_1]).first()
1655
1656 assert user.bookmarks[0] == post_1
1657 assert user.bookmarks[1] == link_1
1658
1659 def test_generic_reference_document_not_registered(self):
1660 """Ensure dereferencing out of the document registry throws a

Callers

nothing calls this directly

Calls 7

drop_collectionMethod · 0.80
LinkClass · 0.70
PostClass · 0.70
UserClass · 0.70
saveMethod · 0.45
firstMethod · 0.45
objectsMethod · 0.45

Tested by

no test coverage detected