mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
add daemon subcommand
This command emulates default systemd timer and can be useful in docker container in order to run 24/7
This commit is contained in:
40
tests/ahriman/application/handlers/test_handler_daemon.py
Normal file
40
tests/ahriman/application/handlers/test_handler_daemon.py
Normal file
@ -0,0 +1,40 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.handlers import Daemon
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
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.interval = 60 * 60 * 12
|
||||
args.no_aur = False
|
||||
args.no_local = False
|
||||
args.no_manual = False
|
||||
args.no_vcs = False
|
||||
return args
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
run_mock = mocker.patch("ahriman.application.handlers.Update.run")
|
||||
start_mock = mocker.patch("threading.Timer.start")
|
||||
join_mock = mocker.patch("threading.Timer.join")
|
||||
|
||||
Daemon.run(args, "x86_64", configuration, True, False)
|
||||
Daemon._SHOULD_RUN = False
|
||||
run_mock.assert_called_once_with(args, "x86_64", configuration, True, False)
|
||||
start_mock.assert_called_once_with()
|
||||
join_mock.assert_called_once_with()
|
@ -65,6 +65,26 @@ def test_subparsers_aur_search_architecture(parser: argparse.ArgumentParser) ->
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_daemon(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
daemon command must imply dry run, exit code and package
|
||||
"""
|
||||
args = parser.parse_args(["daemon"])
|
||||
assert not args.dry_run
|
||||
assert not args.exit_code
|
||||
assert args.package == []
|
||||
|
||||
|
||||
def test_subparsers_daemon_option_interval(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
daemon command must convert interval option to int instance
|
||||
"""
|
||||
args = parser.parse_args(["daemon"])
|
||||
assert isinstance(args.interval, int)
|
||||
args = parser.parse_args(["daemon", "--interval", "10"])
|
||||
assert isinstance(args.interval, int)
|
||||
|
||||
|
||||
def test_subparsers_help(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
help command must imply architecture list, lock, no-report, quiet, unsafe and parser
|
||||
|
Reference in New Issue
Block a user