Skip to content
This repository
Browse code

Testing the unique indexes

  • Loading branch information...
commit 3628fcfaa81224c5736e767f5b85c9db14e73306 1 parent 1b6a505
Charles Leifer authored August 02, 2012

Showing 1 changed file with 23 additions and 0 deletions. Show diff stats Hide diff stats

  1. 23  tests.py
23  tests.py
@@ -203,6 +203,17 @@ class CustomPKColumn(TestModel):
203 203
 class CPKRel(TestModel):
204 204
     custom = ForeignKeyField(CustomPKColumn)
205 205
 
  206
+class MultiIndexModel(TestModel):
  207
+    f1 = CharField()
  208
+    f2 = CharField()
  209
+    f3 = CharField()
  210
+
  211
+    class Meta:
  212
+        indexes = (
  213
+            (('f1', 'f2'), True),
  214
+            (('f2', 'f3'), False),
  215
+        )
  216
+
206 217
 class BasePeeweeTestCase(unittest.TestCase):
207 218
     def setUp(self):
208 219
         self.qh = QueryLogHandler()
@@ -3225,6 +3236,8 @@ def setUp(self):
3225 3236
         super(ModelIndexTestCase, self).setUp()
3226 3237
         UniqueModel.drop_table(True)
3227 3238
         UniqueModel.create_table()
  3239
+        MultiIndexModel.drop_table(True)
  3240
+        MultiIndexModel.create_table()
3228 3241
 
3229 3242
     def get_sorted_indexes(self, model):
3230 3243
         return test_db.get_indexes_for_table(model._meta.db_table)
@@ -3288,6 +3301,16 @@ def test_unique_index(self):
3288 3301
         self.assertRaises(Exception, UniqueModel.create, name='a')
3289 3302
         test_db.rollback()
3290 3303
 
  3304
+    def test_multi_index(self):
  3305
+        mi1 = MultiIndexModel.create(f1='a', f2='a', f3='a')
  3306
+        mi2 = MultiIndexModel.create(f1='b', f2='b', f3='b')
  3307
+        self.assertRaises(Exception, MultiIndexModel.create, f1='a', f2='a', f3='b')
  3308
+        test_db.rollback()
  3309
+        self.assertRaises(Exception, MultiIndexModel.create, f1='b', f2='b', f3='a')
  3310
+        test_db.rollback()
  3311
+
  3312
+        mi3 = MultiIndexModel.create(f1='a', f2='b', f3='b')
  3313
+
3291 3314
 
3292 3315
 class ModelTablesTestCase(BaseModelTestCase):
3293 3316
     def test_tables_created(self):

0 notes on commit 3628fcf

Please sign in to comment.
Something went wrong with that request. Please try again.