Merge "Fixes the use of dates when listing images"

This commit is contained in:
Jenkins 2016-06-14 12:20:51 +00:00 committed by Gerrit Code Review
commit 3adf8cc6dd
2 changed files with 22 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import six
from webob import exc
from glance.common import exception
from glance.common import timeutils
from glance.i18n import _, _LE, _LW
CONF = cfg.CONF
@ -603,8 +604,17 @@ def split_filter_op(expression):
"""
left, sep, right = expression.partition(':')
if sep:
op = left
threshold = right
# If the expression is a date of the format ISO 8601 like
# CCYY-MM-DDThh:mm:ss+hh:mm and has no operator, it should
# not be partitioned, and a default operator of eq should be
# assumed.
try:
timeutils.parse_isotime(expression)
op = 'eq'
threshold = expression
except ValueError:
op = left
threshold = right
else:
op = 'eq' # default operator
threshold = left

View File

@ -450,6 +450,16 @@ class SplitFilterOpTestCase(test_utils.BaseTestCase):
returned = utils.split_filter_op(expr)
self.assertEqual(('eq', expr), returned)
def test_default_operator_with_datetime(self):
expr = '2015-08-27T09:49:58Z'
returned = utils.split_filter_op(expr)
self.assertEqual(('eq', expr), returned)
def test_operator_with_datetime(self):
expr = 'lt:2015-08-27T09:49:58Z'
returned = utils.split_filter_op(expr)
self.assertEqual(('lt', '2015-08-27T09:49:58Z'), returned)
class EvaluateFilterOpTestCase(test_utils.BaseTestCase):