'Tests the RenameModel operation.'

def test_rename_model(self):

    project_state = self.set_up_test_model('test_rnmo', related_model=True)
    operation = migrations.RenameModel('Pony', 'Horse')
    self.assertEqual(operation.describe(), 'Rename    model    Pony    to    Horse')
    self.assertIn(('test_rnmo', 'pony'), project_state.models)
    self.assertNotIn(('test_rnmo', 'horse'), project_state.models)
    self.assertTableExists('test_rnmo_pony')
    self.assertTableNotExists('test_rnmo_horse')
    if connection.features.supports_foreign_keys:
        self.assertFKExists('test_rnmo_rider', ['pony_id'], ('test_rnmo_pony', 'id'))
        self.assertFKNotExists('test_rnmo_rider', ['pony_id'], ('test_rnmo_horse', 'id'))
    new_state = project_state.clone()
    new_state = self.apply_operations('test_rnmo', new_state, [operation])
    self.assertNotIn(('test_rnmo', 'pony'), new_state.models)
    self.assertIn(('test_rnmo', 'horse'), new_state.models)
    self.assertEqual('test_rnmo.Horse', new_state.models[('test_rnmo', 'rider')].fields[1][1].remote_field.model)
    self.assertTableNotExists('test_rnmo_pony')
    self.assertTableExists('test_rnmo_horse')
    if connection.features.supports_foreign_keys:
        self.assertFKNotExists('test_rnmo_rider', ['pony_id'], ('test_rnmo_pony', 'id'))
        self.assertFKExists('test_rnmo_rider', ['pony_id'], ('test_rnmo_horse', 'id'))
    original_state = self.unapply_operations('test_rnmo', project_state, [operation])
    self.assertIn(('test_rnmo', 'pony'), original_state.models)
    self.assertNotIn(('test_rnmo', 'horse'), original_state.models)
    self.assertEqual('Pony', original_state.models[('test_rnmo', 'rider')].fields[1][1].remote_field.model)
    self.assertTableExists('test_rnmo_pony')
    self.assertTableNotExists('test_rnmo_horse')
    if connection.features.supports_foreign_keys:
        self.assertFKExists('test_rnmo_rider', ['pony_id'], ('test_rnmo_pony', 'id'))
        self.assertFKNotExists('test_rnmo_rider', ['pony_id'], ('test_rnmo_horse', 'id'))
    definition = operation.deconstruct()
    self.assertEqual(definition[0], 'RenameModel')
    self.assertEqual(definition[1], [])
    self.assertEqual(definition[2], {'old_name': 'Pony', 'new_name': 'Horse'})
