Added DictField
This commit is contained in:
@@ -176,6 +176,28 @@ class FieldTest(unittest.TestCase):
|
||||
post.comments = 'yay'
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
def test_dict_validation(self):
|
||||
"""Ensure that dict types work as expected.
|
||||
"""
|
||||
class BlogPost(Document):
|
||||
info = DictField()
|
||||
|
||||
post = BlogPost()
|
||||
post.info = 'my post'
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.info = ['test', 'test']
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.info = {'$title': 'test'}
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.info = {'the.title': 'test'}
|
||||
self.assertRaises(ValidationError, post.validate)
|
||||
|
||||
post.info = {'title': 'test'}
|
||||
post.validate()
|
||||
|
||||
def test_embedded_document_validation(self):
|
||||
"""Ensure that invalid embedded documents cannot be assigned to
|
||||
embedded document fields.
|
||||
|
||||
@@ -277,6 +277,22 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
def test_find_dict_item(self):
|
||||
"""Ensure that DictField items may be found.
|
||||
"""
|
||||
class BlogPost(Document):
|
||||
info = DictField()
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
post = BlogPost(info={'title': 'test'})
|
||||
post.save()
|
||||
|
||||
post_obj = BlogPost.objects(info__title='test').first()
|
||||
self.assertEqual(post_obj.id, post.id)
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
def test_q(self):
|
||||
class BlogPost(Document):
|
||||
publish_date = DateTimeField()
|
||||
|
||||
Reference in New Issue
Block a user