diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-08 23:34:20 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-08 23:52:51 -0400 |
commit | 104e6907284e602a8485f32fc67fd6af0c00e4d0 (patch) | |
tree | fd628fbc353341fa31953b5f55be98b9748e6bea /test/dialect/test_sqlite.py | |
parent | d8da7f5ac544f3dd853a221faa5fab4ff788e25b (diff) | |
download | sqlalchemy-104e6907284e602a8485f32fc67fd6af0c00e4d0.tar.gz |
Correct name for json_serializer / json_deserializer, document and test
The dialects that support json are supposed to take arguments
``json_serializer`` and ``json_deserializer`` at the create_engine() level,
however the SQLite dialect calls them ``_json_serilizer`` and
``_json_deserilalizer``. The names have been corrected, the old names are
accepted with a change warning, and these parameters are now documented as
:paramref:`.create_engine.json_serializer` and
:paramref:`.create_engine.json_deserializer`.
Fixes: #4798
Change-Id: I1dbfe439b421fe9bb7ff3594ef455af8156f8851
Diffstat (limited to 'test/dialect/test_sqlite.py')
-rw-r--r-- | test/dialect/test_sqlite.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index e72700510..1e894da55 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -2,6 +2,7 @@ """SQLite-specific tests.""" import datetime +import json import os from sqlalchemy import and_ @@ -318,6 +319,35 @@ class JSONTest(fixtures.TestBase): conn.scalar(select([sqlite_json.c.foo["json"]])), value["json"] ) + @testing.provide_metadata + def test_deprecated_serializer_args(self): + sqlite_json = Table( + "json_test", self.metadata, Column("foo", sqlite.JSON) + ) + data_element = {"foo": "bar"} + + js = mock.Mock(side_effect=json.dumps) + jd = mock.Mock(side_effect=json.loads) + + with testing.expect_deprecated( + "The _json_deserializer argument to the SQLite " + "dialect has been renamed", + "The _json_serializer argument to the SQLite " + "dialect has been renamed", + ): + engine = engines.testing_engine( + options=dict(_json_serializer=js, _json_deserializer=jd) + ) + self.metadata.create_all(engine) + + engine.execute(sqlite_json.insert(), {"foo": data_element}) + + row = engine.execute(select([sqlite_json.c.foo])).first() + + eq_(row, (data_element,)) + eq_(js.mock_calls, [mock.call(data_element)]) + eq_(jd.mock_calls, [mock.call(json.dumps(data_element))]) + class DateTimeTest(fixtures.TestBase, AssertsCompiledSQL): def test_time_microseconds(self): |