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

Method test_no_dereference

tests/queryset/test_queryset.py:5310–5333  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5308 assert result == {"_id": user.id, "name": "User", "age": 50}
5309
5310 def test_no_dereference(self):
5311 class Organization(Document):
5312 name = StringField()
5313
5314 class User(Document):
5315 name = StringField()
5316 organization = ReferenceField(Organization)
5317
5318 User.drop_collection()
5319 Organization.drop_collection()
5320
5321 whitehouse = Organization(name="White House").save()
5322 User(name="Bob Dole", organization=whitehouse).save()
5323
5324 qs = User.objects()
5325 qs_user = qs.first()
5326
5327 assert isinstance(qs.first().organization, Organization)
5328
5329 user = qs.no_dereference().first()
5330 assert isinstance(user.organization, DBRef)
5331
5332 assert isinstance(qs_user.organization, Organization)
5333 assert isinstance(qs.first().organization, Organization)
5334
5335 def test_no_dereference_internals(self):
5336 # Test the internals on which queryset.no_dereference relies on

Callers

nothing calls this directly

Calls 7

drop_collectionMethod · 0.80
no_dereferenceMethod · 0.80
OrganizationClass · 0.70
UserClass · 0.70
saveMethod · 0.45
objectsMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected