diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-18 20:35:01 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-27 21:19:06 -0400 |
| commit | 47552aa93bedcce3756dc89774f02db9f1868e68 (patch) | |
| tree | 4a00be1f85b5964e8cf6d035ed94345eba0459e4 /test/sql | |
| parent | 8b2eb2a2d0f4c7e283d96cf3e5263b5dd48e3b14 (diff) | |
| download | sqlalchemy-47552aa93bedcce3756dc89774f02db9f1868e68.tar.gz | |
Use roles for ORM alias() conversion
as SELECT statements will have subquery() and not alias(),
start getting ready for the places where the ORM coerces SELECTs
into subqueries and be ready to warn about it
Change-Id: I90d4b6cae2c72816c6b192016ce074589caf4731
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_deprecations.py | 12 | ||||
| -rw-r--r-- | test/sql/test_roles.py | 33 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 2 |
3 files changed, 46 insertions, 1 deletions
diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 8e8591aec..90646c41d 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -486,6 +486,18 @@ class SubqueryCoercionsTest(fixtures.TestBase, AssertsCompiledSQL): is_true(stmt.compare(select([table1.c.myid]).scalar_subquery())) + def test_fromclause_subquery(self): + stmt = select([table1.c.myid]) + with testing.expect_deprecated( + "Implicit coercion of SELECT and textual SELECT constructs " + "into FROM clauses is deprecated" + ): + coerced = coercions.expect( + roles.StrictFromClauseRole, stmt, allow_select=True + ) + + is_true(coerced.compare(stmt.subquery())) + class TextTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = "default" diff --git a/test/sql/test_roles.py b/test/sql/test_roles.py index 81934de24..0d819c13d 100644 --- a/test/sql/test_roles.py +++ b/test/sql/test_roles.py @@ -195,6 +195,39 @@ class RoleTest(fixtures.TestBase): d1 = DDL("hi") is_(expect(roles.CoerceTextStatementRole, d1), d1) + def test_strict_from_clause_role(self): + stmt = select([t]).subquery() + is_true( + expect(roles.StrictFromClauseRole, stmt).compare( + select([t]).subquery() + ) + ) + + def test_strict_from_clause_role_disallow_select(self): + stmt = select([t]) + assert_raises_message( + exc.ArgumentError, + r"FROM expression, such as a Table or alias\(\) " + "object expected, got .*Select", + expect, + roles.StrictFromClauseRole, + stmt, + ) + + def test_anonymized_from_clause_role(self): + is_true(expect(roles.AnonymizedFromClauseRole, t).compare(t.alias())) + + # note the compare for subquery().alias(), even if it is two + # plain Alias objects (which it won't be once we introduce the + # Subquery class), still compares based on alias() being present + # twice, that is, alias().alias() builds an alias of an alias, rather + # than just replacing the outer alias. + is_true( + expect( + roles.AnonymizedFromClauseRole, select([t]).subquery() + ).compare(select([t]).subquery().alias()) + ) + def test_statement_coercion_sequence(self): s1 = Sequence("hi") is_(expect(roles.CoerceTextStatementRole, s1), s1) diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index f88243fc2..186fb3d9e 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -1711,7 +1711,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): { "BaseItem": base_item_table.select( base_item_table.c.child_name == "BaseItem" - ), + ).subquery(), "Item": base_item_table.join(item_table), }, None, |
