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

Method test_exclude

tests/queryset/test_field_list.py:244–274  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

242 BlogPost.drop_collection()
243
244 def test_exclude(self):
245 class User(EmbeddedDocument):
246 name = StringField()
247 email = StringField()
248
249 class Comment(EmbeddedDocument):
250 title = StringField()
251 text = StringField()
252
253 class BlogPost(Document):
254 content = StringField()
255 author = EmbeddedDocumentField(User)
256 comments = ListField(EmbeddedDocumentField(Comment))
257
258 BlogPost.drop_collection()
259
260 post = BlogPost(content="Had a good coffee today...")
261 post.author = User(name="Test User")
262 post.comments = [
263 Comment(title="I aggree", text="Great post!"),
264 Comment(title="Coffee", text="I hate coffee"),
265 ]
266 post.save()
267
268 obj = BlogPost.objects.exclude("author", "comments.text").get()
269 assert obj.author is None
270 assert obj.content == "Had a good coffee today..."
271 assert obj.comments[0].title == "I aggree"
272 assert obj.comments[0].text is None
273
274 BlogPost.drop_collection()
275
276 def test_exclude_only_combining(self):
277 class Attachment(EmbeddedDocument):

Callers

nothing calls this directly

Calls 7

drop_collectionMethod · 0.80
BlogPostClass · 0.70
UserClass · 0.70
CommentClass · 0.70
saveMethod · 0.45
getMethod · 0.45
excludeMethod · 0.45

Tested by

no test coverage detected