Add unit test and conditional formatting for ?field__isnull

pull/107/head
Ray N 2017-11-16 03:59:09 +00:00
rodzic cdaa111e28
commit 4ea861538d
2 zmienionych plików z 16 dodań i 3 usunięć

Wyświetl plik

@ -57,11 +57,15 @@ def build_where_clauses(args):
converted = value_convert(value)
if lookup in numeric_operators and converted.isdigit():
converted = int(converted)
param_id = 'p{}'.format(i)
if ':{}' in template:
param_id = 'p{}'.format(i)
params[param_id] = converted
tokens = (column, param_id)
else:
tokens = (column,)
sql_bits.append(
template.format(column, param_id)
template.format(*tokens)
)
params[param_id] = converted
return sql_bits, params

Wyświetl plik

@ -88,6 +88,15 @@ def test_custom_json_encoder(obj, expected):
['"foo" like :p0', '"zax" glob :p1'],
['2%2', '3*']
),
(
{
'foo__isnull': '1',
'baz__isnull': '1',
'bar__gt': '10'
},
['"bar" > :p0', '"baz" is null', '"foo" is null'],
[10]
),
])
def test_build_where(args, expected_where, expected_params):
sql_bits, actual_params = utils.build_where_clauses(args)