Update Tests for EmbeddedDocument Unique Indicies

This commit is contained in:
Matthew Ellison 2014-11-20 11:20:04 -05:00
parent bc53dd6830
commit 43af9f3fad
3 changed files with 18 additions and 17 deletions

View File

@ -1974,14 +1974,14 @@ class FieldTest(unittest.TestCase):
def test_recursive_embedding(self): def test_recursive_embedding(self):
"""Ensure that EmbeddedDocumentFields can contain their own documents. """Ensure that EmbeddedDocumentFields can contain their own documents.
""" """
class Tree(Document):
name = StringField()
children = ListField(EmbeddedDocumentField('TreeNode'))
class TreeNode(EmbeddedDocument): class TreeNode(EmbeddedDocument):
name = StringField() name = StringField()
children = ListField(EmbeddedDocumentField('self')) children = ListField(EmbeddedDocumentField('self'))
class Tree(Document):
name = StringField()
children = ListField(EmbeddedDocumentField('TreeNode'))
Tree.drop_collection() Tree.drop_collection()
tree = Tree(name="Tree") tree = Tree(name="Tree")

View File

@ -512,16 +512,16 @@ class QuerySetTest(unittest.TestCase):
def test_updates_can_have_match_operators(self): def test_updates_can_have_match_operators(self):
class Post(Document):
title = StringField(required=True)
tags = ListField(StringField())
comments = ListField(EmbeddedDocumentField("Comment"))
class Comment(EmbeddedDocument): class Comment(EmbeddedDocument):
content = StringField() content = StringField()
name = StringField(max_length=120) name = StringField(max_length=120)
vote = IntField() vote = IntField()
class Post(Document):
title = StringField(required=True)
tags = ListField(StringField())
comments = ListField(EmbeddedDocumentField("Comment"))
Post.drop_collection() Post.drop_collection()
comm1 = Comment(content="very funny indeed", name="John S", vote=1) comm1 = Comment(content="very funny indeed", name="John S", vote=1)

View File

@ -318,6 +318,10 @@ class FieldTest(unittest.TestCase):
def test_circular_reference(self): def test_circular_reference(self):
"""Ensure you can handle circular references """Ensure you can handle circular references
""" """
class Relation(EmbeddedDocument):
name = StringField()
person = ReferenceField('Person')
class Person(Document): class Person(Document):
name = StringField() name = StringField()
relations = ListField(EmbeddedDocumentField('Relation')) relations = ListField(EmbeddedDocumentField('Relation'))
@ -325,10 +329,6 @@ class FieldTest(unittest.TestCase):
def __repr__(self): def __repr__(self):
return "<Person: %s>" % self.name return "<Person: %s>" % self.name
class Relation(EmbeddedDocument):
name = StringField()
person = ReferenceField('Person')
Person.drop_collection() Person.drop_collection()
mother = Person(name="Mother") mother = Person(name="Mother")
daughter = Person(name="Daughter") daughter = Person(name="Daughter")
@ -1220,14 +1220,15 @@ class FieldTest(unittest.TestCase):
self.assertEqual(page.tags[0], page.posts[0].tags[0]) self.assertEqual(page.tags[0], page.posts[0].tags[0])
def test_select_related_follows_embedded_referencefields(self): def test_select_related_follows_embedded_referencefields(self):
class Playlist(Document):
items = ListField(EmbeddedDocumentField("PlaylistItem")) class Song(Document):
title = StringField()
class PlaylistItem(EmbeddedDocument): class PlaylistItem(EmbeddedDocument):
song = ReferenceField("Song") song = ReferenceField("Song")
class Song(Document): class Playlist(Document):
title = StringField() items = ListField(EmbeddedDocumentField("PlaylistItem"))
Playlist.drop_collection() Playlist.drop_collection()
Song.drop_collection() Song.drop_collection()