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/sql/test_selectable.py | |
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/sql/test_selectable.py')
-rw-r--r-- | test/sql/test_selectable.py | 129 |
1 files changed, 129 insertions, 0 deletions
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].""" |