Exemple #1
0
 def test_rename_fk_inbound(self):
     """
     Tests that the column referred to by an external column can be renamed.
     Edge case, but also useful as stepping stone to renaming tables.
     """
     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()  #Create constraints
     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)
 def test_rename_fk_inbound(self):
     """
     Tests that the column referred to by an external column can be renamed.
     Edge case, but also useful as stepping stone to renaming tables.
     """
     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()  #Create constraints
     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)
Exemple #3
0
 def test_reverse_column_constraint(self):
     """Tests that referred column in a foreign key (ex. id) is found"""
     main_table = 'test_reverse_ref'
     reference_table = 'test_rr_foreign'
     db.start_transaction()
     self._create_foreign_tables(main_table, reference_table)
     db.execute_deferred_sql()
     inverse = db._lookup_reverse_constraint(reference_table, 'id')
     (cname, rev_table, rev_column) = inverse[0]
     self.assertEquals(main_table, rev_table)
     self.assertEquals('foreign_id', rev_column)
     db.delete_table(main_table)
     db.delete_table(reference_table)
 def test_reverse_column_constraint(self):
     """Tests that referred column in a foreign key (ex. id) is found"""
     main_table = 'test_reverse_ref'
     reference_table = 'test_rr_foreign'
     db.start_transaction()
     self._create_foreign_tables(main_table, reference_table)
     db.execute_deferred_sql()
     inverse = db._lookup_reverse_constraint(reference_table, 'id')
     (cname, rev_table, rev_column) = inverse[0]
     self.assertEquals(main_table, rev_table)
     self.assertEquals('foreign_id', rev_column)
     db.delete_table(main_table)
     db.delete_table(reference_table)
 def test_renamed_referenced_table(self):
     """Rename a table referred to in a foreign key"""
     main_table = 'test_rn_refd_table'
     ref_table = 'test_rrt_ref'
     renamed_table = 'test_renamed_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._lookup_reverse_constraint(ref_table)
     self.assertEquals(len(constraints), 1)
     db.rename_table(ref_table, renamed_table)
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     (rtable, rcolumn) = db._lookup_constraint_references(
             main_table, constraints[0])
     self.assertEquals(renamed_table, rtable)
     db.delete_table(main_table)
     db.delete_table(renamed_table)
Exemple #6
0
 def test_renamed_referenced_table(self):
     """Rename a table referred to in a foreign key"""
     main_table = 'test_rn_refd_table'
     ref_table = 'test_rrt_ref'
     renamed_table = 'test_renamed_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._lookup_reverse_constraint(ref_table)
     self.assertEquals(len(constraints), 1)
     db.rename_table(ref_table, renamed_table)
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     (rtable, rcolumn) = db._lookup_constraint_references(
             main_table, constraints[0])
     self.assertEquals(renamed_table, rtable)
     db.delete_table(main_table)
     db.delete_table(renamed_table)