1010 ValidationError ,
1111)
1212from mongoengine .base import _DocumentRegistry
13- from tests .utils import MongoDBTestCase
13+ from tests .utils import MongoDBTestCase , get_as_pymongo
1414
1515
1616class TestField (MongoDBTestCase ):
1717
18- def test_generic_reference (self ):
18+ def test_generic_reference_field_basics (self ):
1919 """Ensure that a GenericReferenceField properly dereferences items."""
2020
2121 class Link (Document ):
@@ -42,14 +42,27 @@ class Bookmark(Document):
4242 bm .save ()
4343
4444 bm = Bookmark .objects (bookmark_object = post_1 ).first ()
45-
45+ assert get_as_pymongo (bm ) == {
46+ "_id" : bm .id ,
47+ "bookmark_object" : {
48+ "_cls" : "Post" ,
49+ "_ref" : post_1 .to_dbref (),
50+ },
51+ }
4652 assert bm .bookmark_object == post_1
4753 assert isinstance (bm .bookmark_object , Post )
4854
4955 bm .bookmark_object = link_1
5056 bm .save ()
5157
5258 bm = Bookmark .objects (bookmark_object = link_1 ).first ()
59+ assert get_as_pymongo (bm ) == {
60+ "_id" : bm .id ,
61+ "bookmark_object" : {
62+ "_cls" : "Link" ,
63+ "_ref" : link_1 .to_dbref (),
64+ },
65+ }
5366
5467 assert bm .bookmark_object == link_1
5568 assert isinstance (bm .bookmark_object , Link )
@@ -67,14 +80,6 @@ class OtherObj(Document):
6780 s1 = SomeObj ().save ()
6881 OtherObj (obj = s1 ).save ()
6982
70- assert OtherObj .objects .as_pymongo ().first () == {
71- "_id" : OtherObj .objects .first ().id ,
72- "obj" : {
73- "_cls" : "SomeObj" ,
74- "_ref" : s1 .to_dbref (),
75- },
76- }
77-
7883 # Query using to_dbref
7984 assert OtherObj .objects (obj__in = [s1 .to_dbref ()]).count () == 1
8085
0 commit comments