Skip to content

Commit

Permalink
Fix or operator in parser (dashboard module) (#3027)
Browse files Browse the repository at this point in the history
Fix `or` op. and test execution.
The error are:
- overlapping names of tests (2 tests called `test_process_value`)
- value passed to `_filter_operator` is string which cause using `,` as value (replaced string with list)
  • Loading branch information
xliiv committed Apr 20, 2017
1 parent 5d405a8 commit 62ac15a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/ralph/dashboards/filter_parser.py
Expand Up @@ -11,6 +11,8 @@

class FilterParser(object):

or_sep = ','

def __init__(self, queryset, filters_dict, exclude_mode=False):
self.filters = filters_dict
if exclude_mode:
Expand Down Expand Up @@ -40,7 +42,8 @@ def _filter_operator(self, key, value, op):
return reduce(op, [Q(**{key: v}) for v in value])

def filter_or(self, key, value):
return [self._filter_operator(key, value, operator.or_)], {}
norm_val = value.split(self.or_sep)
return [self._filter_operator(key, norm_val, operator.or_)], {}

def filter_and(self, key, value):
return [self._filter_operator(key, value, operator.and_)], {}
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/dashboards/tests/test_parser.py
Expand Up @@ -48,7 +48,7 @@ def test_process_value(self, value, expect):
(['1'], Q(key='1')),
(['1', '2'], Q(key='1') & Q(key='2')),
)
def test_process_value(self, value, expect):
def test_process_value_as_list(self, value, expect):
result = self.parser.filter_and('key', value)
self.assertEqual(str(result[ARGS][0]), str(expect))

Expand Down

0 comments on commit 62ac15a

Please sign in to comment.