'Test the RemoveIndex operation.'

def test_remove_index(self):

    project_state = self.set_up_test_model('test_rmin', multicol_index=True)
    self.assertTableExists('test_rmin_pony')
    self.assertIndexExists('test_rmin_pony', ['pink', 'weight'])
    operation = migrations.RemoveIndex('Pony', 'pony_test_idx')
    self.assertEqual(operation.describe(), 'Remove    index    pony_test_idx    from    Pony')
    new_state = project_state.clone()
    operation.state_forwards('test_rmin', new_state)
    self.assertEqual(len(new_state.models[('test_rmin', 'pony')].options['indexes']), 0)
    self.assertIndexExists('test_rmin_pony', ['pink', 'weight'])
    with connection.schema_editor() as editor:
        operation.database_forwards('test_rmin', editor, project_state, new_state)
    self.assertIndexNotExists('test_rmin_pony', ['pink', 'weight'])
    with connection.schema_editor() as editor:
        operation.database_backwards('test_rmin', editor, new_state, project_state)
    self.assertIndexExists('test_rmin_pony', ['pink', 'weight'])
    definition = operation.deconstruct()
    self.assertEqual(definition[0], 'RemoveIndex')
    self.assertEqual(definition[1], [])
    self.assertEqual(definition[2], {'model_name': 'Pony', 'name': 'pony_test_idx'})
    operations = [migrations.RemoveIndex('Pony', 'pony_test_idx'), migrations.RemoveField('Pony', 'pink')]
    self.assertColumnExists('test_rmin_pony', 'pink')
    self.assertIndexExists('test_rmin_pony', ['pink', 'weight'])
    new_state = project_state.clone()
    self.apply_operations('test_rmin', new_state, operations=operations)
    self.assertColumnNotExists('test_rmin_pony', 'pink')
    self.assertIndexNotExists('test_rmin_pony', ['pink', 'weight'])
    self.unapply_operations('test_rmin', project_state, operations=operations)
    self.assertIndexExists('test_rmin_pony', ['pink', 'weight'])
