summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-10-11 15:55:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-10-11 15:55:57 -0400
commit9d38ed33400adf3ba8fdf3af49f26de1270bbe23 (patch)
treebe88cbfb8654fc5cb119e05a0829c2111b966de2 /test/sql
parent5f0b864ad02409cf668fa7db5cbac99ac6ffc329 (diff)
downloadsqlalchemy-9d38ed33400adf3ba8fdf3af49f26de1270bbe23.tar.gz
The "name" attribute is set on :class:`.Index` before the "attach"
events are called, so that attachment events can be used to dynamically generate a name for the index based on the parent table and/or columns. [ticket:2835]
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_metadata.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 2498a822c..1da833d9f 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -1904,6 +1904,7 @@ class CatchAllEventsTest(fixtures.TestBase):
parent.__class__.__name__))
def after_attach(obj, parent):
+ assert hasattr(obj, 'name') # so we can change it
canary.append("%s->%s" % (target.__name__, parent))
event.listen(target, "before_parent_attach", before_attach)
event.listen(target, "after_parent_attach", after_attach)
@@ -1911,14 +1912,15 @@ class CatchAllEventsTest(fixtures.TestBase):
for target in [
schema.ForeignKeyConstraint, schema.PrimaryKeyConstraint,
schema.UniqueConstraint,
- schema.CheckConstraint
+ schema.CheckConstraint,
+ schema.Index
]:
evt(target)
m = MetaData()
Table('t1', m,
Column('id', Integer, Sequence('foo_id'), primary_key=True),
- Column('bar', String, ForeignKey('t2.id')),
+ Column('bar', String, ForeignKey('t2.id'), index=True),
Column('bat', Integer, unique=True),
)
Table('t2', m,
@@ -1926,17 +1928,20 @@ class CatchAllEventsTest(fixtures.TestBase):
Column('bar', Integer),
Column('bat', Integer),
CheckConstraint("bar>5"),
- UniqueConstraint('bar', 'bat')
+ UniqueConstraint('bar', 'bat'),
+ Index(None, 'bar', 'bat')
)
eq_(
canary,
[
'PrimaryKeyConstraint->Table', 'PrimaryKeyConstraint->t1',
+ 'Index->Table', 'Index->t1',
'ForeignKeyConstraint->Table', 'ForeignKeyConstraint->t1',
'UniqueConstraint->Table', 'UniqueConstraint->t1',
'PrimaryKeyConstraint->Table', 'PrimaryKeyConstraint->t2',
'CheckConstraint->Table', 'CheckConstraint->t2',
- 'UniqueConstraint->Table', 'UniqueConstraint->t2'
+ 'UniqueConstraint->Table', 'UniqueConstraint->t2',
+ 'Index->Table', 'Index->t2'
]
)