Improved validation of (Generic)Reference fields
This commit is contained in:
parent
5e8604967c
commit
5cc9188c5b
2 changed files with 35 additions and 0 deletions
|
|
@ -377,6 +377,7 @@ class FieldTest(unittest.TestCase):
|
|||
comments = ListField(EmbeddedDocumentField(Comment))
|
||||
tags = ListField(StringField())
|
||||
authors = ListField(ReferenceField(User))
|
||||
generic = ListField(GenericReferenceField())
|
||||
|
||||
post = BlogPost(content='Went for a walk today...')
|
||||
post.validate()
|
||||
|
|
@ -404,8 +405,28 @@ class FieldTest(unittest.TestCase):
|
|||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.authors = [User()]
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
user = User()
|
||||
user.save()
|
||||
post.authors = [user]
|
||||
post.validate()
|
||||
|
||||
post.generic = [1, 2]
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.generic = [User(), Comment()]
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.generic = [Comment()]
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.generic = [user]
|
||||
post.validate()
|
||||
|
||||
User.drop_collection()
|
||||
BlogPost.drop_collection()
|
||||
|
||||
def test_sorted_list_sorting(self):
|
||||
"""Ensure that a sorted list field properly sorts values.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue