summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-11-25 18:01:31 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-11-25 18:01:31 -0500
commit212d93366d1c5c3a8e44f8b428eeece6258ae28f (patch)
treefa75fbed92f1e899b98cda73911c7936c790871e /test/sql
parentde11f9498258182cbb6668b72067ec3f43a90415 (diff)
downloadsqlalchemy-212d93366d1c5c3a8e44f8b428eeece6258ae28f.tar.gz
- The behavioral contract of the :attr:`.ForeignKeyConstraint.columns`
collection has been made consistent; this attribute is now a :class:`.ColumnCollection` like that of all other constraints and is initialized at the point when the constraint is associated with a :class:`.Table`. fixes #3243
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_metadata.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 3c55242fd..3f24fd07d 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -227,6 +227,50 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
fk1 = ForeignKeyConstraint(('foo', ), ('bar', ), table=t1)
assert fk1 in t1.constraints
+ def test_fk_constraint_col_collection_w_table(self):
+ c1 = Column('foo', Integer)
+ c2 = Column('bar', Integer)
+ m = MetaData()
+ t1 = Table('t', m, c1, c2)
+ fk1 = ForeignKeyConstraint(('foo', ), ('bar', ), table=t1)
+ eq_(dict(fk1.columns), {"foo": c1})
+
+ def test_fk_constraint_col_collection_no_table(self):
+ fk1 = ForeignKeyConstraint(('foo', 'bat'), ('bar', 'hoho'))
+ eq_(dict(fk1.columns), {})
+ eq_(fk1.column_keys, ['foo', 'bat'])
+ eq_(fk1._col_description, 'foo, bat')
+ eq_(fk1._elements, {"foo": fk1.elements[0], "bat": fk1.elements[1]})
+
+ def test_fk_constraint_col_collection_no_table_real_cols(self):
+ c1 = Column('foo', Integer)
+ c2 = Column('bar', Integer)
+ fk1 = ForeignKeyConstraint((c1, ), (c2, ))
+ eq_(dict(fk1.columns), {})
+ eq_(fk1.column_keys, ['foo'])
+ eq_(fk1._col_description, 'foo')
+ eq_(fk1._elements, {"foo": fk1.elements[0]})
+
+ def test_fk_constraint_col_collection_added_to_table(self):
+ c1 = Column('foo', Integer)
+ m = MetaData()
+ fk1 = ForeignKeyConstraint(('foo', ), ('bar', ))
+ Table('t', m, c1, fk1)
+ eq_(dict(fk1.columns), {"foo": c1})
+ eq_(fk1._elements, {"foo": fk1.elements[0]})
+
+ def test_fk_constraint_col_collection_via_fk(self):
+ fk = ForeignKey('bar')
+ c1 = Column('foo', Integer, fk)
+ m = MetaData()
+ t1 = Table('t', m, c1)
+ fk1 = fk.constraint
+ eq_(fk1.column_keys, ['foo'])
+ assert fk1 in t1.constraints
+ eq_(fk1.column_keys, ['foo'])
+ eq_(dict(fk1.columns), {"foo": c1})
+ eq_(fk1._elements, {"foo": fk})
+
def test_fk_no_such_parent_col_error(self):
meta = MetaData()
a = Table('a', meta, Column('a', Integer))