]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Repair tests for SQLAlchemy 1.3 safestring change
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 7 Feb 2019 15:04:41 +0000 (10:04 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 7 Feb 2019 15:05:58 +0000 (10:05 -0500)
Latest 1.3 includes checks for valid SQL keywords and applies
column() to the element of ExcludeConstraint, adjust tests to
work for this as well as previous behavior.

Change-Id: I7ee571d04cd359dce5b170ed1178cb5637694a10

alembic/autogenerate/render.py
tests/test_op.py
tests/test_postgresql.py

index 3fb0a422daa67860b47a4a3a129b923d2240a715..21bbb50322629c871f02734e6dab4e5386506724 100644 (file)
@@ -614,7 +614,7 @@ def _render_column(column, autogen_context):
 
     comment = sqla_compat._comment_attribute(column)
     if comment:
-        opts.append(("comment", '%r' % comment))
+        opts.append(("comment", "%r" % comment))
 
     # TODO: for non-ascii colname, assign a "key"
     return "%(prefix)sColumn(%(name)r, %(type)s, %(kw)s)" % {
index 8a3e32fbca935d3b779ad37acdcbe058668c9a2b..3a7f436e191cd7732880aac903fc831c692cbb9b 100644 (file)
@@ -522,11 +522,11 @@ class OpTest(TestBase):
             "t2",
             ["foo", "bar"],
             ["bat", "hoho"],
-            initially="INITIAL",
+            initially="deferred",
         )
         context.assert_(
             "ALTER TABLE t1 ADD CONSTRAINT fk_test FOREIGN KEY(foo, bar) "
-            "REFERENCES t2 (bat, hoho) INITIALLY INITIAL"
+            "REFERENCES t2 (bat, hoho) INITIALLY deferred"
         )
 
     @config.requirements.foreign_key_match
index 77e3a20b7c17f66609e25b930bc3422cdda52e52..e6ff8aa9b4e725e7b9b250124c0440b6798998e4 100644 (file)
@@ -135,7 +135,7 @@ class PostgresqlOpTest(TestBase):
         op.create_exclude_constraint(
             "ex1",
             "SomeTable",
-            ('"SomeColumn"', ">"),
+            (column("SomeColumn"), ">"),
             where='"SomeColumn" > 5',
             using="gist",
         )
@@ -263,27 +263,15 @@ class PostgresqlOpTest(TestBase):
     def test_create_table_comment(self):
         # this is handled by SQLAlchemy's compilers
         context = op_fixture("postgresql")
-        op.create_table_comment(
-            't2',
-            comment='t2 table',
-            schema='foo'
-        )
-        context.assert_(
-            "COMMENT ON TABLE foo.t2 IS 't2 table'"
-        )
+        op.create_table_comment("t2", comment="t2 table", schema="foo")
+        context.assert_("COMMENT ON TABLE foo.t2 IS 't2 table'")
 
     @config.requirements.comments_api
     def test_drop_table_comment(self):
         # this is handled by SQLAlchemy's compilers
         context = op_fixture("postgresql")
-        op.drop_table_comment(
-            't2',
-            existing_comment='t2 table',
-            schema='foo'
-        )
-        context.assert_(
-            "COMMENT ON TABLE foo.t2 IS NULL"
-        )
+        op.drop_table_comment("t2", existing_comment="t2 table", schema="foo")
+        context.assert_("COMMENT ON TABLE foo.t2 IS NULL")
 
 
 class PGOfflineEnumTest(TestBase):
@@ -937,7 +925,10 @@ class PostgresqlAutogenRenderTest(TestBase):
             Column("x", String),
             Column("y", String),
             ExcludeConstraint(
-                ("x", ">"), using="gist", where="x != 2", name="t_excl_x"
+                (column("x"), ">"),
+                using="gist",
+                where="x != 2",
+                name="t_excl_x",
             ),
         )
 
@@ -947,7 +938,7 @@ class PostgresqlAutogenRenderTest(TestBase):
             autogenerate.render_op_text(autogen_context, op_obj),
             "op.create_table('t',sa.Column('x', sa.String(), nullable=True),"
             "sa.Column('y', sa.String(), nullable=True),"
-            "postgresql.ExcludeConstraint((!U'x', '>'), "
+            "postgresql.ExcludeConstraint((sa.column(!U'x'), '>'), "
             "where=sa.text(!U'x != 2'), using='gist', name='t_excl_x')"
             ")",
         )