mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 14:51:43 +00:00
add ability to check for service updates
This commit is contained in:
@ -0,0 +1,58 @@
|
||||
import argparse
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman import version
|
||||
from ahriman.application.handlers import ServiceUpdates
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
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.exit_code = False
|
||||
return args
|
||||
|
||||
|
||||
def test_run(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run command
|
||||
"""
|
||||
package_ahriman.version = "0.0.0"
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_aur", return_value=package_ahriman)
|
||||
application_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
|
||||
ServiceUpdates.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
package_mock.assert_called_once_with(package_ahriman.base, repository.pacman)
|
||||
application_mock.assert_called_once_with(verbose=True, separator=" -> ")
|
||||
check_mock.assert_called_once_with(args.exit_code, True)
|
||||
|
||||
|
||||
def test_run_skip(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must do not perform any actions if package is up-to-date
|
||||
"""
|
||||
package_ahriman.version = f"{version.__version__}-1"
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", return_value=package_ahriman)
|
||||
application_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
|
||||
ServiceUpdates.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_mock.assert_not_called()
|
||||
check_mock.assert_not_called()
|
@ -107,6 +107,26 @@ def test_subparsers_help_commands_unsafe_architecture(parser: argparse.ArgumentP
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_help_updates(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
help-updates command must imply architecture list, lock, report, quiet and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["help-updates"])
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert not args.report
|
||||
assert args.quiet
|
||||
assert args.unsafe
|
||||
|
||||
|
||||
def test_subparsers_help_updates_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
help-updates command must correctly parse architecture list
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "help-updates"])
|
||||
assert args.architecture == [""]
|
||||
|
||||
|
||||
def test_subparsers_help_version(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
help-version command must imply architecture, lock, report, quiet and unsafe
|
||||
|
Reference in New Issue
Block a user