示例#1
0
 def test_remove(self):
     project_state = self.set_up_test_model(self.app_label, index=True)
     table_name = '%s_pony' % self.app_label
     self.assertTableExists(table_name)
     new_state = project_state.clone()
     operation = RemoveIndexConcurrently('Pony', 'pony_pink_idx')
     self.assertEqual(
         operation.describe(),
         'Concurrently remove index pony_pink_idx from Pony',
     )
     operation.state_forwards(self.app_label, new_state)
     self.assertEqual(
         len(new_state.models[self.app_label, 'pony'].options['indexes']),
         0)
     self.assertIndexExists(table_name, ['pink'])
     # Remove index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(self.app_label, editor, project_state,
                                     new_state)
     self.assertIndexNotExists(table_name, ['pink'])
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(self.app_label, editor, new_state,
                                      project_state)
     self.assertIndexExists(table_name, ['pink'])
     # Deconstruction.
     name, args, kwargs = operation.deconstruct()
     self.assertEqual(name, 'RemoveIndexConcurrently')
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {
         'model_name': 'Pony',
         'name': 'pony_pink_idx'
     })
示例#2
0
 def test_remove(self):
     project_state = self.set_up_test_model(self.app_label, index=True)
     table_name = "%s_pony" % self.app_label
     self.assertTableExists(table_name)
     new_state = project_state.clone()
     operation = RemoveIndexConcurrently("Pony", "pony_pink_idx")
     self.assertEqual(
         operation.describe(),
         "Concurrently remove index pony_pink_idx from Pony",
     )
     operation.state_forwards(self.app_label, new_state)
     self.assertEqual(
         len(new_state.models[self.app_label, "pony"].options["indexes"]), 0
     )
     self.assertIndexExists(table_name, ["pink"])
     # Remove index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(
             self.app_label, editor, project_state, new_state
         )
     self.assertIndexNotExists(table_name, ["pink"])
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(
             self.app_label, editor, new_state, project_state
         )
     self.assertIndexExists(table_name, ["pink"])
     # Deconstruction.
     name, args, kwargs = operation.deconstruct()
     self.assertEqual(name, "RemoveIndexConcurrently")
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {"model_name": "Pony", "name": "pony_pink_idx"})