Added test for listfields containing embedded documents

Added Adam to the authors - thanks for the patch
fixes #466
This commit is contained in:
Ross Lawley 2012-03-22 15:44:22 +00:00
parent 3b5b715567
commit 0f420abc8e
2 changed files with 32 additions and 0 deletions

View File

@ -98,3 +98,4 @@ that much better:
* Chris Williams
* Robert Kajic
* Jacob Peddicord
* Adam Parrish

View File

@ -1518,6 +1518,37 @@ class QuerySetTest(unittest.TestCase):
BlogPost.drop_collection()
def test_set_list_embedded_documents(self):
class Author(EmbeddedDocument):
name = StringField()
class Message(Document):
title = StringField()
authors = ListField(EmbeddedDocumentField('Author'))
Message.drop_collection()
message = Message(title="hello", authors=[Author(name="Harry")])
message.save()
Message.objects(authors__name="Harry").update_one(
set__authors__S=Author(name="Ross"))
message = message.reload()
self.assertEquals(message.authors[0].name, "Ross")
Message.objects(authors__name="Ross").update_one(
set__authors=[Author(name="Harry"),
Author(name="Ross"),
Author(name="Adam")])
message = message.reload()
self.assertEquals(message.authors[0].name, "Harry")
self.assertEquals(message.authors[1].name, "Ross")
self.assertEquals(message.authors[2].name, "Adam")
def test_order_by(self):
"""Ensure that QuerySets may be ordered.
"""