File: test_json_sql.py

package info (click to toggle)
python-sqlalchemy-utils 0.30.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,056 kB
  • sloc: python: 10,350; makefile: 160
file content (33 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pytest
import sqlalchemy as sa

from sqlalchemy_utils import json_sql
from tests import TestCase


class TestJSONSQL(TestCase):
    dns = 'postgres://postgres@localhost/sqlalchemy_utils_test'

    @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, value, result):
        assert result == (
            self.connection.execute(sa.select([json_sql(value)])).fetchone()[0]
        )