From b540674a84b096d3df7dfaf8004c5f6bfa4adcc1 Mon Sep 17 00:00:00 2001 From: astacksu Date: Thu, 31 Aug 2017 11:16:42 +0800 Subject: [PATCH] Operator for start/end_timestamp changes to 'eq' start/end_timestamp originally are associated with op 'ge' and 'le'. Changing them to 'eq' fixes the bug and the usage will make more sense. Related review: https://review.openstack.org/#/c/495763 Change-Id: Ia94a499f9340102553863db48dccb96bea92ea78 Closes-Bug: #1711997 --- panko/api/controllers/v2/events.py | 14 +------------- .../functional/api/v2/test_event_scenarios.py | 12 ++++++------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/panko/api/controllers/v2/events.py b/panko/api/controllers/v2/events.py index c3e508e6..943ea5e3 100644 --- a/panko/api/controllers/v2/events.py +++ b/panko/api/controllers/v2/events.py @@ -198,24 +198,12 @@ def _event_query_to_event_filter(q): {'operator': i.op, 'supported': base.operation_kind}) raise base.ClientSideError(error) if i.field in evt_model_filter: - if i.op != 'eq' and i.field in ('event_type', 'message_id'): + if i.op != 'eq': error = (_('Operator %(operator)s is not supported. Only' ' `eq\' operator is available for field' ' %(field)s') % {'operator': i.op, 'field': i.field}) raise base.ClientSideError(error) - if i.op != 'ge' and i.field == 'start_timestamp': - error = (_('Operator %(operator)s is not supported. Only' - ' `ge\' operator is available for field' - ' %(field)s') % - {'operator': i.op, 'field': i.field}) - raise base.ClientSideError(error) - if i.op != 'le' and i.field == 'end_timestamp': - error = (_('Operator %(operator)s is not supported. Only' - ' `le\' operator is available for field' - ' %(field)s') % - {'operator': i.op, 'field': i.field}) - raise base.ClientSideError(error) evt_model_filter[i.field] = i.value else: trait_type = i.type or 'string' diff --git a/panko/tests/functional/api/v2/test_event_scenarios.py b/panko/tests/functional/api/v2/test_event_scenarios.py index 740f1972..cc33d2e8 100644 --- a/panko/tests/functional/api/v2/test_event_scenarios.py +++ b/panko/tests/functional/api/v2/test_event_scenarios.py @@ -226,7 +226,7 @@ class TestEventAPI(EventTestBase): def test_get_events_filter_start_timestamp(self): data = self.get_json(self.PATH, headers=HEADERS, q=[{'field': 'start_timestamp', - 'op': 'ge', + 'op': 'eq', 'value': '2014-01-01T00:00:00'}]) self.assertEqual(2, len(data)) sorted_types = sorted([d['event_type'] for d in data]) @@ -241,14 +241,14 @@ class TestEventAPI(EventTestBase): expect_errors=True) self.assertEqual(400, resp.status_code) self.assertEqual(u'Operator gt is not supported. Only' - ' `ge\' operator is available for field' + ' `eq\' operator is available for field' ' start_timestamp', resp.json['error_message']['faultstring']) def test_get_events_filter_end_timestamp(self): data = self.get_json(self.PATH, headers=HEADERS, q=[{'field': 'end_timestamp', - 'op': 'le', + 'op': 'eq', 'value': '2014-01-03T00:00:00'}]) self.assertEqual(3, len(data)) event_types = ['Foo', 'Bar', 'Zoo'] @@ -263,17 +263,17 @@ class TestEventAPI(EventTestBase): expect_errors=True) self.assertEqual(400, resp.status_code) self.assertEqual(u'Operator gt is not supported. Only' - ' `le\' operator is available for field' + ' `eq\' operator is available for field' ' end_timestamp', resp.json['error_message']['faultstring']) def test_get_events_filter_start_end_timestamp(self): data = self.get_json(self.PATH, headers=HEADERS, q=[{'field': 'start_timestamp', - 'op': 'ge', + 'op': 'eq', 'value': '2014-01-02T00:00:00'}, {'field': 'end_timestamp', - 'op': 'le', + 'op': 'eq', 'value': '2014-01-03T10:00:00'}]) self.assertEqual(1, len(data)) sorted_types = sorted([d['event_type'] for d in data])