From 22c40a4d2c2b004393839c0735327fd2e6c7bd9e Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Sun, 11 Jan 2015 16:53:33 +0200 Subject: [PATCH] Fix json sql tests * Make tests deterministic * Run tests against Postgres --- tests/functions/test_json_sql.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/functions/test_json_sql.py b/tests/functions/test_json_sql.py index 5833dc9..7faf313 100644 --- a/tests/functions/test_json_sql.py +++ b/tests/functions/test_json_sql.py @@ -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] + )