Added test for list of referencefields
This commit is contained in:
parent
fb4c4e3e08
commit
f666141981
@ -189,6 +189,9 @@ class FieldTest(unittest.TestCase):
|
|||||||
def test_list_validation(self):
|
def test_list_validation(self):
|
||||||
"""Ensure that a list field only accepts lists with valid elements.
|
"""Ensure that a list field only accepts lists with valid elements.
|
||||||
"""
|
"""
|
||||||
|
class User(Document):
|
||||||
|
pass
|
||||||
|
|
||||||
class Comment(EmbeddedDocument):
|
class Comment(EmbeddedDocument):
|
||||||
content = StringField()
|
content = StringField()
|
||||||
|
|
||||||
@ -196,6 +199,7 @@ class FieldTest(unittest.TestCase):
|
|||||||
content = StringField()
|
content = StringField()
|
||||||
comments = ListField(EmbeddedDocumentField(Comment))
|
comments = ListField(EmbeddedDocumentField(Comment))
|
||||||
tags = ListField(StringField())
|
tags = ListField(StringField())
|
||||||
|
authors = ListField(ReferenceField(User))
|
||||||
|
|
||||||
post = BlogPost(content='Went for a walk today...')
|
post = BlogPost(content='Went for a walk today...')
|
||||||
post.validate()
|
post.validate()
|
||||||
@ -210,15 +214,21 @@ class FieldTest(unittest.TestCase):
|
|||||||
post.tags = ('fun', 'leisure')
|
post.tags = ('fun', 'leisure')
|
||||||
post.validate()
|
post.validate()
|
||||||
|
|
||||||
comments = [Comment(content='Good for you'), Comment(content='Yay.')]
|
|
||||||
post.comments = comments
|
|
||||||
post.validate()
|
|
||||||
|
|
||||||
post.comments = ['a']
|
post.comments = ['a']
|
||||||
self.assertRaises(ValidationError, post.validate)
|
self.assertRaises(ValidationError, post.validate)
|
||||||
post.comments = 'yay'
|
post.comments = 'yay'
|
||||||
self.assertRaises(ValidationError, post.validate)
|
self.assertRaises(ValidationError, post.validate)
|
||||||
|
|
||||||
|
comments = [Comment(content='Good for you'), Comment(content='Yay.')]
|
||||||
|
post.comments = comments
|
||||||
|
post.validate()
|
||||||
|
|
||||||
|
post.authors = [Comment()]
|
||||||
|
self.assertRaises(ValidationError, post.validate)
|
||||||
|
|
||||||
|
post.authors = [User()]
|
||||||
|
post.validate()
|
||||||
|
|
||||||
def test_sorted_list_sorting(self):
|
def test_sorted_list_sorting(self):
|
||||||
"""Ensure that a sorted list field properly sorts values.
|
"""Ensure that a sorted list field properly sorts values.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user