diff options
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_defaults.py | 2 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 93 | ||||
| -rw-r--r-- | test/sql/test_insert.py | 30 | ||||
| -rw-r--r-- | test/sql/test_insert_exec.py | 8 | ||||
| -rw-r--r-- | test/sql/test_update.py | 11 |
5 files changed, 135 insertions, 9 deletions
diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index ad27828a4..831f2a680 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -460,7 +460,7 @@ class DefaultTest(fixtures.TestBase): set([t.c.col3, t.c.col5, t.c.col4, t.c.col6]), ) - r = t.insert(inline=True).execute() + r = t.insert().inline().execute() assert r.lastrow_has_defaults() eq_( set(r.context.postfetch_cols), diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index ba6048f07..8bdba2793 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -1731,3 +1731,96 @@ class DefaultTest(fixtures.TestBase): conn.execute(table.insert().values(x=5)) eq_(conn.execute(select([table])).first(), (5, 12)) + + +class DMLTest(fixtures.TestBase, AssertsCompiledSQL): + __dialect__ = "default" + + def test_insert_inline_kw_defaults(self): + m = MetaData() + foo = Table("foo", m, Column("id", Integer)) + + t = Table( + "test", + m, + Column("col1", Integer, default=func.foo(1)), + Column( + "col2", + Integer, + default=select([func.coalesce(func.max(foo.c.id))]), + ), + ) + + with testing.expect_deprecated_20( + "The insert.inline parameter will be removed in SQLAlchemy 2.0." + ): + stmt = t.insert(inline=True, values={}) + + self.assert_compile( + stmt, + "INSERT INTO test (col1, col2) VALUES (foo(:foo_1), " + "(SELECT coalesce(max(foo.id)) AS coalesce_1 FROM " + "foo))", + inline_flag=True, + ) + + def test_insert_inline_kw_default(self): + metadata = MetaData() + table = Table( + "sometable", + metadata, + Column("id", Integer, primary_key=True), + Column("foo", Integer, default=func.foobar()), + ) + + with testing.expect_deprecated_20( + "The insert.inline parameter will be removed in SQLAlchemy 2.0." + ): + stmt = table.insert(values={}, inline=True) + + self.assert_compile( + stmt, + "INSERT INTO sometable (foo) VALUES (foobar())", + inline_flag=True, + ) + + with testing.expect_deprecated_20( + "The insert.inline parameter will be removed in SQLAlchemy 2.0." + ): + stmt = table.insert(inline=True) + + self.assert_compile( + stmt, + "INSERT INTO sometable (foo) VALUES (foobar())", + params={}, + inline_flag=True, + ) + + def test_update_inline_kw_defaults(self): + m = MetaData() + foo = Table("foo", m, Column("id", Integer)) + + t = Table( + "test", + m, + Column("col1", Integer, onupdate=func.foo(1)), + Column( + "col2", + Integer, + onupdate=select([func.coalesce(func.max(foo.c.id))]), + ), + Column("col3", String(30)), + ) + + with testing.expect_deprecated_20( + "The update.inline parameter will be removed in SQLAlchemy 2.0." + ): + stmt = t.update(inline=True, values={"col3": "foo"}) + + self.assert_compile( + stmt, + "UPDATE test SET col1=foo(:foo_1), col2=(SELECT " + "coalesce(max(foo.id)) AS coalesce_1 FROM foo), " + "col3=:col3", + inline_flag=True, + ) diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index f4516f942..7508ee6c7 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -135,10 +135,19 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): ) self.assert_compile( - t.insert(inline=True, values={}), + t.insert().values({}), "INSERT INTO test (col1, col2) VALUES (foo(:foo_1), " "(SELECT coalesce(max(foo.id)) AS coalesce_1 FROM " "foo))", + inline_flag=False, + ) + + self.assert_compile( + t.insert().inline().values({}), + "INSERT INTO test (col1, col2) VALUES (foo(:foo_1), " + "(SELECT coalesce(max(foo.id)) AS coalesce_1 FROM " + "foo))", + inline_flag=True, ) def test_generic_insert_bind_params_all_columns(self): @@ -290,14 +299,29 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): ) self.assert_compile( - table.insert(values={}, inline=True), + table.insert().values(), + "INSERT INTO sometable (foo) VALUES (foobar())", + inline_flag=False, + ) + + self.assert_compile( + table.insert(), + "INSERT INTO sometable (foo) VALUES (foobar())", + params={}, + inline_flag=False, + ) + + self.assert_compile( + table.insert().values().inline(), "INSERT INTO sometable (foo) VALUES (foobar())", + inline_flag=True, ) self.assert_compile( - table.insert(inline=True), + table.insert().inline(), "INSERT INTO sometable (foo) VALUES (foobar())", params={}, + inline_flag=True, ) def test_insert_returning_not_in_default(self): diff --git a/test/sql/test_insert_exec.py b/test/sql/test_insert_exec.py index 2021c030c..9f9525f3c 100644 --- a/test/sql/test_insert_exec.py +++ b/test/sql/test_insert_exec.py @@ -338,7 +338,7 @@ class InsertExecTest(fixtures.TablesTest): class TableInsertTest(fixtures.TablesTest): """test for consistent insert behavior across dialects - regarding the inline=True flag, lower-case 't' tables. + regarding the inline() method, lower-case 't' tables. """ @@ -410,7 +410,7 @@ class TableInsertTest(fixtures.TablesTest): def test_uppercase_inline(self): t = self.tables.foo self._test( - t.insert(inline=True).values(id=1, data="data", x=5), + t.insert().inline().values(id=1, data="data", x=5), (1, "data", 5), inserted_primary_key=[1], ) @@ -422,7 +422,7 @@ class TableInsertTest(fixtures.TablesTest): def test_uppercase_inline_implicit(self): t = self.tables.foo self._test( - t.insert(inline=True).values(data="data", x=5), + t.insert().inline().values(data="data", x=5), (1, "data", 5), inserted_primary_key=[None], ) @@ -501,7 +501,7 @@ class TableInsertTest(fixtures.TablesTest): def test_implicit_pk_inline(self): t = self._fixture() self._test( - t.insert(inline=True).values(data="data", x=5), + t.insert().inline().values(data="data", x=5), (1, "data", 5), inserted_primary_key=[], ) diff --git a/test/sql/test_update.py b/test/sql/test_update.py index 68db6270f..78eecdf21 100644 --- a/test/sql/test_update.py +++ b/test/sql/test_update.py @@ -329,10 +329,19 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL): ) self.assert_compile( - t.update(inline=True, values={"col3": "foo"}), + t.update().values({"col3": "foo"}), "UPDATE test SET col1=foo(:foo_1), col2=(SELECT " "coalesce(max(foo.id)) AS coalesce_1 FROM foo), " "col3=:col3", + inline_flag=False, + ) + + self.assert_compile( + t.update().inline().values({"col3": "foo"}), + "UPDATE test SET col1=foo(:foo_1), col2=(SELECT " + "coalesce(max(foo.id)) AS coalesce_1 FROM foo), " + "col3=:col3", + inline_flag=True, ) def test_update_1(self): |
