remove unused absolute path validator (#106)

Extracted path is always absolute, so there is no need to check it
This commit is contained in:
Evgenii Alekseev 2023-08-13 20:48:07 +03:00
parent 9259d9c727
commit 573ade4ba5
3 changed files with 2 additions and 44 deletions

View File

@ -144,24 +144,6 @@ class Validator(RootValidator):
if constraint and url.scheme not in constraint: if constraint and url.scheme not in constraint:
self._error(field, f"Url {value} scheme must be one of {constraint}") self._error(field, f"Url {value} scheme must be one of {constraint}")
def _validate_path_is_absolute(self, constraint: bool, field: str, value: Path) -> None:
"""
check if path is absolute or not
Args:
constraint(bool): True in case if path must be absolute and False if it must be relative
field(str): field name to be checked
value(Path): value to be checked
Examples:
The rule's arguments are validated against this schema:
{"type": "boolean"}
"""
if constraint and not value.is_absolute():
self._error(field, f"Path {value} must be absolute")
if not constraint and value.is_absolute():
self._error(field, f"Path {value} must be relative")
def _validate_path_exists(self, constraint: bool, field: str, value: Path) -> None: def _validate_path_exists(self, constraint: bool, field: str, value: Path) -> None:
""" """
check if paths exists check if paths exists

View File

@ -59,8 +59,8 @@ class MirrorlistTrigger(Trigger):
"type": "string", "type": "string",
}, },
"path": { "path": {
"type": "string", "type": "path",
"path_is_absolute": True, "coerce": "absolute_path",
}, },
"servers": { "servers": {
"type": "list", "type": "list",

View File

@ -73,30 +73,6 @@ def test_validate_is_ip_address(validator: Validator, mocker: MockerFixture) ->
]) ])
def test_validate_path_is_absolute(validator: Validator, mocker: MockerFixture) -> None:
"""
must validate that path is absolute
"""
error_mock = mocker.patch("ahriman.core.configuration.validator.Validator._error")
mocker.patch("pathlib.Path.is_absolute", return_value=False)
validator._validate_path_is_absolute(False, "field", Path("1"))
mocker.patch("pathlib.Path.is_absolute", return_value=True)
validator._validate_path_is_absolute(False, "field", Path("2"))
mocker.patch("pathlib.Path.is_absolute", return_value=False)
validator._validate_path_is_absolute(True, "field", Path("3"))
mocker.patch("pathlib.Path.is_absolute", return_value=True)
validator._validate_path_is_absolute(True, "field", Path("4"))
error_mock.assert_has_calls([
MockCall("field", "Path 2 must be relative"),
MockCall("field", "Path 3 must be absolute"),
])
def test_validate_is_url(validator: Validator, mocker: MockerFixture) -> None: def test_validate_is_url(validator: Validator, mocker: MockerFixture) -> None:
""" """
must validate url correctly must validate url correctly