]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- move out unconsumed names tests from test_compiler out to test_insert, test_update
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Mar 2016 01:24:49 +0000 (20:24 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Mar 2016 01:24:49 +0000 (20:24 -0500)
- establish consistent names between existing unconsumed names tests and new ones
added per ref #3666

test/sql/test_compiler.py
test/sql/test_insert.py
test/sql/test_update.py

index 041cd37b6f6eb876535c35d748ceb565ccd856f6..8e75638a24db02b5e633c775bdc95b575cfdbc48 100644 (file)
@@ -2898,48 +2898,6 @@ class CRUDTest(fixtures.TestBase, AssertsCompiledSQL):
                 'x2': 1,
                 'y': 2})
 
-    def test_unconsumed_names(self):
-        t = table("t", column("x"), column("y"))
-        t2 = table("t2", column("q"), column("z"))
-        assert_raises_message(
-            exc.CompileError,
-            "Unconsumed column names: z",
-            t.insert().values(x=5, z=5).compile,
-        )
-        assert_raises_message(
-            exc.CompileError,
-            "Unconsumed column names: z",
-            t.update().values(x=5, z=5).compile,
-        )
-
-        assert_raises_message(
-            exc.CompileError,
-            "Unconsumed column names: j",
-            t.update().values(x=5, j=7).values({t2.c.z: 5}).
-            where(t.c.x == t2.c.q).compile,
-        )
-
-        # bindparam names don't get counted
-        i = t.insert().values(x=3 + bindparam('x2'))
-        self.assert_compile(
-            i,
-            "INSERT INTO t (x) VALUES ((:param_1 + :x2))"
-        )
-
-        # even if in the params list
-        i = t.insert().values(x=3 + bindparam('x2'))
-        self.assert_compile(
-            i,
-            "INSERT INTO t (x) VALUES ((:param_1 + :x2))",
-            params={"x2": 1}
-        )
-
-        assert_raises_message(
-            exc.CompileError,
-            "Unconsumed column names: j",
-            t.update().values(x=5, j=7).compile,
-            column_keys=['j']
-        )
 
     def test_labels_no_collision(self):
 
index 315a567ef9de7d7a02940ec6892517777a9adead..f2515c4eba1fd627666a8255e7011e1265ef0121 100644 (file)
@@ -1,14 +1,13 @@
 #! coding:utf-8
 
 from sqlalchemy import Column, Integer, MetaData, String, Table,\
-    bindparam, exc, func, insert, select, column, text
+    bindparam, exc, func, insert, select, column, text, table
 from sqlalchemy.dialects import mysql, postgresql
 from sqlalchemy.engine import default
 from sqlalchemy.testing import AssertsCompiledSQL,\
     assert_raises_message, fixtures, eq_
 from sqlalchemy.sql import crud
 
-
 class _InsertTestBase(object):
 
     @classmethod
@@ -55,7 +54,32 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
             'INSERT INTO mytable (myid, name) VALUES (:myid, :name)',
             checkparams=checkparams)
 
-    def test_insert_with_values_dict_unknown_column(self):
+    def test_unconsumed_names_kwargs(self):
+        t = table("t", column("x"), column("y"))
+        assert_raises_message(
+            exc.CompileError,
+            "Unconsumed column names: z",
+            t.insert().values(x=5, z=5).compile,
+        )
+
+    def test_bindparam_name_no_consume_error(self):
+        t = table("t", column("x"), column("y"))
+        # bindparam names don't get counted
+        i = t.insert().values(x=3 + bindparam('x2'))
+        self.assert_compile(
+            i,
+            "INSERT INTO t (x) VALUES ((:param_1 + :x2))"
+        )
+
+        # even if in the params list
+        i = t.insert().values(x=3 + bindparam('x2'))
+        self.assert_compile(
+            i,
+            "INSERT INTO t (x) VALUES ((:param_1 + :x2))",
+            params={"x2": 1}
+        )
+
+    def test_unconsumed_names_values_dict(self):
         table1 = self.tables.mytable
 
         checkparams = {
@@ -72,7 +96,7 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
             dialect=postgresql.dialect()
         )
 
-    def test_insert_with_values_dict_unknown_column_multiple(self):
+    def test_unconsumed_names_multi_values_dict(self):
         table1 = self.tables.mytable
 
         checkparams = [{
index 3ab580b112059ba16b2117ccde630c39f64a39e4..8726710083310eff516a22c2dfb8a9c6946f8d24 100644 (file)
@@ -1,8 +1,10 @@
-from sqlalchemy import *
+from sqlalchemy import Integer, String, ForeignKey, and_, or_, func, \
+    literal, update, table, bindparam, column, select, exc
 from sqlalchemy import testing
 from sqlalchemy.dialects import mysql
 from sqlalchemy.engine import default
-from sqlalchemy.testing import AssertsCompiledSQL, eq_, fixtures
+from sqlalchemy.testing import AssertsCompiledSQL, eq_, fixtures, \
+    assert_raises_message
 from sqlalchemy.testing.schema import Table, Column
 from sqlalchemy import util
 
@@ -188,6 +190,36 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL):
             'mytable.myid = hoho(:hoho_1) AND '
             'mytable.name = :param_2 || mytable.name || :param_3')
 
+    def test_unconsumed_names_kwargs(self):
+        t = table("t", column("x"), column("y"))
+
+        assert_raises_message(
+            exc.CompileError,
+            "Unconsumed column names: z",
+            t.update().values(x=5, z=5).compile,
+        )
+
+    def test_unconsumed_names_values_dict(self):
+        t = table("t", column("x"), column("y"))
+        t2 = table("t2", column("q"), column("z"))
+
+        assert_raises_message(
+            exc.CompileError,
+            "Unconsumed column names: j",
+            t.update().values(x=5, j=7).values({t2.c.z: 5}).
+            where(t.c.x == t2.c.q).compile,
+        )
+
+    def test_unconsumed_names_kwargs_w_keys(self):
+        t = table("t", column("x"), column("y"))
+
+        assert_raises_message(
+            exc.CompileError,
+            "Unconsumed column names: j",
+            t.update().values(x=5, j=7).compile,
+            column_keys=['j']
+        )
+
     def test_update_ordered_parameters_1(self):
         table1 = self.tables.mytable