From: Mike Bayer Date: Thu, 7 Feb 2019 15:04:41 +0000 (-0500) Subject: Repair tests for SQLAlchemy 1.3 safestring change X-Git-Tag: rel_1_0_8~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c12b867f8af5f853900970be571857b86151f41;p=thirdparty%2Fsqlalchemy%2Falembic.git Repair tests for SQLAlchemy 1.3 safestring change 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 --- diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py index 3fb0a422..21bbb503 100644 --- a/alembic/autogenerate/render.py +++ b/alembic/autogenerate/render.py @@ -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)" % { diff --git a/tests/test_op.py b/tests/test_op.py index 8a3e32fb..3a7f436e 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -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 diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 77e3a20b..e6ff8aa9 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -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')" ")", )