MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_cycle_named_fks

Method test_cycle_named_fks

test/sql/test_constraints.py:497–562  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

495
496 @testing.force_drop_names("a", "b")
497 def test_cycle_named_fks(self):
498 metadata = MetaData()
499
500 Table(
501 "a",
502 metadata,
503 Column("id", Integer, primary_key=True),
504 Column("bid", Integer, ForeignKey("b.id")),
505 )
506
507 Table(
508 "b",
509 metadata,
510 Column("id", Integer, primary_key=True),
511 Column(
512 "aid",
513 Integer,
514 ForeignKey("a.id", use_alter=True, name="aidfk"),
515 ),
516 )
517
518 assertions = [
519 AllOf(
520 CompiledSQL(
521 "CREATE TABLE b ("
522 "id INTEGER NOT NULL, "
523 "aid INTEGER, "
524 "PRIMARY KEY (id)"
525 ")"
526 ),
527 CompiledSQL(
528 "CREATE TABLE a ("
529 "id INTEGER NOT NULL, "
530 "bid INTEGER, "
531 "PRIMARY KEY (id), "
532 "FOREIGN KEY(bid) REFERENCES b (id)"
533 ")"
534 ),
535 ),
536 CompiledSQL(
537 "ALTER TABLE b ADD CONSTRAINT aidfk "
538 "FOREIGN KEY(aid) REFERENCES a (id)"
539 ),
540 ]
541 with self.sql_execution_asserter() as asserter:
542 metadata.create_all(testing.db, checkfirst=False)
543
544 if testing.db.dialect.supports_alter:
545 asserter.assert_(*assertions)
546
547 with self.sql_execution_asserter() as asserter:
548 metadata.drop_all(testing.db, checkfirst=False)
549
550 asserter.assert_(
551 CompiledSQL("ALTER TABLE b DROP CONSTRAINT aidfk"),
552 AllOf(
553 CompiledSQL("DROP TABLE b"), CompiledSQL("DROP TABLE a")
554 ),

Callers

nothing calls this directly

Calls 10

create_allMethod · 0.95
drop_allMethod · 0.95
MetaDataClass · 0.90
TableClass · 0.90
ColumnClass · 0.90
ForeignKeyClass · 0.90
AllOfClass · 0.90
CompiledSQLClass · 0.90
assert_Method · 0.45

Tested by

no test coverage detected