Added test for meta[indexes]
This commit is contained in:
parent
a6d64b2010
commit
4c93e2945c
@ -67,8 +67,6 @@ class Document(BaseDocument):
|
|||||||
def reload(self):
|
def reload(self):
|
||||||
"""Reloads all attributes from the database.
|
"""Reloads all attributes from the database.
|
||||||
"""
|
"""
|
||||||
#object_id = self._fields['id'].to_mongo(self.id)
|
|
||||||
#obj = self.__class__.objects(id=object_id).first()
|
|
||||||
obj = self.__class__.objects(id=self.id).first()
|
obj = self.__class__.objects(id=self.id).first()
|
||||||
for field in self._fields:
|
for field in self._fields:
|
||||||
setattr(self, field, getattr(obj, field))
|
setattr(self, field, getattr(obj, field))
|
||||||
|
@ -25,7 +25,7 @@ class QuerySet(object):
|
|||||||
self._query = {'_types': self._document._class_name}
|
self._query = {'_types': self._document._class_name}
|
||||||
self._cursor_obj = None
|
self._cursor_obj = None
|
||||||
|
|
||||||
def ensure_index(self, key_or_list, direction=None):
|
def ensure_index(self, key_or_list):
|
||||||
"""Ensure that the given indexes are in place.
|
"""Ensure that the given indexes are in place.
|
||||||
"""
|
"""
|
||||||
if isinstance(key_or_list, basestring):
|
if isinstance(key_or_list, basestring):
|
||||||
|
@ -221,6 +221,32 @@ class DocumentTest(unittest.TestCase):
|
|||||||
|
|
||||||
Log.drop_collection()
|
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):
|
def test_creation(self):
|
||||||
"""Ensure that document may be created using keyword arguments.
|
"""Ensure that document may be created using keyword arguments.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user