in verifiers/xmlElementMatch.py [0:0]
def testNode(cls, node, node_path, test):
result = None
if test[0] == '@':
if '=' in test:
attr, value = test[1:].split('=')
value = value[1:-1]
else:
attr = test[1:]
value = None
if attr not in node.keys():
result = " Missing attribute returned in XML for %s\n" % (node_path,)
if value is not None and node.get(attr) != value:
result = " Incorrect attribute value returned in XML for %s\n" % (node_path,)
elif test[0] == '=':
if node.text != test[1:]:
result = " Incorrect value returned in XML for %s\n" % (node_path,)
elif test[0] == '!':
if node.text == test[1:]:
result = " Incorrect value returned in XML for %s\n" % (node_path,)
elif test[0] == '*':
if node.text is None or node.text.find(test[1:]) == -1:
result = " Incorrect value returned in XML for %s\n" % (node_path,)
elif test[0] == '$':
if node.text is None or node.text.find(test[1:]) != -1:
result = " Incorrect value returned in XML for %s\n" % (node_path,)
elif test[0] == '+':
if node.text is None or not node.text.startswith(test[1:]):
result = " Incorrect value returned in XML for %s\n" % (node_path,)
elif test[0] == '^':
if "=" in test:
element, value = test[1:].split("=", 1)
else:
element = test[1:]
value = None
for child in node.getchildren():
if child.tag == element and (value is None or child.text == value):
break
else:
result = " Missing child returned in XML for %s\n" % (node_path,)
elif test[0] == '|':
if len(test) == 2 and test[1] == "|":
if node.text is None and len(node.getchildren()) == 0:
result = " Empty element returned in XML for %s\n" % (node_path,)
else:
if node.text is not None or len(node.getchildren()) != 0:
result = " Non-empty element returned in XML for %s\n" % (node_path,)
# Try to parse as iCalendar
elif test == 'icalendar':
try:
Calendar.parseText(node.text)
except:
result = " Incorrect value returned in iCalendar for %s\n" % (node_path,)
# Try to parse as JSON
elif test == 'json':
try:
json.loads(node.text)
except:
result = " Incorrect value returned in XML for %s\n" % (node_path,)
return result