exp.set('sort_by', 'title') # for clarity (already default)
self.check_json_get('/conditions?sort_by=foo&pattern=bar&foo=x', exp)
# test non-empty result, automatic (positive) sorting by title
+ exp.set('pattern', '')
post_cond1 = {'is_active': 0, 'title': 'foo', 'description': 'oof'}
post_cond2 = {'is_active': 0, 'title': 'bar', 'description': 'rab'}
post_cond3 = {'is_active': 1, 'title': 'baz', 'description': 'zab'}
for i, post in enumerate([post_cond1, post_cond2, post_cond3]):
self.post_exp_cond([exp], i+1, post, '', f'?id={i+1}')
- exp.set('pattern', '')
- exp.force('conditions', [2, 3, 1])
- self.check_json_get('/conditions', exp)
+ self.check_filter(exp, 'conditions', 'sort_by', 'title', [2, 3, 1])
# test other sortings
- exp.set('sort_by', '-title')
- exp.force('conditions', [1, 3, 2])
- self.check_json_get('/conditions?sort_by=-title', exp)
- exp.set('sort_by', 'is_active')
- exp.force('conditions', [1, 2, 3])
- self.check_json_get('/conditions?sort_by=is_active', exp)
- exp.set('sort_by', '-is_active')
- exp.force('conditions', [3, 2, 1])
- self.check_json_get('/conditions?sort_by=-is_active', exp)
+ self.check_filter(exp, 'conditions', 'sort_by', '-title', [1, 3, 2])
+ self.check_filter(exp, 'conditions', 'sort_by', 'is_active', [1, 2, 3])
+ self.check_filter(exp, 'conditions', 'sort_by', '-is_active',
+ [3, 2, 1])
# test pattern matching on title
exp.set('sort_by', 'title')
- exp.set('pattern', 'ba')
- exp.force('conditions', [2, 3])
exp.lib_del('Condition', 1)
- self.check_json_get('/conditions?pattern=ba', exp)
+ self.check_filter(exp, 'conditions', 'pattern', 'ba', [2, 3])
# test pattern matching on description
- exp.set('pattern', 'of')
exp.lib_wipe('Condition')
exp.set_cond_from_post(1, post_cond1)
- exp.force('conditions', [1])
- self.check_json_get('/conditions?pattern=of', exp)
+ self.check_filter(exp, 'conditions', 'pattern', 'of', [1])
# test on meaningless non-empty params (incl. entirely un-used key),
# that 'sort_by' default to 'title' (even if set to something else, as
# long as without handler) and 'pattern' get preserved
- exp.set('pattern', 'bar') # preserved despite zero effect!
+ exp.set('pattern', 'bar')
url = '/processes?sort_by=foo&pattern=bar&foo=x'
self.check_json_get(url, exp)
# test non-empty result, automatic (positive) sorting by title
exp.lib_set('ProcessStep', [exp.procstep_as_dict(1, 2, 1),
exp.procstep_as_dict(2, 3, 1),
exp.procstep_as_dict(3, 3, 2)])
- exp.lib_get('Process', '')
exp.set('pattern', '')
- exp.force('processes', [2, 3, 1])
- self.check_json_get('/processes', exp)
+ self.check_filter(exp, 'processes', 'sort_by', 'title', [2, 3, 1])
# test other sortings
- exp.set('sort_by', '-title')
- exp.force('processes', [1, 3, 2])
- self.check_json_get('/processes?sort_by=-title', exp)
- exp.set('sort_by', 'effort')
- exp.force('processes', [3, 1, 2])
- self.check_json_get('/processes?sort_by=effort', exp)
- exp.set('sort_by', '-effort')
- exp.force('processes', [2, 1, 3])
- self.check_json_get('/processes?sort_by=-effort', exp)
- exp.set('sort_by', 'steps')
- exp.force('processes', [1, 2, 3])
- self.check_json_get('/processes?sort_by=steps', exp)
- exp.set('sort_by', '-steps')
- exp.force('processes', [3, 2, 1])
- self.check_json_get('/processes?sort_by=-steps', exp)
- exp.set('sort_by', 'owners')
- exp.force('processes', [3, 2, 1])
- self.check_json_get('/processes?sort_by=owners', exp)
- exp.set('sort_by', '-owners')
- exp.force('processes', [1, 2, 3])
- self.check_json_get('/processes?sort_by=-owners', exp)
+ self.check_filter(exp, 'processes', 'sort_by', '-title', [1, 3, 2])
+ self.check_filter(exp, 'processes', 'sort_by', 'effort', [3, 1, 2])
+ self.check_filter(exp, 'processes', 'sort_by', '-effort', [2, 1, 3])
+ self.check_filter(exp, 'processes', 'sort_by', 'steps', [1, 2, 3])
+ self.check_filter(exp, 'processes', 'sort_by', '-steps', [3, 2, 1])
+ self.check_filter(exp, 'processes', 'sort_by', 'owners', [3, 2, 1])
+ self.check_filter(exp, 'processes', 'sort_by', '-owners', [1, 2, 3])
# test pattern matching on title
- exp.set('pattern', 'ba')
exp.set('sort_by', 'title')
exp.lib_del('Process', '1')
- exp.force('processes', [2, 3])
- self.check_json_get('/processes?pattern=ba', exp)
+ self.check_filter(exp, 'processes', 'pattern', 'ba', [2, 3])
# test pattern matching on description
- exp.set('pattern', 'of')
exp.lib_wipe('Process')
exp.lib_wipe('ProcessStep')
self.post_exp_process([exp], {'description': 'oof', 'effort': 1.0}, 1)
- exp.force('processes', [1])
- self.check_json_get('/processes?pattern=of', exp)
+ self.check_filter(exp, 'processes', 'pattern', 'of', [1])