kopia lustrzana https://github.com/simonw/datasette
rodzic
3863a30b5d
commit
3280972c89
|
@ -49,50 +49,49 @@ def test_custom_json_encoder(obj, expected):
|
||||||
@pytest.mark.parametrize('args,expected_where,expected_params', [
|
@pytest.mark.parametrize('args,expected_where,expected_params', [
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
'name_english__contains': ['foo'],
|
'name_english__contains': 'foo',
|
||||||
},
|
},
|
||||||
'"name_english" like :p0',
|
['"name_english" like :p0'],
|
||||||
['%foo%']
|
['%foo%']
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
'foo': ['bar'],
|
'foo': 'bar',
|
||||||
'bar__contains': ['baz'],
|
'bar__contains': 'baz',
|
||||||
},
|
},
|
||||||
'"bar" like :p0 and "foo" = :p1',
|
['"bar" like :p0', '"foo" = :p1'],
|
||||||
['%baz%', 'bar']
|
['%baz%', 'bar']
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
'foo__startswith': ['bar'],
|
'foo__startswith': 'bar',
|
||||||
'bar__endswith': ['baz'],
|
'bar__endswith': 'baz',
|
||||||
},
|
},
|
||||||
'"bar" like :p0 and "foo" like :p1',
|
['"bar" like :p0', '"foo" like :p1'],
|
||||||
['%baz', 'bar%']
|
['%baz', 'bar%']
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
'foo__lt': ['1'],
|
'foo__lt': '1',
|
||||||
'bar__gt': ['2'],
|
'bar__gt': '2',
|
||||||
'baz__gte': ['3'],
|
'baz__gte': '3',
|
||||||
'bax__lte': ['4'],
|
'bax__lte': '4',
|
||||||
},
|
},
|
||||||
'"bar" > :p0 and "bax" <= :p1 and "baz" >= :p2 and "foo" < :p3',
|
['"bar" > :p0', '"bax" <= :p1', '"baz" >= :p2', '"foo" < :p3'],
|
||||||
[2, 4, 3, 1]
|
[2, 4, 3, 1]
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
'foo__like': ['2%2'],
|
'foo__like': '2%2',
|
||||||
'zax__glob': ['3*'],
|
'zax__glob': '3*',
|
||||||
},
|
},
|
||||||
'"foo" like :p0 and "zax" glob :p1',
|
['"foo" like :p0', '"zax" glob :p1'],
|
||||||
['2%2', '3*']
|
['2%2', '3*']
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
def test_build_where(args, expected_where, expected_params):
|
def test_build_where(args, expected_where, expected_params):
|
||||||
sql_bits, actual_params = utils.build_where_clauses(args)
|
sql_bits, actual_params = utils.build_where_clauses(args)
|
||||||
actual_where = ' and '.join(sql_bits)
|
assert expected_where == sql_bits
|
||||||
assert expected_where == actual_where
|
|
||||||
assert {
|
assert {
|
||||||
'p{}'.format(i): param
|
'p{}'.format(i): param
|
||||||
for i, param in enumerate(expected_params)
|
for i, param in enumerate(expected_params)
|
||||||
|
|
Ładowanie…
Reference in New Issue