diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-15 18:42:59 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-15 18:42:59 -0400 |
| commit | 54808ecccd9f6e7907f4762f6df33e1ad303189c (patch) | |
| tree | dc70f48d77371ea44c6422e243b96ce4fd1c329f /test | |
| parent | 6d8643a1560015de0fefefc7a0ca87b1cc9ce3fd (diff) | |
| download | sqlalchemy-54808ecccd9f6e7907f4762f6df33e1ad303189c.tar.gz | |
- [bug] Declarative can now propagate a column
declared on a single-table inheritance subclass
up to the parent class' table, when the parent
class is itself mapped to a join() or select()
statement, directly or via joined inheritane,
and not just a Table. [ticket:2549]
Diffstat (limited to 'test')
| -rw-r--r-- | test/ext/declarative/test_inheritance.py | 24 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 129 |
2 files changed, 153 insertions, 0 deletions
diff --git a/test/ext/declarative/test_inheritance.py b/test/ext/declarative/test_inheritance.py index 5a8c8e23e..c7117fb43 100644 --- a/test/ext/declarative/test_inheritance.py +++ b/test/ext/declarative/test_inheritance.py @@ -577,6 +577,30 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): eq_(sess.query(Engineer).filter_by(primary_language='cobol' ).one(), Engineer(name='vlad', primary_language='cobol')) + def test_single_from_joined_colsonsub(self): + class Person(Base, fixtures.ComparableEntity): + + __tablename__ = 'people' + id = Column(Integer, primary_key=True, + test_needs_autoincrement=True) + name = Column(String(50)) + discriminator = Column('type', String(50)) + __mapper_args__ = {'polymorphic_on': discriminator} + + class Manager(Person): + __tablename__ = 'manager' + __mapper_args__ = {'polymorphic_identity': 'manager'} + id = Column(Integer, ForeignKey('people.id'), primary_key=True) + golf_swing = Column(String(50)) + + class Boss(Manager): + boss_name = Column(String(50)) + + is_( + Boss.__mapper__.column_attrs['boss_name'].columns[0], + Manager.__table__.c.boss_name + ) + def test_polymorphic_on_converted_from_inst(self): class A(Base): __tablename__ = 'A' diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index ef5f99c40..045f6695c 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -578,6 +578,135 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled Table('t1', MetaData(), c1) eq_(c1._label, "t1_c1") + +class RefreshForNewColTest(fixtures.TestBase): + def test_join_uninit(self): + a = table('a', column('x')) + b = table('b', column('y')) + j = a.join(b, a.c.x == b.c.y) + + q = column('q') + b.append_column(q) + j._refresh_for_new_column(q) + assert j.c.b_q is q + + def test_join_init(self): + a = table('a', column('x')) + b = table('b', column('y')) + j = a.join(b, a.c.x == b.c.y) + j.c + q = column('q') + b.append_column(q) + j._refresh_for_new_column(q) + assert j.c.b_q is q + + + def test_join_samename_init(self): + a = table('a', column('x')) + b = table('b', column('y')) + j = a.join(b, a.c.x == b.c.y) + j.c + q = column('x') + b.append_column(q) + j._refresh_for_new_column(q) + assert j.c.b_x is q + + def test_select_samename_init(self): + a = table('a', column('x')) + b = table('b', column('y')) + s = select([a, b]).apply_labels() + s.c + q = column('x') + b.append_column(q) + s._refresh_for_new_column(q) + assert q in s.c.b_x.proxy_set + + def test_aliased_select_samename_uninit(self): + a = table('a', column('x')) + b = table('b', column('y')) + s = select([a, b]).apply_labels().alias() + q = column('x') + b.append_column(q) + s._refresh_for_new_column(q) + assert q in s.c.b_x.proxy_set + + def test_aliased_select_samename_init(self): + a = table('a', column('x')) + b = table('b', column('y')) + s = select([a, b]).apply_labels().alias() + s.c + q = column('x') + b.append_column(q) + s._refresh_for_new_column(q) + assert q in s.c.b_x.proxy_set + + def test_aliased_select_irrelevant(self): + a = table('a', column('x')) + b = table('b', column('y')) + c = table('c', column('z')) + s = select([a, b]).apply_labels().alias() + s.c + q = column('x') + c.append_column(q) + s._refresh_for_new_column(q) + assert 'c_x' not in s.c + + def test_aliased_select_no_cols_clause(self): + a = table('a', column('x')) + s = select([a.c.x]).apply_labels().alias() + s.c + q = column('q') + a.append_column(q) + s._refresh_for_new_column(q) + assert 'a_q' not in s.c + + def test_union_uninit(self): + a = table('a', column('x')) + s1 = select([a]) + s2 = select([a]) + s3 = s1.union(s2) + q = column('q') + a.append_column(q) + s3._refresh_for_new_column(q) + assert a.c.q in s3.c.q.proxy_set + + def test_union_init_raises(self): + a = table('a', column('x')) + s1 = select([a]) + s2 = select([a]) + s3 = s1.union(s2) + s3.c + q = column('q') + a.append_column(q) + assert_raises_message( + NotImplementedError, + "CompoundSelect constructs don't support addition of " + "columns to underlying selectables", + s3._refresh_for_new_column, q + ) + def test_nested_join_uninit(self): + a = table('a', column('x')) + b = table('b', column('y')) + c = table('c', column('z')) + j = a.join(b, a.c.x == b.c.y).join(c, b.c.y == c.c.z) + + q = column('q') + b.append_column(q) + j._refresh_for_new_column(q) + assert j.c.b_q is q + + def test_nested_join_init(self): + a = table('a', column('x')) + b = table('b', column('y')) + c = table('c', column('z')) + j = a.join(b, a.c.x == b.c.y).join(c, b.c.y == c.c.z) + + j.c + q = column('q') + b.append_column(q) + j._refresh_for_new_column(q) + assert j.c.b_q is q + class AnonLabelTest(fixtures.TestBase): """Test behaviors fixed by [ticket:2168].""" |
