dav_events.config: fixed tests and improved FieldInitial

This commit is contained in:
2026-06-11 16:17:35 +02:00
parent 8ddabd3189
commit 9c513b3dee
2 changed files with 9 additions and 5 deletions
+5 -3
View File
@@ -20,7 +20,7 @@ ADDITIONAL_COSTS_MAX_LENGTH = COMMON_CHAR_FIELD_LENGTH
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):
self._tuples = []
@@ -61,8 +61,10 @@ class FieldInitial(object):
if c_field not in parameters:
logger.error('FieldInitial: Invalid field: \'%s\'', sub_constraint)
continue
c_op = c.group('op')
c_value = c.group('value')
if c_value is None:
c_value = ''
c_op = c.group('op')
if c_op == '==':
if parameters[c_field] == c_value:
match = True
@@ -70,7 +72,7 @@ class FieldInitial(object):
else:
match = False
break
else:
else: # pragma: no cover
logger.error('FieldInitial: Invalid operator: \'%s\'', sub_constraint)
continue
else:
+4 -2
View File
@@ -83,8 +83,10 @@ class FieldInitialTestCase(TestCase):
def test_invalid_constraints(self):
invalid_constraints = (
'sport', # Not in <key><operator><value> form
'sport ==hiking' # Blanks before operator
'sport== hiking' # Blanks after operator
'sport ==hiking', # Blank before operator
'sport== hiking', # Blank after operator
'sport=hiking', # Invalid operator
'sport===hiking', # Invalid operator
'sport!=hiking', # Invalid operator
'==hiking', # Missing key
)