'Tests that the column referred to by an external column can be renamed.
Edge case, but also useful as stepping stone to renaming tables.'

def test_rename_fk_inbound(self):

    main_table = 'test_rename_fk_inbound'
    ref_table = 'test_rfi_ref'
    self._create_foreign_tables(main_table, ref_table)
    db.execute_deferred_sql()
    constraints = db._lookup_reverse_constraint(ref_table, 'id')
    self.assertEquals(len(constraints), 1)
    db.rename_column(ref_table, 'id', 'rfi_id')
    db.execute_deferred_sql()
    constraints = db._lookup_reverse_constraint(ref_table, 'rfi_id')
    self.assertEquals(len(constraints), 1)
    cname = db._find_foreign_constraints(main_table, 'foreign_id')[0]
    (rtable, rcolumn) = db._lookup_constraint_references(main_table, cname)
    self.assertEquals(rcolumn, 'rfi_id')
    db.delete_table(main_table)
    db.delete_table(ref_table)
