Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Testing the unique indexes

  • Loading branch information...
commit 3628fcfaa81224c5736e767f5b85c9db14e73306 1 parent 1b6a505
@coleifer authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 tests.py
View
23 tests.py
@@ -203,6 +203,17 @@ class CustomPKColumn(TestModel):
class CPKRel(TestModel):
custom = ForeignKeyField(CustomPKColumn)
+class MultiIndexModel(TestModel):
+ f1 = CharField()
+ f2 = CharField()
+ f3 = CharField()
+
+ class Meta:
+ indexes = (
+ (('f1', 'f2'), True),
+ (('f2', 'f3'), False),
+ )
+
class BasePeeweeTestCase(unittest.TestCase):
def setUp(self):
self.qh = QueryLogHandler()
@@ -3225,6 +3236,8 @@ def setUp(self):
super(ModelIndexTestCase, self).setUp()
UniqueModel.drop_table(True)
UniqueModel.create_table()
+ MultiIndexModel.drop_table(True)
+ MultiIndexModel.create_table()
def get_sorted_indexes(self, model):
return test_db.get_indexes_for_table(model._meta.db_table)
@@ -3288,6 +3301,16 @@ def test_unique_index(self):
self.assertRaises(Exception, UniqueModel.create, name='a')
test_db.rollback()
+ def test_multi_index(self):
+ mi1 = MultiIndexModel.create(f1='a', f2='a', f3='a')
+ mi2 = MultiIndexModel.create(f1='b', f2='b', f3='b')
+ self.assertRaises(Exception, MultiIndexModel.create, f1='a', f2='a', f3='b')
+ test_db.rollback()
+ self.assertRaises(Exception, MultiIndexModel.create, f1='b', f2='b', f3='a')
+ test_db.rollback()
+
+ mi3 = MultiIndexModel.create(f1='a', f2='b', f3='b')
+
class ModelTablesTestCase(BaseModelTestCase):
def test_tables_created(self):
Please sign in to comment.
Something went wrong with that request. Please try again.