argos/tests/test_schemas_config.py
Alexis Métaireau 43e1767002 Refactor check config vlidation
- Refactored the `get_check_by_name` method to `get_registered_check` in the
  BaseCheck class and added a `get_registered_checks` method to get all the
  registered checks.
- Added a validation in the `WebsitePath` class to ensure that a check exists
  when parsing the configuration file.
- Updated the existing test for parsing SSL duration and added new tests to
  validate path parsing and check existence validation.
2023-10-10 10:04:46 +02:00

32 lines
1 KiB
Python

import pytest
from argos.schemas.config import SSL, WebsitePath
def test_ssl_duration_parsing():
data = {"thresholds": [{"2d": "warning"}, {"3w": "error"}]}
# Test the validation and parsing of SSL model
ssl_object = SSL(**data)
assert len(ssl_object.thresholds) == 2
assert ssl_object.thresholds == [(2, "warning"), (21, "error")]
# Test the constraint on severity
with pytest.raises(ValueError):
erroneous_data = {"thresholds": [{"1d": "caution"}, {"1w": "danger"}]}
SSL(**erroneous_data)
def test_path_parsing():
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)]
def test_path_ensures_check_exists():
with pytest.raises(ValueError):
erroneous_data = {
"path": "/",
"checks": [{"non-existing-key": "youpi"}, {"status-is": 200}],
}
WebsitePath(**erroneous_data)