mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
feat: add ability to run multiple commands on success
This commit is contained in:
66
tests/ahriman/application/handlers/test_handler_run.py
Normal file
66
tests/ahriman/application/handlers/test_handler_run.py
Normal file
@ -0,0 +1,66 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.ahriman import _parser
|
||||
from ahriman.application.handlers import Run
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import ExitCode
|
||||
|
||||
|
||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
"""
|
||||
default arguments for these test cases
|
||||
|
||||
Args:
|
||||
args(argparse.Namespace): command line arguments fixture
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.command = ["help"]
|
||||
args.parser = _parser
|
||||
return args
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Run.run_command")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Run.run(args, repository_id, configuration, report=False)
|
||||
application_mock.assert_called_once_with(["help"], pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_run_failed(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run commands until success
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.command = ["help", "config"]
|
||||
application_mock = mocker.patch("ahriman.application.handlers.Run.run_command", return_value=False)
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
with pytest.raises(ExitCode):
|
||||
Run.run(args, repository_id, configuration, report=False)
|
||||
application_mock.assert_called_once_with(["help"], pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_run_command(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly run external command
|
||||
"""
|
||||
execute_mock = mocker.patch("ahriman.application.handlers.Help.execute")
|
||||
Run.run_command(["help"], _parser())
|
||||
execute_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_disallow_multi_architecture_run() -> None:
|
||||
"""
|
||||
must not allow multi architecture run
|
||||
"""
|
||||
assert not Run.ALLOW_MULTI_ARCHITECTURE_RUN
|
@ -1060,6 +1060,34 @@ def test_subparsers_service_repositories_option_repository(parser: argparse.Argu
|
||||
assert args.repository == ""
|
||||
|
||||
|
||||
def test_subparsers_service_run(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
service-run command must imply architecture, lock, report, repository and parser
|
||||
"""
|
||||
args = parser.parse_args(["service-run", "help"])
|
||||
assert args.architecture == ""
|
||||
assert args.lock is None
|
||||
assert not args.report
|
||||
assert args.repository == ""
|
||||
assert args.parser is not None and args.parser()
|
||||
|
||||
|
||||
def test_subparsers_service_run_option_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
service-run command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "service-run", "help"])
|
||||
assert args.architecture == ""
|
||||
|
||||
|
||||
def test_subparsers_service_run_option_repository(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
service-run command must correctly parse repository list
|
||||
"""
|
||||
args = parser.parse_args(["-r", "repo", "service-run", "help"])
|
||||
assert args.repository == ""
|
||||
|
||||
|
||||
def test_subparsers_service_setup(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
service-setup command must imply lock, quiet, report and unsafe
|
||||
|
Reference in New Issue
Block a user