diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-01-31 19:04:54 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-01-31 19:04:54 -0500 |
| commit | bf70f556b382dc376783efbcb598e0fab71ee235 (patch) | |
| tree | b2eb21efee6bf90b693b4703e4a3890e9dcfb912 /test/dialect/postgresql | |
| parent | a523163c4140e5a912540a0092206b99ddf9796d (diff) | |
| download | sqlalchemy-bf70f556b382dc376783efbcb598e0fab71ee235.tar.gz | |
- Added support for the :class:`postgresql.JSONB` datatype when
using psycopg2 2.5.4 or greater, which features native conversion
of JSONB data so that SQLAlchemy's converters must be disabled;
additionally, the newly added psycopg2 extension
``extras.register_default_jsonb`` is used to establish a JSON
deserializer passed to the dialect via the ``json_deserializer``
argument. Also repaired the Postgresql integration tests which
weren't actually round-tripping the JSONB type as opposed to the
JSON type. Pull request courtesy Mateusz Susik.
- Repaired the use of the "array_oid" flag when registering the
HSTORE type with older psycopg2 versions < 2.4.3, which does not
support this flag, as well as use of the native json serializer
hook "register_default_json" with user-defined ``json_deserializer``
on psycopg2 versions < 2.5, which does not include native json.
Diffstat (limited to 'test/dialect/postgresql')
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 1f572c9a1..5e00fd605 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -1948,13 +1948,15 @@ class JSONRoundTripTest(fixtures.TablesTest): __only_on__ = ('postgresql >= 9.3',) __backend__ = True + test_type = JSON + @classmethod def define_tables(cls, metadata): Table('data_table', metadata, Column('id', Integer, primary_key=True), Column('name', String(30), nullable=False), - Column('data', JSON), - Column('nulldata', JSON(none_as_null=True)) + Column('data', cls.test_type), + Column('nulldata', cls.test_type(none_as_null=True)) ) def _fixture_data(self, engine): @@ -2016,7 +2018,8 @@ class JSONRoundTripTest(fixtures.TablesTest): else: options = {} - if testing.against("postgresql+psycopg2"): + if testing.against("postgresql+psycopg2") and \ + testing.db.dialect.psycopg2_version >= (2, 5): from psycopg2.extras import register_default_json engine = engines.testing_engine(options=options) @@ -2037,7 +2040,7 @@ class JSONRoundTripTest(fixtures.TablesTest): def test_reflect(self): insp = inspect(testing.db) cols = insp.get_columns('data_table') - assert isinstance(cols[2]['type'], JSON) + assert isinstance(cols[2]['type'], self.test_type) @testing.only_on("postgresql+psycopg2") def test_insert_native(self): @@ -2096,7 +2099,7 @@ class JSONRoundTripTest(fixtures.TablesTest): "key": "value", "x": "q" }, - JSON + self.test_type ) ]) eq_( @@ -2172,7 +2175,7 @@ class JSONRoundTripTest(fixtures.TablesTest): "key": "value", "key2": {"k1": "v1", "k2": "v2"} }, - JSON + self.test_type ) ]) eq_( @@ -2199,7 +2202,7 @@ class JSONRoundTripTest(fixtures.TablesTest): util.u('réveillé'): util.u('réveillé'), "data": {"k1": util.u('drôle')} }, - JSON + self.test_type ) ]) eq_( @@ -2266,3 +2269,13 @@ class JSONBTest(JSONTest): class JSONBRoundTripTest(JSONRoundTripTest): __only_on__ = ('postgresql >= 9.4',) + + test_type = JSONB + + @testing.requires.postgresql_utf8_server_encoding + def test_unicode_round_trip_python(self): + super(JSONBRoundTripTest, self).test_unicode_round_trip_python() + + @testing.requires.postgresql_utf8_server_encoding + def test_unicode_round_trip_native(self): + super(JSONBRoundTripTest, self).test_unicode_round_trip_native() |
