attribute should match for all

This commit is contained in:
abikouo
2021-05-20 12:23:07 +02:00
parent 930c551654
commit 483c91ca22
2 changed files with 19 additions and 1 deletions

View File

@@ -44,7 +44,7 @@ def match_json_property(module, data, expr, value=None):
def _match_value(buf, v):
if isinstance(buf, list):
# convert all values from bool to str and lowercase them
return v.lower() in [str(i).lower() for i in buf]
return all([str(i).lower() == v.lower() for i in buf])
elif isinstance(buf, str):
return v.lower() == content.lower()
elif isinstance(buf, bool):

View File

@@ -60,6 +60,24 @@ def test_boolean_value():
assert match_json_property(None, data, "containers[*].connected", "TRUE")
assert match_json_property(None, data, "containers[0].poweron", "false")
data = {
"containers": [
{"image": "nginx", "ready": False},
{"image": "python", "ready": False},
{"image": "mongo", "ready": True}
]
}
assert not match_json_property(None, data, "containers[*].ready", "true")
data = {
"containers": [
{"image": "nginx", "ready": True},
{"image": "python", "ready": True},
{"image": "mongo", "ready": True}
]
}
assert match_json_property(None, data, "containers[*].ready", "true")
def test_valid_expression():
data = dict(key="ansible", value="unit-test")