Files
deb-python-sqlalchemy-utils/tests/functions/test_json_sql.py
Jacob Magnusson 815f07d6c1 Use pytest fixtures to reduce complexity and repetition
Also:

Allow override of database name and user in tests (important for me as I would have to mess with my PSQL and MySQL database users otherwise)
Use dict.items instead of six.iteritems as it sporadically caused RuntimeError: dictionary changed size during iteration in Python 2.6 tests.
Fix typo DNS to DSN
Adds Python 3.5 to tox.ini
Added an .editorconfig
Import babel.dates in sqlalchemy_utils.i18n as an exception would be raised when using the latest versions of babel.
2016-01-19 10:52:30 +01:00

33 lines
793 B
Python

import pytest
import sqlalchemy as sa
from sqlalchemy_utils import json_sql
@pytest.mark.usefixtures('postgresql_dsn')
class TestJSONSQL(object):
@pytest.mark.parametrize(
('value', 'result'),
(
(1, 1),
(14.14, 14.14),
({'a': 2, 'b': 'c'}, {'a': 2, 'b': 'c'}),
(
{'a': {'b': 'c'}},
{'a': {'b': 'c'}}
),
({}, {}),
([1, 2], [1, 2]),
([], []),
(
[sa.select([sa.text('1')]).label('alias')],
[1]
)
)
)
def test_compiled_scalars(self, connection, value, result):
assert result == (
connection.execute(sa.select([json_sql(value)])).fetchone()[0]
)