From 9fab143a9b6efbfd749c4f96a03eded173561e0a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 22 Feb 2017 16:59:09 -0500 Subject: Apply subtype repr logic to JSON/JSONB Fixed bug where Postgresql JSON/JSONB types rendered on SQLAlchemy 1.1 would render the "astext_type" argument which defaults to the ``Text()`` type without the module prefix, similarly to the issue with ARRAY fixed in :ticket:`85`. Also modifies the ARRAY approach from :ticket:`85` to be regular expression based for safer targeting of the inner repr() type. Change-Id: I66d51301f4bf5b747b5e8da26a83cbff075d71b2 Fixes: #411 --- tests/test_postgresql.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/test_postgresql.py') diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 1666e50..e8608b7 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -30,6 +30,10 @@ from sqlalchemy import Boolean from sqlalchemy.sql import false +if util.sqla_09: + from sqlalchemy.dialects.postgresql import JSON, JSONB + + class PostgresqlOpTest(TestBase): def test_rename_table_postgresql(self): @@ -732,3 +736,33 @@ unique=False, """ "where=sa.text(!U'x != 2'), using='gist', name='t_excl_x')" ")" ) + + @config.requirements.sqlalchemy_09 + def test_json_type(self): + if config.requirements.sqlalchemy_110.enabled: + eq_ignore_whitespace( + autogenerate.render._repr_type( + JSON(), self.autogen_context), + "postgresql.JSON(astext_type=sa.Text())" + ) + else: + eq_ignore_whitespace( + autogenerate.render._repr_type( + JSON(), self.autogen_context), + "postgresql.JSON()" + ) + + @config.requirements.sqlalchemy_09 + def test_jsonb_type(self): + if config.requirements.sqlalchemy_110.enabled: + eq_ignore_whitespace( + autogenerate.render._repr_type( + JSONB(), self.autogen_context), + "postgresql.JSONB(astext_type=sa.Text())" + ) + else: + eq_ignore_whitespace( + autogenerate.render._repr_type( + JSONB(), self.autogen_context), + "postgresql.JSONB()" + ) -- cgit v1.2.1