Added filter operators

In this changeset, I refactored the DB filter system to support
comparison operators using a django-like syntax.
A filter can take 2 forms:

- "<FIELDNAME>" which is a syntactic sugar for "<FIELDNAME>__eq"
- "<FIELDNAME>__<OPERATOR>" where <OPERATOR> is the comparison operator
  to be used.

Here is the list of the supported operators:

- 'eq' (==)
- 'neq' (!=)
- 'gt' (>)
- 'gte' (>=)
- 'lt' (<)
- 'lte' (<=)
- 'in' (in)
- 'notin' (not in)

Change-Id: I53a61d50a3253342a40f0ff87cb5612ed57a3bd1
This commit is contained in:
Vincent Françoise
2016-06-06 10:07:00 +02:00
committed by David TARDIVEL
parent 7b403c0d3b
commit 77c07a466f
4 changed files with 162 additions and 196 deletions

View File

@@ -47,10 +47,12 @@ class TestDbAuditFilters(base.DbTestCase):
audit_template_id=self.audit_template.id, id=1, uuid=None)
with freezegun.freeze_time(self.FAKE_OLD_DATE):
self.audit2 = utils.create_test_audit(
audit_template_id=self.audit_template.id, id=2, uuid=None)
audit_template_id=self.audit_template.id, id=2, uuid=None,
state=audit_objects.State.FAILED)
with freezegun.freeze_time(self.FAKE_OLDER_DATE):
self.audit3 = utils.create_test_audit(
audit_template_id=self.audit_template.id, id=3, uuid=None)
audit_template_id=self.audit_template.id, id=3, uuid=None,
state=audit_objects.State.CANCELLED)
def _soft_delete_audits(self):
with freezegun.freeze_time(self.FAKE_TODAY):
@@ -225,6 +227,26 @@ class TestDbAuditFilters(base.DbTestCase):
[self.audit1['id'], self.audit2['id']],
[r.id for r in res])
def test_get_audit_list_filter_state_in(self):
res = self.dbapi.get_audit_list(
self.context,
filters={'state__in': (audit_objects.State.FAILED,
audit_objects.State.CANCELLED)})
self.assertEqual(
[self.audit2['id'], self.audit3['id']],
[r.id for r in res])
def test_get_audit_list_filter_state_notin(self):
res = self.dbapi.get_audit_list(
self.context,
filters={'state__notin': (audit_objects.State.FAILED,
audit_objects.State.CANCELLED)})
self.assertEqual(
[self.audit1['id']],
[r.id for r in res])
class DbAuditTestCase(base.DbTestCase):