mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
remove unused absolute path validator (#106)
Extracted path is always absolute, so there is no need to check it
This commit is contained in:
parent
95e29d16bb
commit
d9eaf17a11
@ -144,24 +144,6 @@ class Validator(RootValidator):
|
||||
if constraint and url.scheme not in 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:
|
||||
"""
|
||||
check if paths exists
|
||||
|
@ -59,8 +59,8 @@ class MirrorlistTrigger(Trigger):
|
||||
"type": "string",
|
||||
},
|
||||
"path": {
|
||||
"type": "string",
|
||||
"path_is_absolute": True,
|
||||
"type": "path",
|
||||
"coerce": "absolute_path",
|
||||
},
|
||||
"servers": {
|
||||
"type": "list",
|
||||
|
@ -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:
|
||||
"""
|
||||
must validate url correctly
|
||||
|
Loading…
Reference in New Issue
Block a user