diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-22 16:59:09 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-22 17:37:12 -0500 |
commit | 9fab143a9b6efbfd749c4f96a03eded173561e0a (patch) | |
tree | 3f33d84616dc24fd5168035087efe8077d99a4ac /tests/test_postgresql.py | |
parent | 3e5e3a8d3fa402e91671f689c590b8e57ca10ee8 (diff) | |
download | alembic-9fab143a9b6efbfd749c4f96a03eded173561e0a.tar.gz |
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
Diffstat (limited to 'tests/test_postgresql.py')
-rw-r--r-- | tests/test_postgresql.py | 34 |
1 files changed, 34 insertions, 0 deletions
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()" + ) |