server/search: fix searching for invalid numbers
This commit is contained in:
parent
1034362b84
commit
a72f6aa585
|
@ -38,6 +38,7 @@ class BaseSearchConfig(object):
|
||||||
'''
|
'''
|
||||||
Decorate SQLAlchemy filter on given column using supplied criterion.
|
Decorate SQLAlchemy filter on given column using supplied criterion.
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
if isinstance(criterion, criteria.PlainSearchCriterion):
|
if isinstance(criterion, criteria.PlainSearchCriterion):
|
||||||
expr = column == int(criterion.value)
|
expr = column == int(criterion.value)
|
||||||
elif isinstance(criterion, criteria.ArraySearchCriterion):
|
elif isinstance(criterion, criteria.ArraySearchCriterion):
|
||||||
|
@ -54,6 +55,9 @@ class BaseSearchConfig(object):
|
||||||
expr = column <= int(criterion.max_value)
|
expr = column <= int(criterion.max_value)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
except ValueError as e:
|
||||||
|
raise errors.SearchError(
|
||||||
|
'Criterion value %r must be a number.' % (criterion,))
|
||||||
if criterion.negated:
|
if criterion.negated:
|
||||||
expr = ~expr
|
expr = ~expr
|
||||||
return expr
|
return expr
|
||||||
|
|
|
@ -134,7 +134,9 @@ def test_filter_by_edit_time(
|
||||||
('post-count:2', ['t1']),
|
('post-count:2', ['t1']),
|
||||||
('post-count:1', ['t2']),
|
('post-count:1', ['t2']),
|
||||||
('post-count:1..', ['t1', 't2']),
|
('post-count:1..', ['t1', 't2']),
|
||||||
|
('post-count-min:1', ['t1', 't2']),
|
||||||
('post-count:..1', ['t2']),
|
('post-count:..1', ['t2']),
|
||||||
|
('post-count-max:1', ['t2']),
|
||||||
('usage-count:2', ['t1']),
|
('usage-count:2', ['t1']),
|
||||||
('usage-count:1', ['t2']),
|
('usage-count:1', ['t2']),
|
||||||
('usages:2', ['t1']),
|
('usages:2', ['t1']),
|
||||||
|
@ -153,6 +155,19 @@ def test_filter_by_post_count(
|
||||||
post2.tags.append(tag1)
|
post2.tags.append(tag1)
|
||||||
verify_unpaged(input, expected_tag_names)
|
verify_unpaged(input, expected_tag_names)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('input', [
|
||||||
|
'post-count:..',
|
||||||
|
'post-count:asd',
|
||||||
|
'post-count:asd,1',
|
||||||
|
'post-count:1,asd',
|
||||||
|
'post-count:asd..1',
|
||||||
|
'post-count:1..asd',
|
||||||
|
])
|
||||||
|
def test_filter_by_invalid_input(executor, input):
|
||||||
|
with pytest.raises(errors.SearchError):
|
||||||
|
actual_count, actual_posts = executor.execute(
|
||||||
|
input, page=1, page_size=100)
|
||||||
|
|
||||||
@pytest.mark.parametrize('input,expected_tag_names', [
|
@pytest.mark.parametrize('input,expected_tag_names', [
|
||||||
('suggestion-count:2', ['t1']),
|
('suggestion-count:2', ['t1']),
|
||||||
('suggestion-count:1', ['t2']),
|
('suggestion-count:1', ['t2']),
|
||||||
|
|
Loading…
Reference in New Issue