Skip to content
This repository
Browse code

adding tests for multiple column indexes

  • Loading branch information...
commit 22a61584c68c63d58b3b5e0d4ac94f183949f46f 1 parent ca7bd0b
Charles Leifer authored October 02, 2012

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

  1. 25  tests.py
25  tests.py
@@ -167,9 +167,20 @@ class SeqModelB(TestModel):
167 167
     id = IntegerField(primary_key=True, sequence='just_testing_seq')
168 168
     other_num = IntegerField()
169 169
 
  170
+class MultiIndexModel(TestModel):
  171
+    f1 = CharField()
  172
+    f2 = CharField()
  173
+    f3 = CharField()
  174
+
  175
+    class Meta:
  176
+        indexes = (
  177
+            (('f1', 'f2'), True),
  178
+            (('f2', 'f3'), False),
  179
+        )
  180
+
170 181
 
171 182
 MODELS = [User, Blog, Comment, Relationship, NullModel, UniqueModel, OrderedModel, Category, UserCategory,
172  
-          NonIntModel, NonIntRelModel, DBUser, DBBlog, SeqModelA, SeqModelB]
  183
+          NonIntModel, NonIntRelModel, DBUser, DBBlog, SeqModelA, SeqModelB, MultiIndexModel]
173 184
 INT = test_db.interpolation
174 185
 
175 186
 def drop_tables(only=None):
@@ -1133,7 +1144,7 @@ class CustomFormatsModel(Model):
1133 1144
 
1134 1145
 
1135 1146
 class UniqueTestCase(ModelTestCase):
1136  
-    requires = [UniqueModel]
  1147
+    requires = [UniqueModel, MultiIndexModel]
1137 1148
 
1138 1149
     def test_unique(self):
1139 1150
         uniq1 = UniqueModel.create(name='a')
@@ -1141,6 +1152,16 @@ def test_unique(self):
1141 1152
         self.assertRaises(Exception, UniqueModel.create, name='a')
1142 1153
         test_db.rollback()
1143 1154
 
  1155
+    def test_multi_index(self):
  1156
+        mi1 = MultiIndexModel.create(f1='a', f2='a', f3='a')
  1157
+        mi2 = MultiIndexModel.create(f1='b', f2='b', f3='b')
  1158
+        self.assertRaises(Exception, MultiIndexModel.create, f1='a', f2='a', f3='b')
  1159
+        test_db.rollback()
  1160
+        self.assertRaises(Exception, MultiIndexModel.create, f1='b', f2='b', f3='a')
  1161
+        test_db.rollback()
  1162
+
  1163
+        mi3 = MultiIndexModel.create(f1='a', f2='b', f3='b')
  1164
+
1144 1165
 
1145 1166
 class NonIntPKTestCase(ModelTestCase):
1146 1167
     requires = [NonIntModel, NonIntRelModel]

0 notes on commit 22a6158

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