Changed checks to accept ints for expected values.

(In the configuration)
This commit is contained in:
Alexis Métaireau 2023-10-18 12:32:33 +02:00
parent 0ea9ad4c6e
commit e437f48b34
2 changed files with 12 additions and 3 deletions

View file

@ -56,6 +56,8 @@ def parse_checks(value):
if name not in available_names: if name not in available_names:
msg = f"Check should be one of f{available_names}. ({name} given)" msg = f"Check should be one of f{available_names}. ({name} given)"
raise ValueError(msg) raise ValueError(msg)
if isinstance(expected, int):
expected = str(expected)
return (name, expected) return (name, expected)

View file

@ -18,16 +18,23 @@ def test_ssl_duration_parsing():
def test_path_parsing_transforms_to_tuples(): def test_path_parsing_transforms_to_tuples():
data = {"path": "/", "checks": [{"body-contains": "youpi"}, {"status-is": 200}]} data = {"path": "/", "checks": [{"body-contains": "youpi"}, {"status-is": "200"}]}
path = WebsitePath(**data) path = WebsitePath(**data)
assert len(path.checks) == 2 assert len(path.checks) == 2
assert path.checks == [("body-contains", "youpi"), ("status-is", 200)] assert path.checks == [("body-contains", "youpi"), ("status-is", "200")]
def test_path_ensures_check_exists(): def test_path_ensures_check_exists():
with pytest.raises(ValueError): with pytest.raises(ValueError):
erroneous_data = { erroneous_data = {
"path": "/", "path": "/",
"checks": [{"non-existing-key": "youpi"}, {"status-is": 200}], "checks": [{"non-existing-key": "youpi"}, {"status-is": "200"}],
} }
WebsitePath(**erroneous_data) WebsitePath(**erroneous_data)
def test_expected_accepts_and_convert_ints():
data = {"path": "/", "checks": [{"body-contains": "youpi"}, {"status-is": 200}]}
path = WebsitePath(**data)
assert len(path.checks) == 2
assert path.checks == [("body-contains", "youpi"), ("status-is", "200")]