def test_not_unique(self):
num_constraints_before = len(self.get_constraints(Job))
# Add the index
index_name = 'job_test_idx'
index = PartialIndex(fields=['-group'], name=index_name, unique=False, where_postgresql='is_complete = false', where_sqlite='is_complete = 0')
with self.schema_editor() as editor:
editor.add_index(Job, index)
constraints = self.get_constraints(Job)
self.assertEqual(len(constraints), num_constraints_before + 1)
self.assertEqual(constraints[index_name]['columns'], ['group'])
self.assertEqual(constraints[index_name]['orders'], ['DESC'])
self.assertEqual(constraints[index_name]['primary_key'], False)
self.assertEqual(constraints[index_name]['check'], False)
self.assertEqual(constraints[index_name]['index'], True)
self.assertEqual(constraints[index_name]['unique'], False)
# Drop the index
with self.schema_editor() as editor:
editor.remove_index(Job, index)
constraints = self.get_constraints(Job)
self.assertEqual(len(constraints), num_constraints_before)
self.assertNotIn(index_name, constraints)
评论列表
文章目录