Ensure that a ListField properly dereferences generic references.
(self)
| 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 |