mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
e7e50875d3
commit
e06b011771
2 changed files with 12 additions and 9 deletions
|
|
@ -393,7 +393,7 @@ def path_from_row_pks(row, pks, use_rowid):
|
||||||
def build_where_clause(args):
|
def build_where_clause(args):
|
||||||
sql_bits = []
|
sql_bits = []
|
||||||
params = {}
|
params = {}
|
||||||
for i, (key, values) in enumerate(args.items()):
|
for i, (key, values) in enumerate(sorted(args.items())):
|
||||||
if '__' in key:
|
if '__' in key:
|
||||||
column, lookup = key.rsplit('__', 1)
|
column, lookup = key.rsplit('__', 1)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ def test_compound_pks_from_path(path, expected):
|
||||||
({'A': 123}, ['A'], '123'),
|
({'A': 123}, ['A'], '123'),
|
||||||
])
|
])
|
||||||
def test_path_from_row_pks(row, pks, expected_path):
|
def test_path_from_row_pks(row, pks, expected_path):
|
||||||
actual_path = app.path_from_row_pks(row, pks)
|
actual_path = app.path_from_row_pks(row, pks, False)
|
||||||
assert expected_path == actual_path
|
assert expected_path == actual_path
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ def test_custom_json_encoder(obj, expected):
|
||||||
{
|
{
|
||||||
'name_english__contains': ['foo'],
|
'name_english__contains': ['foo'],
|
||||||
},
|
},
|
||||||
'"name_english" like ?',
|
'"name_english" like :p0',
|
||||||
['%foo%']
|
['%foo%']
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
|
@ -55,7 +55,7 @@ def test_custom_json_encoder(obj, expected):
|
||||||
'foo': ['bar'],
|
'foo': ['bar'],
|
||||||
'bar__contains': ['baz'],
|
'bar__contains': ['baz'],
|
||||||
},
|
},
|
||||||
'"bar" like ? and "foo" = ?',
|
'"bar" like :p0 and "foo" = :p1',
|
||||||
['%baz%', 'bar']
|
['%baz%', 'bar']
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
|
@ -63,7 +63,7 @@ def test_custom_json_encoder(obj, expected):
|
||||||
'foo__startswith': ['bar'],
|
'foo__startswith': ['bar'],
|
||||||
'bar__endswith': ['baz'],
|
'bar__endswith': ['baz'],
|
||||||
},
|
},
|
||||||
'"bar" like ? and "foo" like ?',
|
'"bar" like :p0 and "foo" like :p1',
|
||||||
['%baz', 'bar%']
|
['%baz', 'bar%']
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
|
@ -73,22 +73,25 @@ def test_custom_json_encoder(obj, expected):
|
||||||
'baz__gte': ['3'],
|
'baz__gte': ['3'],
|
||||||
'bax__lte': ['4'],
|
'bax__lte': ['4'],
|
||||||
},
|
},
|
||||||
'"bar" > ? and "bax" <= ? and "baz" >= ? and "foo" < ?',
|
'"bar" > :p0 and "bax" <= :p1 and "baz" >= :p2 and "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 ? and "zax" glob ?',
|
'"foo" like :p0 and "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):
|
||||||
actual_where, actual_params = app.build_where_clause(args)
|
actual_where, actual_params = app.build_where_clause(args)
|
||||||
assert expected_where == actual_where
|
assert expected_where == actual_where
|
||||||
assert expected_params == actual_params
|
assert {
|
||||||
|
'p{}'.format(i): param
|
||||||
|
for i, param in enumerate(expected_params)
|
||||||
|
} == actual_params
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('bad_sql', [
|
@pytest.mark.parametrize('bad_sql', [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue