Fix json sql tests
* Make tests deterministic * Run tests against Postgres
This commit is contained in:
@@ -9,23 +9,25 @@ class TestJSONSQL(TestCase):
|
|||||||
dns = 'postgres://postgres@localhost/sqlalchemy_utils_test'
|
dns = 'postgres://postgres@localhost/sqlalchemy_utils_test'
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('value', 'compiled'),
|
('value', 'result'),
|
||||||
(
|
(
|
||||||
(1, 'to_json(1)'),
|
(1, 1),
|
||||||
(14.14, 'to_json(14.14)'),
|
(14.14, 14.14),
|
||||||
({'a': 2, 'b': 'c'}, "json_build_object('a', 2, 'b', 'c')"),
|
({'a': 2, 'b': 'c'}, {'a': 2, 'b': 'c'}),
|
||||||
(
|
(
|
||||||
{'a': {'b': 'c'}},
|
{'a': {'b': 'c'}},
|
||||||
"json_build_object('a', json_build_object('b', 'c'))"
|
{'a': {'b': 'c'}}
|
||||||
),
|
),
|
||||||
({}, 'json_build_object()'),
|
({}, {}),
|
||||||
([1, 2], 'json_build_array(1, 2)'),
|
([1, 2], [1, 2]),
|
||||||
([], 'json_build_array()'),
|
([], []),
|
||||||
(
|
(
|
||||||
[sa.select([sa.text('1')])],
|
[sa.select([sa.text('1')]).label('alias')],
|
||||||
'json_build_array((SELECT 1))'
|
[1]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
def test_compiled_scalars(self, value, compiled):
|
def test_compiled_scalars(self, value, result):
|
||||||
assert str(json_sql(value).compile(self.connection)) == compiled
|
assert result == (
|
||||||
|
self.connection.execute(sa.select([json_sql(value)])).fetchone()[0]
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user