mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
* add external process spawner and update test cases * pass no_report to handlers * provide service api endpoints * do not spawn process for single architecture run * pass no report to handlers * make _call method of handlers public and also simplify process spawn * move update under add * implement actions from web page * clear logging & improve l&f
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import argparse
|
|
|
|
from pytest_mock import MockerFixture
|
|
|
|
from ahriman.application.application import Application
|
|
from ahriman.application.handlers import Update
|
|
from ahriman.core.configuration import Configuration
|
|
|
|
|
|
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
|
"""
|
|
default arguments for these test cases
|
|
:param args: command line arguments fixture
|
|
:return: generated arguments for these test cases
|
|
"""
|
|
args.package = []
|
|
args.dry_run = False
|
|
args.no_aur = 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)
|
|
mocker.patch("pathlib.Path.mkdir")
|
|
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
|
updates_mock = mocker.patch("ahriman.application.application.Application.get_updates")
|
|
|
|
Update.run(args, "x86_64", configuration, True)
|
|
application_mock.assert_called_once()
|
|
updates_mock.assert_called_once()
|
|
|
|
|
|
def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
|
"""
|
|
must run simplified command
|
|
"""
|
|
args = _default_args(args)
|
|
args.dry_run = True
|
|
mocker.patch("pathlib.Path.mkdir")
|
|
updates_mock = mocker.patch("ahriman.application.application.Application.get_updates")
|
|
|
|
Update.run(args, "x86_64", configuration, True)
|
|
updates_mock.assert_called_once()
|
|
|
|
|
|
def test_log_fn(application: Application, mocker: MockerFixture) -> None:
|
|
"""
|
|
must print package updates
|
|
"""
|
|
logger_mock = mocker.patch("logging.Logger.info")
|
|
Update.log_fn(application, False)("hello")
|
|
logger_mock.assert_called_once()
|