Unique indexes are created before user declared indexes

This ensures that indexes are created with the unique flag, if a user
declares the index, that would automatically be declared by the `unique_indexes`
logic.

Thanks to btubbs for the test case.
Fixes #129
This commit is contained in:
Ross Lawley
2011-05-18 17:37:41 +01:00
parent 5d5a84dbcf
commit fc2aff342b
2 changed files with 28 additions and 5 deletions

View File

@@ -357,6 +357,29 @@ class DocumentTest(unittest.TestCase):
BlogPost.drop_collection()
def test_unique_and_indexes(self):
"""Ensure that 'unique' constraints aren't overridden by
meta.indexes.
"""
class Customer(Document):
cust_id = IntField(unique=True, required=True)
meta = {
'indexes': ['cust_id'],
'allow_inheritance': False,
}
Customer.drop_collection()
cust = Customer(cust_id=1)
cust.save()
cust_dupe = Customer(cust_id=1)
try:
cust_dupe.save()
raise AssertionError, "We saved a dupe!"
except OperationError:
pass
Customer.drop_collection()
def test_custom_id_field(self):
"""Ensure that documents may be created with custom primary keys.
"""