dav_events.config: fixed tests and improved FieldInitial
This commit is contained in:
@@ -20,7 +20,7 @@ ADDITIONAL_COSTS_MAX_LENGTH = COMMON_CHAR_FIELD_LENGTH
|
|||||||
|
|
||||||
|
|
||||||
class FieldInitial(object):
|
class FieldInitial(object):
|
||||||
_constraint_re = re.compile(r'^(?P<field>[a-z_]+)(?P<op>[=]+)(?P<value>.*)$')
|
_constraint_re = re.compile(r'^(?P<field>[a-z_]+)(?P<op>==)(?P<value>[^= ].*)?$')
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self._tuples = []
|
self._tuples = []
|
||||||
@@ -61,8 +61,10 @@ class FieldInitial(object):
|
|||||||
if c_field not in parameters:
|
if c_field not in parameters:
|
||||||
logger.error('FieldInitial: Invalid field: \'%s\'', sub_constraint)
|
logger.error('FieldInitial: Invalid field: \'%s\'', sub_constraint)
|
||||||
continue
|
continue
|
||||||
c_op = c.group('op')
|
|
||||||
c_value = c.group('value')
|
c_value = c.group('value')
|
||||||
|
if c_value is None:
|
||||||
|
c_value = ''
|
||||||
|
c_op = c.group('op')
|
||||||
if c_op == '==':
|
if c_op == '==':
|
||||||
if parameters[c_field] == c_value:
|
if parameters[c_field] == c_value:
|
||||||
match = True
|
match = True
|
||||||
@@ -70,7 +72,7 @@ class FieldInitial(object):
|
|||||||
else:
|
else:
|
||||||
match = False
|
match = False
|
||||||
break
|
break
|
||||||
else:
|
else: # pragma: no cover
|
||||||
logger.error('FieldInitial: Invalid operator: \'%s\'', sub_constraint)
|
logger.error('FieldInitial: Invalid operator: \'%s\'', sub_constraint)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -83,8 +83,10 @@ class FieldInitialTestCase(TestCase):
|
|||||||
def test_invalid_constraints(self):
|
def test_invalid_constraints(self):
|
||||||
invalid_constraints = (
|
invalid_constraints = (
|
||||||
'sport', # Not in <key><operator><value> form
|
'sport', # Not in <key><operator><value> form
|
||||||
'sport ==hiking' # Blanks before operator
|
'sport ==hiking', # Blank before operator
|
||||||
'sport== hiking' # Blanks after operator
|
'sport== hiking', # Blank after operator
|
||||||
|
'sport=hiking', # Invalid operator
|
||||||
|
'sport===hiking', # Invalid operator
|
||||||
'sport!=hiking', # Invalid operator
|
'sport!=hiking', # Invalid operator
|
||||||
'==hiking', # Missing key
|
'==hiking', # Missing key
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user