Added test for meta[indexes]

This commit is contained in:
Harry Marr
2010-01-07 15:46:52 +00:00
parent a6d64b2010
commit 4c93e2945c
3 changed files with 27 additions and 3 deletions

View File

@@ -221,6 +221,32 @@ class DocumentTest(unittest.TestCase):
Log.drop_collection()
def test_indexes(self):
"""Ensure that indexes are used when meta[indexes] is specified.
"""
class BlogPost(Document):
date = DateTimeField(default=datetime.datetime.now)
category = StringField()
meta = {
'indexes': [
'-date',
('category', '-date')
],
}
BlogPost.drop_collection()
info = BlogPost.objects._collection.index_information()
self.assertEqual(len(info), 0)
BlogPost.objects()
info = BlogPost.objects._collection.index_information()
self.assertTrue([('category', 1), ('date', -1)] in info.values())
# Even though descending order was specified, single-key indexes use 1
self.assertTrue([('date', 1)] in info.values())
BlogPost.drop_collection()
def test_creation(self):
"""Ensure that document may be created using keyword arguments.
"""