From 62ac15a92ace5cb600992cb76487c06644c7f1d6 Mon Sep 17 00:00:00 2001 From: xliiv Date: Thu, 20 Apr 2017 10:40:12 +0200 Subject: [PATCH] Fix `or` operator in parser (dashboard module) (#3027) 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) --- src/ralph/dashboards/filter_parser.py | 5 ++++- src/ralph/dashboards/tests/test_parser.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ralph/dashboards/filter_parser.py b/src/ralph/dashboards/filter_parser.py index b4a85068cb..e2f4f88c36 100644 --- a/src/ralph/dashboards/filter_parser.py +++ b/src/ralph/dashboards/filter_parser.py @@ -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: @@ -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_)], {} diff --git a/src/ralph/dashboards/tests/test_parser.py b/src/ralph/dashboards/tests/test_parser.py index 1323088583..4663b825e4 100644 --- a/src/ralph/dashboards/tests/test_parser.py +++ b/src/ralph/dashboards/tests/test_parser.py @@ -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))