mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 18:59:56 +00:00
add raises note
Also change behaviour of the `from_option` method to fallback to disabled instead of raising exception on unknown option
This commit is contained in:
@ -6,7 +6,6 @@ from pytest_mock import MockerFixture
|
||||
from ahriman.application.ahriman import _parser
|
||||
from ahriman.application.handlers import UnsafeCommands
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import ExitCode
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
@ -53,19 +52,22 @@ def test_run_check(args: argparse.Namespace, configuration: Configuration, mocke
|
||||
check_mock.assert_called_once_with("clean", ["command"], pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_check_unsafe() -> None:
|
||||
def test_check_unsafe(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must check if command is unsafe
|
||||
"""
|
||||
with pytest.raises(ExitCode):
|
||||
UnsafeCommands.check_unsafe("repo-clean", ["repo-clean"], _parser())
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_if_empty")
|
||||
UnsafeCommands.check_unsafe("repo-clean", ["repo-clean"], _parser())
|
||||
check_mock.assert_called_once_with(True, True)
|
||||
|
||||
|
||||
def test_check_unsafe_safe() -> None:
|
||||
def test_check_unsafe_safe(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must check if command is safe
|
||||
"""
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_if_empty")
|
||||
UnsafeCommands.check_unsafe("package-status", ["repo-clean"], _parser())
|
||||
check_mock.assert_called_once_with(True, False)
|
||||
|
||||
|
||||
def test_get_unsafe_commands() -> None:
|
||||
|
@ -220,7 +220,7 @@ def database(configuration: Configuration) -> SQLite:
|
||||
database fixture
|
||||
|
||||
Args:
|
||||
configuration(Configuration):
|
||||
configuration(Configuration): configuration fixture
|
||||
|
||||
Returns:
|
||||
SQLite: database test instance
|
||||
|
@ -4,6 +4,7 @@ import requests
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
from ahriman.models.sign_settings import SignSettings
|
||||
|
||||
@ -63,6 +64,18 @@ def test_sign_command(gpg_with_key: GPG) -> None:
|
||||
assert gpg_with_key.sign_command(Path("a"), gpg_with_key.default_key)
|
||||
|
||||
|
||||
def test_sign_options(configuration: Configuration) -> None:
|
||||
"""
|
||||
must correctly parse sign options
|
||||
"""
|
||||
configuration.set_option("sign", "target", "repository disabled")
|
||||
configuration.set_option("sign", "key", "default-key")
|
||||
|
||||
target, default_key = GPG.sign_options(configuration)
|
||||
assert target == {SignSettings.Repository}
|
||||
assert default_key == "default-key"
|
||||
|
||||
|
||||
def test_key_download(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must download the key from public server
|
||||
|
@ -1,15 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.exceptions import InvalidOption
|
||||
from ahriman.models.auth_settings import AuthSettings
|
||||
|
||||
|
||||
def test_from_option_invalid() -> None:
|
||||
"""
|
||||
must raise exception on invalid option
|
||||
return disabled on invalid option
|
||||
"""
|
||||
with pytest.raises(InvalidOption, match=".* `invalid`$"):
|
||||
AuthSettings.from_option("invalid")
|
||||
assert AuthSettings.from_option("invalid") == AuthSettings.Disabled
|
||||
|
||||
|
||||
def test_from_option_valid() -> None:
|
||||
|
@ -1,15 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.exceptions import InvalidOption
|
||||
from ahriman.models.report_settings import ReportSettings
|
||||
|
||||
|
||||
def test_from_option_invalid() -> None:
|
||||
"""
|
||||
must raise exception on invalid option
|
||||
must return disabled on invalid option
|
||||
"""
|
||||
with pytest.raises(InvalidOption, match=".* `invalid`$"):
|
||||
ReportSettings.from_option("invalid")
|
||||
assert ReportSettings.from_option("invalid") == ReportSettings.Disabled
|
||||
|
||||
|
||||
def test_from_option_valid() -> None:
|
||||
|
@ -1,15 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.exceptions import InvalidOption
|
||||
from ahriman.models.sign_settings import SignSettings
|
||||
|
||||
|
||||
def test_from_option_invalid() -> None:
|
||||
"""
|
||||
must raise exception on invalid option
|
||||
must return disabled on invalid option
|
||||
"""
|
||||
with pytest.raises(InvalidOption, match=".* `invalid`$"):
|
||||
SignSettings.from_option("invalid")
|
||||
assert SignSettings.from_option("invalid") == SignSettings.Disabled
|
||||
|
||||
|
||||
def test_from_option_valid() -> None:
|
||||
|
@ -1,15 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.exceptions import InvalidOption
|
||||
from ahriman.models.upload_settings import UploadSettings
|
||||
|
||||
|
||||
def test_from_option_invalid() -> None:
|
||||
"""
|
||||
must raise exception on invalid option
|
||||
must return disabled on invalid option
|
||||
"""
|
||||
with pytest.raises(InvalidOption, match=".* `invalid`$"):
|
||||
UploadSettings.from_option("invalid")
|
||||
assert UploadSettings.from_option("invalid") == UploadSettings.Disabled
|
||||
|
||||
|
||||
def test_from_option_valid() -> None:
|
||||
|
Reference in New Issue
Block a user