From: Mike Bayer Date: Wed, 6 Jan 2016 18:18:04 +0000 (-0500) Subject: - add a few JSON tests specific to MySQL, including basic reflection X-Git-Tag: rel_1_1_0b1~84^2~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93d71b80f25408a91644a9daf817ba4f0984f0bd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add a few JSON tests specific to MySQL, including basic reflection --- diff --git a/test/dialect/mysql/test_types.py b/test/dialect/mysql/test_types.py index 7c279ffbf6..1fb152377a 100644 --- a/test/dialect/mysql/test_types.py +++ b/test/dialect/mysql/test_types.py @@ -1,6 +1,6 @@ # coding: utf-8 -from sqlalchemy.testing import eq_, assert_raises, assert_raises_message +from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, is_ from sqlalchemy import * from sqlalchemy import sql, exc, schema from sqlalchemy.util import u @@ -10,6 +10,7 @@ from sqlalchemy.testing import fixtures, AssertsCompiledSQL, AssertsExecutionRes from sqlalchemy import testing import datetime import decimal +from sqlalchemy import types as sqltypes class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): @@ -602,6 +603,49 @@ class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): eq_(colspec(table.c.y5), 'y5 YEAR(4)') +class JSONTest(fixtures.TestBase): + __requires__ = ('json_type', ) + __only_on__ = 'mysql' + __backend__ = True + + @testing.provide_metadata + def test_reflection(self): + + Table( + 'mysql_json', self.metadata, + Column('foo', mysql.JSON) + ) + self.metadata.create_all() + + reflected = Table('mysql_json', MetaData(), autoload_with=testing.db) + is_(reflected.c.foo.type._type_affinity, sqltypes.JSON) + assert isinstance(reflected.c.foo.type, mysql.JSON) + + @testing.provide_metadata + def test_rudimental_round_trip(self): + # note that test_suite has many more JSON round trip tests + # using the backend-agnostic JSON type + + mysql_json = Table( + 'mysql_json', self.metadata, + Column('foo', mysql.JSON) + ) + self.metadata.create_all() + + value = { + 'json': {'foo': 'bar'}, + 'recs': ['one', 'two'] + } + + with testing.db.connect() as conn: + conn.execute(mysql_json.insert(), foo=value) + + eq_( + conn.scalar(select([mysql_json.c.foo])), + value + ) + + class EnumSetTest( fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):