Fixed index inheritance issues
firmed up testcases (MongoEngine/mongoengine#123) (MongoEngine/mongoengine#125)
This commit is contained in:
parent
5c6035d636
commit
5949970a95
@ -2,6 +2,11 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
|
||||||
|
Changes in 0.7.4
|
||||||
|
================
|
||||||
|
- Fixed index inheritance issues - firmed up testcases (MongoEngine/mongoengine#123) (MongoEngine/mongoengine#125)
|
||||||
|
|
||||||
Changes in 0.7.3
|
Changes in 0.7.3
|
||||||
================
|
================
|
||||||
- Reverted EmbeddedDocuments meta handling - now can turn off inheritance (MongoEngine/mongoengine#119)
|
- Reverted EmbeddedDocuments meta handling - now can turn off inheritance (MongoEngine/mongoengine#119)
|
||||||
|
@ -501,8 +501,10 @@ class QuerySet(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(spec, basestring):
|
if isinstance(spec, basestring):
|
||||||
spec = {'fields': [spec]}
|
spec = {'fields': [spec]}
|
||||||
if isinstance(spec, (list, tuple)):
|
elif isinstance(spec, (list, tuple)):
|
||||||
spec = {'fields': spec}
|
spec = {'fields': list(spec)}
|
||||||
|
elif isinstance(spec, dict):
|
||||||
|
spec = dict(spec)
|
||||||
|
|
||||||
index_list = []
|
index_list = []
|
||||||
direction = None
|
direction = None
|
||||||
|
@ -420,6 +420,9 @@ class DocumentTest(unittest.TestCase):
|
|||||||
'indexes': ['name']
|
'indexes': ['name']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.assertEqual(Animal._meta['index_specs'],
|
||||||
|
[{'fields': [('_types', 1), ('name', 1)]}])
|
||||||
|
|
||||||
Animal.drop_collection()
|
Animal.drop_collection()
|
||||||
|
|
||||||
dog = Animal(name='dog')
|
dog = Animal(name='dog')
|
||||||
@ -441,6 +444,9 @@ class DocumentTest(unittest.TestCase):
|
|||||||
'allow_inheritance': False,
|
'allow_inheritance': False,
|
||||||
'indexes': ['name']
|
'indexes': ['name']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.assertEqual(Animal._meta['index_specs'],
|
||||||
|
[{'fields': [('name', 1)]}])
|
||||||
collection.update({}, {"$unset": {"_types": 1, "_cls": 1}}, multi=True)
|
collection.update({}, {"$unset": {"_types": 1, "_cls": 1}}, multi=True)
|
||||||
|
|
||||||
# Confirm extra data is removed
|
# Confirm extra data is removed
|
||||||
@ -658,6 +664,12 @@ class DocumentTest(unittest.TestCase):
|
|||||||
'allow_inheritance': True
|
'allow_inheritance': True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.assertEqual(BlogPost._meta['index_specs'],
|
||||||
|
[{'fields': [('_types', 1), ('addDate', -1)]},
|
||||||
|
{'fields': [('tags', 1)]},
|
||||||
|
{'fields': [('_types', 1), ('category', 1),
|
||||||
|
('addDate', -1)]}])
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
info = BlogPost.objects._collection.index_information()
|
info = BlogPost.objects._collection.index_information()
|
||||||
@ -681,6 +693,13 @@ class DocumentTest(unittest.TestCase):
|
|||||||
title = StringField()
|
title = StringField()
|
||||||
meta = {'indexes': ['title']}
|
meta = {'indexes': ['title']}
|
||||||
|
|
||||||
|
self.assertEqual(ExtendedBlogPost._meta['index_specs'],
|
||||||
|
[{'fields': [('_types', 1), ('addDate', -1)]},
|
||||||
|
{'fields': [('tags', 1)]},
|
||||||
|
{'fields': [('_types', 1), ('category', 1),
|
||||||
|
('addDate', -1)]},
|
||||||
|
{'fields': [('_types', 1), ('title', 1)]}])
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
list(ExtendedBlogPost.objects)
|
list(ExtendedBlogPost.objects)
|
||||||
@ -711,6 +730,8 @@ class DocumentTest(unittest.TestCase):
|
|||||||
description = StringField()
|
description = StringField()
|
||||||
|
|
||||||
self.assertEqual(A._meta['index_specs'], B._meta['index_specs'])
|
self.assertEqual(A._meta['index_specs'], B._meta['index_specs'])
|
||||||
|
self.assertEqual([{'fields': [('_types', 1), ('title', 1)]}],
|
||||||
|
A._meta['index_specs'])
|
||||||
|
|
||||||
def test_build_index_spec_is_not_destructive(self):
|
def test_build_index_spec_is_not_destructive(self):
|
||||||
|
|
||||||
@ -791,6 +812,9 @@ class DocumentTest(unittest.TestCase):
|
|||||||
'allow_inheritance': False
|
'allow_inheritance': False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.assertEqual([{'fields': [('rank.title', 1)]}],
|
||||||
|
Person._meta['index_specs'])
|
||||||
|
|
||||||
Person.drop_collection()
|
Person.drop_collection()
|
||||||
|
|
||||||
# Indexes are lazy so use list() to perform query
|
# Indexes are lazy so use list() to perform query
|
||||||
@ -809,6 +833,10 @@ class DocumentTest(unittest.TestCase):
|
|||||||
'*location.point',
|
'*location.point',
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.assertEqual([{'fields': [('location.point', '2d')]}],
|
||||||
|
Place._meta['index_specs'])
|
||||||
|
|
||||||
Place.drop_collection()
|
Place.drop_collection()
|
||||||
|
|
||||||
info = Place.objects._collection.index_information()
|
info = Place.objects._collection.index_information()
|
||||||
@ -834,6 +862,10 @@ class DocumentTest(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.assertEqual([{'fields': [('addDate', -1)], 'unique': True,
|
||||||
|
'sparse': True, 'types': False}],
|
||||||
|
BlogPost._meta['index_specs'])
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
info = BlogPost.objects._collection.index_information()
|
info = BlogPost.objects._collection.index_information()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user