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'
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('value', 'compiled'),
|
||||
('value', 'result'),
|
||||
(
|
||||
(1, 'to_json(1)'),
|
||||
(14.14, 'to_json(14.14)'),
|
||||
({'a': 2, 'b': 'c'}, "json_build_object('a', 2, 'b', 'c')"),
|
||||
(1, 1),
|
||||
(14.14, 14.14),
|
||||
({'a': 2, 'b': 'c'}, {'a': 2, '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)'),
|
||||
([], 'json_build_array()'),
|
||||
({}, {}),
|
||||
([1, 2], [1, 2]),
|
||||
([], []),
|
||||
(
|
||||
[sa.select([sa.text('1')])],
|
||||
'json_build_array((SELECT 1))'
|
||||
[sa.select([sa.text('1')]).label('alias')],
|
||||
[1]
|
||||
)
|
||||
)
|
||||
)
|
||||
def test_compiled_scalars(self, value, compiled):
|
||||
assert str(json_sql(value).compile(self.connection)) == compiled
|
||||
def test_compiled_scalars(self, value, result):
|
||||
assert result == (
|
||||
self.connection.execute(sa.select([json_sql(value)])).fetchone()[0]
|
||||
)
|
||||
|
Reference in New Issue
Block a user