mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-11-04 07:43:42 +00:00 
			
		
		
		
	Docstring update (#58)
* migrate docstrings from reST to google format * add raises note Also change behaviour of the `from_option` method to fallback to disabled instead of raising exception on unknown option * fix part of warnings for sphinx * make identation a bit more readable * review fixes * add verbose description for properties to make them parsed by sphinx extenstion * add demo sphinx generator
This commit is contained in:
		@ -13,10 +13,14 @@ from ahriman.core.database.sqlite import SQLite
 | 
			
		||||
def application_packages(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Packages:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for application with package functions
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Packages: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
@ -27,10 +31,14 @@ def application_packages(configuration: Configuration, database: SQLite, mocker:
 | 
			
		||||
def application_properties(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Properties:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for application with properties only
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Properties: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
@ -41,10 +49,14 @@ def application_properties(configuration: Configuration, database: SQLite, mocke
 | 
			
		||||
def application_repository(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Repository:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for application with repository functions
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Repository: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
 | 
			
		||||
@ -14,10 +14,14 @@ from ahriman.core.database.sqlite import SQLite
 | 
			
		||||
def application(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Application:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for application
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Application: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
@ -28,7 +32,9 @@ def application(configuration: Configuration, database: SQLite, mocker: MockerFi
 | 
			
		||||
def args() -> argparse.Namespace:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for command line arguments
 | 
			
		||||
    :return: command line arguments test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: command line arguments test instance
 | 
			
		||||
    """
 | 
			
		||||
    return argparse.Namespace(architecture=None, lock=None, force=False, unsafe=False, no_report=True)
 | 
			
		||||
 | 
			
		||||
@ -37,9 +43,13 @@ def args() -> argparse.Namespace:
 | 
			
		||||
def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for file lock
 | 
			
		||||
    :param args: command line arguments fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: file lock test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Lock: file lock test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Lock(args, "x86_64", configuration)
 | 
			
		||||
 | 
			
		||||
@ -48,6 +58,8 @@ def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
 | 
			
		||||
def parser() -> argparse.ArgumentParser:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for command line arguments parser
 | 
			
		||||
    :return: command line arguments parser test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.ArgumentParser: command line arguments parser test instance
 | 
			
		||||
    """
 | 
			
		||||
    return _parser()
 | 
			
		||||
 | 
			
		||||
@ -13,8 +13,12 @@ from ahriman.models.result import Result
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.exit_code = False
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,12 @@ from ahriman.models.repository_paths import RepositoryPaths
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.path = Path("result.tar.gz")
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.cache = False
 | 
			
		||||
    args.chroot = False
 | 
			
		||||
 | 
			
		||||
@ -10,8 +10,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.parser = _parser
 | 
			
		||||
    args.command = None
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.key = "0xE989490C"
 | 
			
		||||
    args.key_server = "pgp.mit.edu"
 | 
			
		||||
 | 
			
		||||
@ -13,8 +13,12 @@ from ahriman.models.package import Package
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.package = "ahriman"
 | 
			
		||||
    args.exit_code = False
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.models.result import Result
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.depends_on = []
 | 
			
		||||
    args.dry_run = False
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
@ -10,8 +10,12 @@ from ahriman.models.package import Package
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.dry_run = False
 | 
			
		||||
    args.info = False
 | 
			
		||||
 | 
			
		||||
@ -10,8 +10,12 @@ from ahriman.models.result import Result
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.target = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
@ -11,8 +11,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.path = Path("result.tar.gz")
 | 
			
		||||
    args.output = Path.cwd()
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.models.aur_package import AURPackage
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.search = ["ahriman"]
 | 
			
		||||
    args.exit_code = False
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.models.sign_settings import SignSettings
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.build_as_user = "ahriman"
 | 
			
		||||
    args.build_command = "ahriman"
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,12 @@ from ahriman.models.package import Package
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.ahriman = True
 | 
			
		||||
    args.exit_code = False
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,12 @@ from ahriman.models.package import Package
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.package = None
 | 
			
		||||
    args.action = Action.Update
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.target = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
@ -6,14 +6,17 @@ 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:
 | 
			
		||||
    """
 | 
			
		||||
    default arguments for these test cases
 | 
			
		||||
    :param args: command line arguments fixture
 | 
			
		||||
    :return: generated arguments for these test cases
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.parser = _parser
 | 
			
		||||
    args.command = None
 | 
			
		||||
@ -49,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:
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.models.result import Result
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.dry_run = False
 | 
			
		||||
 | 
			
		||||
@ -16,8 +16,12 @@ from ahriman.models.user_access import UserAccess
 | 
			
		||||
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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.username = "user"
 | 
			
		||||
    args.action = Action.Update
 | 
			
		||||
 | 
			
		||||
@ -10,8 +10,12 @@ 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:
 | 
			
		||||
        args(argparse.Namespace): command line arguments fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        argparse.Namespace: generated arguments for these test cases
 | 
			
		||||
    """
 | 
			
		||||
    args.parser = lambda: True
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
@ -30,20 +30,25 @@ T = TypeVar("T")
 | 
			
		||||
def anyvar(cls: Type[T], strict: bool = False) -> T:
 | 
			
		||||
    """
 | 
			
		||||
    any value helper for mocker calls check
 | 
			
		||||
    :param cls: type class
 | 
			
		||||
    :param strict: if True then check type of supplied argument
 | 
			
		||||
    :return: any wrapper
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        strict(bool, optional): if True then check type of supplied argument (Default value = False)
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        T: any wrapper
 | 
			
		||||
    """
 | 
			
		||||
    class AnyVar(cls):
 | 
			
		||||
        """
 | 
			
		||||
        any value wrapper
 | 
			
		||||
        """
 | 
			
		||||
        """any value wrapper"""
 | 
			
		||||
 | 
			
		||||
        def __eq__(self, other: Any) -> bool:
 | 
			
		||||
            """
 | 
			
		||||
            compare object to other
 | 
			
		||||
            :param other: other object to compare
 | 
			
		||||
            :return: True in case if objects are equal
 | 
			
		||||
 | 
			
		||||
            Args:
 | 
			
		||||
                other(Any): other object to compare
 | 
			
		||||
 | 
			
		||||
            Returns:
 | 
			
		||||
                bool: True in case if objects are equal
 | 
			
		||||
            """
 | 
			
		||||
            return not strict or isinstance(other, cls)
 | 
			
		||||
 | 
			
		||||
@ -54,8 +59,12 @@ def anyvar(cls: Type[T], strict: bool = False) -> T:
 | 
			
		||||
def get_package_status(package: Package) -> Dict[str, Any]:
 | 
			
		||||
    """
 | 
			
		||||
    helper to extract package status from package
 | 
			
		||||
    :param package: package object
 | 
			
		||||
    :return: simplified package status map (with only status and view)
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package(Package): package object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Dict[str, Any]: simplified package status map (with only status and view)
 | 
			
		||||
    """
 | 
			
		||||
    return {"status": BuildStatusEnum.Unknown.value, "package": package.view()}
 | 
			
		||||
 | 
			
		||||
@ -64,8 +73,12 @@ def get_package_status(package: Package) -> Dict[str, Any]:
 | 
			
		||||
def get_package_status_extended(package: Package) -> Dict[str, Any]:
 | 
			
		||||
    """
 | 
			
		||||
    helper to extract package status from package
 | 
			
		||||
    :param package: package object
 | 
			
		||||
    :return: full package status map (with timestamped build status and view)
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package(Package): package object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Dict[str, Any]: full package status map (with timestamped build status and view)
 | 
			
		||||
    """
 | 
			
		||||
    return {"status": BuildStatus().view(), "package": package.view()}
 | 
			
		||||
 | 
			
		||||
@ -75,7 +88,9 @@ def get_package_status_extended(package: Package) -> Dict[str, Any]:
 | 
			
		||||
def aur_package_ahriman() -> AURPackage:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for AUR package
 | 
			
		||||
    :return: AUR package test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        AURPackage: AUR package test instance
 | 
			
		||||
    """
 | 
			
		||||
    return AURPackage(
 | 
			
		||||
        id=1009791,
 | 
			
		||||
@ -128,7 +143,9 @@ def aur_package_ahriman() -> AURPackage:
 | 
			
		||||
def aur_package_akonadi() -> AURPackage:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for AUR package
 | 
			
		||||
    :return: AUR package test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        AURPackage: AUR package test instance
 | 
			
		||||
    """
 | 
			
		||||
    return AURPackage(
 | 
			
		||||
        id=0,
 | 
			
		||||
@ -172,8 +189,12 @@ def aur_package_akonadi() -> AURPackage:
 | 
			
		||||
def auth(configuration: Configuration) -> Auth:
 | 
			
		||||
    """
 | 
			
		||||
    auth provider fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: auth service instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Auth: auth service instance
 | 
			
		||||
    """
 | 
			
		||||
    return Auth(configuration)
 | 
			
		||||
 | 
			
		||||
@ -182,8 +203,12 @@ def auth(configuration: Configuration) -> Auth:
 | 
			
		||||
def configuration(resource_path_root: Path) -> Configuration:
 | 
			
		||||
    """
 | 
			
		||||
    configuration fixture
 | 
			
		||||
    :param resource_path_root: resource path root directory
 | 
			
		||||
    :return: configuration test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        resource_path_root(Path): resource path root directory
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Configuration: configuration test instance
 | 
			
		||||
    """
 | 
			
		||||
    path = resource_path_root / "core" / "ahriman.ini"
 | 
			
		||||
    return Configuration.from_path(path=path, architecture="x86_64", quiet=False)
 | 
			
		||||
@ -193,8 +218,12 @@ def configuration(resource_path_root: Path) -> Configuration:
 | 
			
		||||
def database(configuration: Configuration) -> SQLite:
 | 
			
		||||
    """
 | 
			
		||||
    database fixture
 | 
			
		||||
    :param: configuration: configuration fixture
 | 
			
		||||
    :return: database test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        SQLite: database test instance
 | 
			
		||||
    """
 | 
			
		||||
    database = SQLite.load(configuration)
 | 
			
		||||
    yield database
 | 
			
		||||
@ -205,8 +234,12 @@ def database(configuration: Configuration) -> SQLite:
 | 
			
		||||
def package_ahriman(package_description_ahriman: PackageDescription) -> Package:
 | 
			
		||||
    """
 | 
			
		||||
    package fixture
 | 
			
		||||
    :param package_description_ahriman: description fixture
 | 
			
		||||
    :return: package test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_description_ahriman(PackageDescription): description fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Package: package test instance
 | 
			
		||||
    """
 | 
			
		||||
    packages = {"ahriman": package_description_ahriman}
 | 
			
		||||
    return Package(
 | 
			
		||||
@ -222,9 +255,13 @@ def package_python_schedule(
 | 
			
		||||
        package_description_python2_schedule: PackageDescription) -> Package:
 | 
			
		||||
    """
 | 
			
		||||
    multi package fixture
 | 
			
		||||
    :param package_description_python_schedule: description fixture
 | 
			
		||||
    :param package_description_python2_schedule: description fixture
 | 
			
		||||
    :return: multi package test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_description_python_schedule(PackageDescription): description fixture
 | 
			
		||||
        package_description_python2_schedule(PackageDescription): description fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Package: multi package test instance
 | 
			
		||||
    """
 | 
			
		||||
    packages = {
 | 
			
		||||
        "python-schedule": package_description_python_schedule,
 | 
			
		||||
@ -241,7 +278,9 @@ def package_python_schedule(
 | 
			
		||||
def package_description_ahriman() -> PackageDescription:
 | 
			
		||||
    """
 | 
			
		||||
    package description fixture
 | 
			
		||||
    :return: package description test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        PackageDescription: package description test instance
 | 
			
		||||
    """
 | 
			
		||||
    return PackageDescription(
 | 
			
		||||
        architecture="x86_64",
 | 
			
		||||
@ -267,7 +306,9 @@ def package_description_ahriman() -> PackageDescription:
 | 
			
		||||
def package_description_python_schedule() -> PackageDescription:
 | 
			
		||||
    """
 | 
			
		||||
    package description fixture
 | 
			
		||||
    :return: package description test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        PackageDescription: package description test instance
 | 
			
		||||
    """
 | 
			
		||||
    return PackageDescription(
 | 
			
		||||
        architecture="x86_64",
 | 
			
		||||
@ -286,7 +327,9 @@ def package_description_python_schedule() -> PackageDescription:
 | 
			
		||||
def package_description_python2_schedule() -> PackageDescription:
 | 
			
		||||
    """
 | 
			
		||||
    package description fixture
 | 
			
		||||
    :return: package description test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        PackageDescription: package description test instance
 | 
			
		||||
    """
 | 
			
		||||
    return PackageDescription(
 | 
			
		||||
        architecture="x86_64",
 | 
			
		||||
@ -305,8 +348,12 @@ def package_description_python2_schedule() -> PackageDescription:
 | 
			
		||||
def repository_paths(configuration: Configuration) -> RepositoryPaths:
 | 
			
		||||
    """
 | 
			
		||||
    repository paths fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: repository paths test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        RepositoryPaths: repository paths test instance
 | 
			
		||||
    """
 | 
			
		||||
    return configuration.repository_paths
 | 
			
		||||
 | 
			
		||||
@ -315,8 +362,12 @@ def repository_paths(configuration: Configuration) -> RepositoryPaths:
 | 
			
		||||
def result(package_ahriman: Package) -> Result:
 | 
			
		||||
    """
 | 
			
		||||
    result fixture
 | 
			
		||||
    :param package_ahriman: package fixture
 | 
			
		||||
    :return: result test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_ahriman(Package): package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Result: result test instance
 | 
			
		||||
    """
 | 
			
		||||
    result = Result()
 | 
			
		||||
    result.add_success(package_ahriman)
 | 
			
		||||
@ -327,8 +378,12 @@ def result(package_ahriman: Package) -> Result:
 | 
			
		||||
def spawner(configuration: Configuration) -> Spawn:
 | 
			
		||||
    """
 | 
			
		||||
    spawner fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: spawner fixture
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Spawn: spawner fixture
 | 
			
		||||
    """
 | 
			
		||||
    return Spawn(MagicMock(), "x86_64", configuration)
 | 
			
		||||
 | 
			
		||||
@ -337,7 +392,9 @@ def spawner(configuration: Configuration) -> Spawn:
 | 
			
		||||
def user() -> User:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for user descriptor
 | 
			
		||||
    :return: user descriptor instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        User: user descriptor instance
 | 
			
		||||
    """
 | 
			
		||||
    return User("user", "pa55w0rd", UserAccess.Read)
 | 
			
		||||
 | 
			
		||||
@ -346,10 +403,14 @@ def user() -> User:
 | 
			
		||||
def watcher(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Watcher:
 | 
			
		||||
    """
 | 
			
		||||
    package status watcher fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: package status watcher test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Watcher: package status watcher test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    return Watcher("x86_64", configuration, database)
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,9 @@ from ahriman.core.alpm.remote.remote import Remote
 | 
			
		||||
def aur() -> AUR:
 | 
			
		||||
    """
 | 
			
		||||
    aur helper fixture
 | 
			
		||||
    :return: aur helper instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        AUR: aur helper instance
 | 
			
		||||
    """
 | 
			
		||||
    return AUR()
 | 
			
		||||
 | 
			
		||||
@ -18,7 +20,9 @@ def aur() -> AUR:
 | 
			
		||||
def official() -> Official:
 | 
			
		||||
    """
 | 
			
		||||
    official repository fixture
 | 
			
		||||
    :return: official repository helper instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Official: official repository helper instance
 | 
			
		||||
    """
 | 
			
		||||
    return Official()
 | 
			
		||||
 | 
			
		||||
@ -27,6 +31,8 @@ def official() -> Official:
 | 
			
		||||
def remote() -> Remote:
 | 
			
		||||
    """
 | 
			
		||||
    official repository fixture
 | 
			
		||||
    :return: official repository helper instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Remote: official repository helper instance
 | 
			
		||||
    """
 | 
			
		||||
    return Remote()
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.models.aur_package import AURPackage
 | 
			
		||||
def _get_response(resource_path_root: Path) -> str:
 | 
			
		||||
    """
 | 
			
		||||
    load response from resource file
 | 
			
		||||
    :param resource_path_root: path to resource root
 | 
			
		||||
    :return: response text
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        resource_path_root(Path): path to resource root
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        str: response text
 | 
			
		||||
    """
 | 
			
		||||
    return (resource_path_root / "models" / "package_ahriman_aur").read_text()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.models.aur_package import AURPackage
 | 
			
		||||
def _get_response(resource_path_root: Path) -> str:
 | 
			
		||||
    """
 | 
			
		||||
    load response from resource file
 | 
			
		||||
    :param resource_path_root: path to resource root
 | 
			
		||||
    :return: response text
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        resource_path_root(Path): path to resource root
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        str: response text
 | 
			
		||||
    """
 | 
			
		||||
    return (resource_path_root / "models" / "package_akonadi_aur").read_text()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -10,9 +10,13 @@ from ahriman.core.database.sqlite import SQLite
 | 
			
		||||
def mapping(configuration: Configuration, database: SQLite) -> Mapping:
 | 
			
		||||
    """
 | 
			
		||||
    auth provider fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :return: auth service instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Mapping: auth service instance
 | 
			
		||||
    """
 | 
			
		||||
    return Mapping(configuration, database)
 | 
			
		||||
 | 
			
		||||
@ -21,9 +25,13 @@ def mapping(configuration: Configuration, database: SQLite) -> Mapping:
 | 
			
		||||
def oauth(configuration: Configuration, database: SQLite) -> OAuth:
 | 
			
		||||
    """
 | 
			
		||||
    OAuth provider fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :return: OAuth2 service instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        OAuth: OAuth2 service instance
 | 
			
		||||
    """
 | 
			
		||||
    configuration.set("web", "address", "https://example.com")
 | 
			
		||||
    return OAuth(configuration, database)
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,6 @@ import pytest
 | 
			
		||||
 | 
			
		||||
from ahriman.core.alpm.pacman import Pacman
 | 
			
		||||
from ahriman.core.alpm.repo import Repo
 | 
			
		||||
from ahriman.core.auth.auth import Auth
 | 
			
		||||
from ahriman.core.build_tools.task import Task
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
from ahriman.core.tree import Leaf
 | 
			
		||||
@ -14,8 +13,12 @@ from ahriman.models.repository_paths import RepositoryPaths
 | 
			
		||||
def leaf_ahriman(package_ahriman: Package) -> Leaf:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for tree leaf with package
 | 
			
		||||
    :param package_ahriman: package fixture
 | 
			
		||||
    :return: tree leaf test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_ahriman(Package): package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Leaf: tree leaf test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Leaf(package_ahriman, set())
 | 
			
		||||
 | 
			
		||||
@ -24,8 +27,12 @@ def leaf_ahriman(package_ahriman: Package) -> Leaf:
 | 
			
		||||
def leaf_python_schedule(package_python_schedule: Package) -> Leaf:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for tree leaf with package
 | 
			
		||||
    :param package_python_schedule: package fixture
 | 
			
		||||
    :return: tree leaf test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_python_schedule(Package): package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Leaf: tree leaf test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Leaf(package_python_schedule, set())
 | 
			
		||||
 | 
			
		||||
@ -34,8 +41,12 @@ def leaf_python_schedule(package_python_schedule: Package) -> Leaf:
 | 
			
		||||
def pacman(configuration: Configuration) -> Pacman:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for pacman wrapper
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: pacman wrapper test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Pacman: pacman wrapper test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Pacman(configuration)
 | 
			
		||||
 | 
			
		||||
@ -44,9 +55,13 @@ def pacman(configuration: Configuration) -> Pacman:
 | 
			
		||||
def repo(configuration: Configuration, repository_paths: RepositoryPaths) -> Repo:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for repository wrapper
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param repository_paths: repository paths fixture
 | 
			
		||||
    :return: repository wrapper test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        repository_paths(RepositoryPaths): repository paths fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Repo: repository wrapper test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Repo(configuration.get("repository", "name"), repository_paths, [])
 | 
			
		||||
 | 
			
		||||
@ -55,9 +70,13 @@ def repo(configuration: Configuration, repository_paths: RepositoryPaths) -> Rep
 | 
			
		||||
def task_ahriman(package_ahriman: Package, configuration: Configuration, repository_paths: RepositoryPaths) -> Task:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for built task
 | 
			
		||||
    :param package_ahriman: package fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param repository_paths: repository paths fixture
 | 
			
		||||
    :return: built task test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_ahriman(Package): package fixture
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        repository_paths(RepositoryPaths): repository paths fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Task: built task test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Task(package_ahriman, configuration, repository_paths)
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,8 @@ from unittest.mock import MagicMock
 | 
			
		||||
def connection() -> Connection:
 | 
			
		||||
    """
 | 
			
		||||
    mock object for sqlite3 connection
 | 
			
		||||
    :return: sqlite3 connection test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Connection: sqlite3 connection test instance
 | 
			
		||||
    """
 | 
			
		||||
    return MagicMock()
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,11 @@ from ahriman.core.database.migrations import Migrations
 | 
			
		||||
def migrations(connection: Connection) -> Migrations:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for migrations object
 | 
			
		||||
    :param connection: sqlite connection fixture
 | 
			
		||||
    :return: migrations test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        connection(Connection): sqlite connection fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Migrations: migrations test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Migrations(connection)
 | 
			
		||||
 | 
			
		||||
@ -17,8 +17,12 @@ from ahriman.models.user import User
 | 
			
		||||
def aur_package_ahriman_printer(aur_package_ahriman: AURPackage) -> AurPrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for AUR package printer
 | 
			
		||||
    :param aur_package_ahriman: AUR package fixture
 | 
			
		||||
    :return: AUR package printer test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        aur_package_ahriman(AURPackage): AUR package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        AurPrinter: AUR package printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return AurPrinter(aur_package_ahriman)
 | 
			
		||||
 | 
			
		||||
@ -27,7 +31,9 @@ def aur_package_ahriman_printer(aur_package_ahriman: AURPackage) -> AurPrinter:
 | 
			
		||||
def configuration_printer() -> ConfigurationPrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for configuration printer
 | 
			
		||||
    :return: configuration printer test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        ConfigurationPrinter: configuration printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return ConfigurationPrinter("section", {"key_one": "value_one", "key_two": "value_two"})
 | 
			
		||||
 | 
			
		||||
@ -36,8 +42,12 @@ def configuration_printer() -> ConfigurationPrinter:
 | 
			
		||||
def package_ahriman_printer(package_ahriman: Package) -> PackagePrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for package printer
 | 
			
		||||
    :param package_ahriman: package fixture
 | 
			
		||||
    :return: package printer test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_ahriman(Package): package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        PackagePrinter: package printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return PackagePrinter(package_ahriman, BuildStatus())
 | 
			
		||||
 | 
			
		||||
@ -46,7 +56,9 @@ def package_ahriman_printer(package_ahriman: Package) -> PackagePrinter:
 | 
			
		||||
def status_printer() -> StatusPrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for build status printer
 | 
			
		||||
    :return: build status printer test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        StatusPrinter: build status printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return StatusPrinter(BuildStatus())
 | 
			
		||||
 | 
			
		||||
@ -55,7 +67,9 @@ def status_printer() -> StatusPrinter:
 | 
			
		||||
def string_printer() -> StringPrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for any string printer
 | 
			
		||||
    :return: any string printer test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        StringPrinter: any string printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return StringPrinter("hello, world")
 | 
			
		||||
 | 
			
		||||
@ -64,7 +78,12 @@ def string_printer() -> StringPrinter:
 | 
			
		||||
def update_printer(package_ahriman: Package) -> UpdatePrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for build status printer
 | 
			
		||||
    :return: build status printer test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_ahriman(Package): package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        UpdatePrinter: build status printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return UpdatePrinter(package_ahriman, None)
 | 
			
		||||
 | 
			
		||||
@ -73,7 +92,11 @@ def update_printer(package_ahriman: Package) -> UpdatePrinter:
 | 
			
		||||
def user_printer(user: User) -> UserPrinter:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for user printer
 | 
			
		||||
    :param user: user fixture
 | 
			
		||||
    :return: user printer test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        user(User): user fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        UserPrinter: user printer test instance
 | 
			
		||||
    """
 | 
			
		||||
    return UserPrinter(user)
 | 
			
		||||
 | 
			
		||||
@ -15,10 +15,14 @@ from ahriman.core.repository.update_handler import UpdateHandler
 | 
			
		||||
def cleaner(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Cleaner:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for cleaner
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: cleaner test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Cleaner: cleaner test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    return Cleaner("x86_64", configuration, database, no_report=True, unsafe=False)
 | 
			
		||||
@ -28,10 +32,14 @@ def cleaner(configuration: Configuration, database: SQLite, mocker: MockerFixtur
 | 
			
		||||
def executor(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Executor:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for executor
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: executor test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Executor: executor test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
 | 
			
		||||
    mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_chroot")
 | 
			
		||||
@ -45,10 +53,14 @@ def executor(configuration: Configuration, database: SQLite, mocker: MockerFixtu
 | 
			
		||||
def repository(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> Repository:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for repository
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: repository test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Repository: repository test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
    return Repository("x86_64", configuration, database, no_report=True, unsafe=False)
 | 
			
		||||
@ -58,9 +70,13 @@ def repository(configuration: Configuration, database: SQLite, mocker: MockerFix
 | 
			
		||||
def properties(configuration: Configuration, database: SQLite) -> Properties:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for properties
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :return: properties test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Properties: properties test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Properties("x86_64", configuration, database, no_report=True, unsafe=False)
 | 
			
		||||
 | 
			
		||||
@ -69,10 +85,14 @@ def properties(configuration: Configuration, database: SQLite) -> Properties:
 | 
			
		||||
def update_handler(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> UpdateHandler:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for update handler
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: update handler test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        UpdateHandler: update handler test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
 | 
			
		||||
    mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_chroot")
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,9 @@ from ahriman.core.repository.cleaner import Cleaner
 | 
			
		||||
def _mock_clear(mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    mocker helper for clear function
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.iterdir", return_value=[Path("a"), Path("b"), Path("c")])
 | 
			
		||||
    mocker.patch("shutil.rmtree")
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,12 @@ from ahriman.core.sign.gpg import GPG
 | 
			
		||||
def gpg(configuration: Configuration) -> GPG:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for empty GPG
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: GPG test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        GPG: GPG test instance
 | 
			
		||||
    """
 | 
			
		||||
    return GPG("x86_64", configuration)
 | 
			
		||||
 | 
			
		||||
@ -18,8 +22,12 @@ def gpg(configuration: Configuration) -> GPG:
 | 
			
		||||
def gpg_with_key(gpg: GPG) -> GPG:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for correct GPG
 | 
			
		||||
    :param gpg: empty GPG fixture
 | 
			
		||||
    :return: GPG test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        gpg(GPG): empty GPG fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        GPG: GPG test instance
 | 
			
		||||
    """
 | 
			
		||||
    gpg.default_key = "key"
 | 
			
		||||
    return gpg
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -5,12 +5,13 @@ from ahriman.core.status.client import Client
 | 
			
		||||
from ahriman.core.status.web_client import WebClient
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# fixtures
 | 
			
		||||
@pytest.fixture
 | 
			
		||||
def client() -> Client:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for dummy client
 | 
			
		||||
    :return: dummy client test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Client: dummy client test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Client()
 | 
			
		||||
 | 
			
		||||
@ -19,8 +20,12 @@ def client() -> Client:
 | 
			
		||||
def web_client(configuration: Configuration) -> WebClient:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for web client
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: web client test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        WebClient: web client test instance
 | 
			
		||||
    """
 | 
			
		||||
    configuration.set("web", "port", "8080")
 | 
			
		||||
    return WebClient(configuration)
 | 
			
		||||
 | 
			
		||||
@ -17,8 +17,12 @@ _s3_object = namedtuple("s3_object", ["key", "e_tag", "delete"])
 | 
			
		||||
def github(configuration: Configuration) -> Github:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for github synchronization
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: github test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Github: github test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Github("x86_64", configuration, "github:x86_64")
 | 
			
		||||
 | 
			
		||||
@ -27,7 +31,9 @@ def github(configuration: Configuration) -> Github:
 | 
			
		||||
def github_release() -> Dict[str, Any]:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for the github release object
 | 
			
		||||
    :return: github test release object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Dict[str, Any]: github test release object
 | 
			
		||||
    """
 | 
			
		||||
    return {
 | 
			
		||||
        "url": "release_url",
 | 
			
		||||
@ -47,8 +53,12 @@ def github_release() -> Dict[str, Any]:
 | 
			
		||||
def rsync(configuration: Configuration) -> Rsync:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for rsync synchronization
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: rsync test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Rsync: rsync test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Rsync("x86_64", configuration, "rsync")
 | 
			
		||||
 | 
			
		||||
@ -57,8 +67,12 @@ def rsync(configuration: Configuration) -> Rsync:
 | 
			
		||||
def s3(configuration: Configuration) -> S3:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for S3 synchronization
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :return: S3 test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        S3: S3 test instance
 | 
			
		||||
    """
 | 
			
		||||
    return S3("x86_64", configuration, "customs3")
 | 
			
		||||
 | 
			
		||||
@ -67,7 +81,9 @@ def s3(configuration: Configuration) -> S3:
 | 
			
		||||
def s3_remote_objects() -> List[_s3_object]:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for boto3 like S3 objects
 | 
			
		||||
    :return: boto3 like S3 objects test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        List[_s3_object]: boto3 like S3 objects test instance
 | 
			
		||||
    """
 | 
			
		||||
    delete_mock = MagicMock()
 | 
			
		||||
    return list(map(lambda item: _s3_object(f"x86_64/{item}", f"\"{item}\"", delete_mock), ["a", "b", "c"]))
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,9 @@ from ahriman.models.user_identity import UserIdentity
 | 
			
		||||
def build_status_failed() -> BuildStatus:
 | 
			
		||||
    """
 | 
			
		||||
    build result fixture with failed status
 | 
			
		||||
    :return: failed build status test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        BuildStatus: failed build status test instance
 | 
			
		||||
    """
 | 
			
		||||
    return BuildStatus(BuildStatusEnum.Failed, 42)
 | 
			
		||||
 | 
			
		||||
@ -25,7 +27,9 @@ def build_status_failed() -> BuildStatus:
 | 
			
		||||
def counters() -> Counters:
 | 
			
		||||
    """
 | 
			
		||||
    counters fixture
 | 
			
		||||
    :return: counters test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Counters: counters test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Counters(total=10,
 | 
			
		||||
                    unknown=1,
 | 
			
		||||
@ -39,8 +43,12 @@ def counters() -> Counters:
 | 
			
		||||
def internal_status(counters: Counters) -> InternalStatus:
 | 
			
		||||
    """
 | 
			
		||||
    internal status fixture
 | 
			
		||||
    :param counters: counters fixture
 | 
			
		||||
    :return: internal status test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        counters(Counters): counters fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        InternalStatus: internal status test instance
 | 
			
		||||
    """
 | 
			
		||||
    return InternalStatus(architecture="x86_64",
 | 
			
		||||
                          packages=counters,
 | 
			
		||||
@ -52,7 +60,9 @@ def internal_status(counters: Counters) -> InternalStatus:
 | 
			
		||||
def package_tpacpi_bat_git() -> Package:
 | 
			
		||||
    """
 | 
			
		||||
    git package fixture
 | 
			
		||||
    :return: git package test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Package: git package test instance
 | 
			
		||||
    """
 | 
			
		||||
    return Package(
 | 
			
		||||
        base="tpacpi-bat-git",
 | 
			
		||||
@ -65,8 +75,12 @@ def package_tpacpi_bat_git() -> Package:
 | 
			
		||||
def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
 | 
			
		||||
    """
 | 
			
		||||
    mock object for pyalpm
 | 
			
		||||
    :param pyalpm_package_ahriman: mock object for pyalpm package
 | 
			
		||||
    :return: pyalpm mock
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        pyalpm_package_ahriman(MagicMock): mock object for pyalpm package
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        MagicMock: pyalpm mock
 | 
			
		||||
    """
 | 
			
		||||
    mock = MagicMock()
 | 
			
		||||
    mock.handle.load_pkg.return_value = pyalpm_package_ahriman
 | 
			
		||||
@ -77,8 +91,12 @@ def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
 | 
			
		||||
def pyalpm_package_ahriman(package_ahriman: Package) -> MagicMock:
 | 
			
		||||
    """
 | 
			
		||||
    mock object for pyalpm package
 | 
			
		||||
    :param package_ahriman: package fixture
 | 
			
		||||
    :return: pyalpm package mock
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_ahriman(Package): package fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        MagicMock: pyalpm package mock
 | 
			
		||||
    """
 | 
			
		||||
    mock = MagicMock()
 | 
			
		||||
    type(mock).base = PropertyMock(return_value=package_ahriman.base)
 | 
			
		||||
@ -93,8 +111,12 @@ def pyalpm_package_ahriman(package_ahriman: Package) -> MagicMock:
 | 
			
		||||
def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescription) -> MagicMock:
 | 
			
		||||
    """
 | 
			
		||||
    mock object for pyalpm package description
 | 
			
		||||
    :param package_description_ahriman: package description fixture
 | 
			
		||||
    :return: pyalpm package description mock
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        package_description_ahriman(PackageDescription): package description fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        MagicMock: pyalpm package description mock
 | 
			
		||||
    """
 | 
			
		||||
    mock = MagicMock()
 | 
			
		||||
    type(mock).arch = PropertyMock(return_value=package_description_ahriman.architecture)
 | 
			
		||||
@ -114,6 +136,8 @@ def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescr
 | 
			
		||||
def user_identity() -> UserIdentity:
 | 
			
		||||
    """
 | 
			
		||||
    identity fixture
 | 
			
		||||
    :return: user identity test instance
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        UserIdentity: user identity test instance
 | 
			
		||||
    """
 | 
			
		||||
    return UserIdentity("username", int(time.time()) + 30)
 | 
			
		||||
 | 
			
		||||
@ -12,8 +12,12 @@ from ahriman.models.aur_package import AURPackage
 | 
			
		||||
def _get_aur_data(resource_path_root: Path) -> Dict[str, Any]:
 | 
			
		||||
    """
 | 
			
		||||
    load package description from resource file
 | 
			
		||||
    :param resource_path_root: path to resource root
 | 
			
		||||
    :return: json descriptor
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        resource_path_root(Path): path to resource root
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Dict[str, Any]: json descriptor
 | 
			
		||||
    """
 | 
			
		||||
    response = (resource_path_root / "models" / "package_ahriman_aur").read_text()
 | 
			
		||||
    return json.loads(response)["results"][0]
 | 
			
		||||
@ -22,8 +26,12 @@ def _get_aur_data(resource_path_root: Path) -> Dict[str, Any]:
 | 
			
		||||
def _get_official_data(resource_path_root: Path) -> Dict[str, Any]:
 | 
			
		||||
    """
 | 
			
		||||
    load package description from resource file
 | 
			
		||||
    :param resource_path_root: path to resource root
 | 
			
		||||
    :return: json descriptor
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        resource_path_root(Path): path to resource root
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Dict[str, Any]: json descriptor
 | 
			
		||||
    """
 | 
			
		||||
    response = (resource_path_root / "models" / "package_akonadi_aur").read_text()
 | 
			
		||||
    return json.loads(response)["results"][0]
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -9,9 +9,13 @@ from ahriman.models.package_source import PackageSource
 | 
			
		||||
def _is_file_mock(is_any_file: bool, is_pkgbuild: bool) -> Callable[[Path], bool]:
 | 
			
		||||
    """
 | 
			
		||||
    helper to mock is_file method
 | 
			
		||||
    :param is_any_file: value which will be return for any file
 | 
			
		||||
    :param is_pkgbuild: value which will be return if PKGBUILD like path asked
 | 
			
		||||
    :return: side effect function for the mocker object
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        is_any_file(bool): value which will be return for any file
 | 
			
		||||
        is_pkgbuild(bool): value which will be return if PKGBUILD like path asked
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Callable[[Path], bool]: side effect function for the mocker object
 | 
			
		||||
    """
 | 
			
		||||
    side_effect: Callable[[Path], bool] = lambda source: is_pkgbuild if source.name == "PKGBUILD" else is_any_file
 | 
			
		||||
    return side_effect
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -14,9 +14,13 @@ from ahriman.models.repository_paths import RepositoryPaths
 | 
			
		||||
def _get_owner(root: Path, same: bool) -> Callable[[Path], Tuple[int, int]]:
 | 
			
		||||
    """
 | 
			
		||||
    mocker function for owner definition
 | 
			
		||||
    :param root: root directory
 | 
			
		||||
    :param same: if True then returns the same as root directory and different otherwise
 | 
			
		||||
    :return: function which can define ownership
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        root(Path): root directory
 | 
			
		||||
        same(bool): if True then returns the same as root directory and different otherwise
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Callable[[Path], Tuple[int, int]]: function which can define ownership
 | 
			
		||||
    """
 | 
			
		||||
    root_owner = (42, 42)
 | 
			
		||||
    nonroot_owner = (42, 42) if same else (1, 1)
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -21,12 +21,16 @@ _request = namedtuple("_request", ["app", "path", "method", "json", "post"])
 | 
			
		||||
def request(app: web.Application, path: str, method: str, json: Any = None, data: Any = None) -> _request:
 | 
			
		||||
    """
 | 
			
		||||
    request generator helper
 | 
			
		||||
    :param app: application fixture
 | 
			
		||||
    :param path: path for the request
 | 
			
		||||
    :param method: method for the request
 | 
			
		||||
    :param json: json payload of the request
 | 
			
		||||
    :param data: form data payload of the request
 | 
			
		||||
    :return: dummy request object
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        app(web.Application): application fixture
 | 
			
		||||
        path(str): path for the request
 | 
			
		||||
        method(str): method for the request
 | 
			
		||||
        json(Any, optional): json payload of the request (Default value = None)
 | 
			
		||||
        data(Any, optional): form data payload of the request (Default value = None)
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        _request: dummy request object
 | 
			
		||||
    """
 | 
			
		||||
    return _request(app, path, method, json, data)
 | 
			
		||||
 | 
			
		||||
@ -36,11 +40,15 @@ def application(configuration: Configuration, spawner: Spawn, database: SQLite,
 | 
			
		||||
                mocker: MockerFixture) -> web.Application:
 | 
			
		||||
    """
 | 
			
		||||
    application fixture
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param spawner: spawner fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        spawner(Spawn): spawner fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        web.Application: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
    mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
 | 
			
		||||
@ -53,12 +61,16 @@ def application_with_auth(configuration: Configuration, user: User, spawner: Spa
 | 
			
		||||
                          mocker: MockerFixture) -> web.Application:
 | 
			
		||||
    """
 | 
			
		||||
    application fixture with auth enabled
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param user: user descriptor fixture
 | 
			
		||||
    :param spawner: spawner fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        user(User): user descriptor fixture
 | 
			
		||||
        spawner(Spawn): spawner fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        web.Application: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    configuration.set_option("auth", "target", "configuration")
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
@ -77,12 +89,16 @@ def application_with_debug(configuration: Configuration, user: User, spawner: Sp
 | 
			
		||||
                           mocker: MockerFixture) -> web.Application:
 | 
			
		||||
    """
 | 
			
		||||
    application fixture with debug enabled
 | 
			
		||||
    :param configuration: configuration fixture
 | 
			
		||||
    :param user: user descriptor fixture
 | 
			
		||||
    :param spawner: spawner fixture
 | 
			
		||||
    :param database: database fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: application test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        user(User): user descriptor fixture
 | 
			
		||||
        spawner(Spawn): spawner fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        web.Application: application test instance
 | 
			
		||||
    """
 | 
			
		||||
    configuration.set_option("web", "debug", "yes")
 | 
			
		||||
    mocker.patch("ahriman.core.database.sqlite.SQLite.load", return_value=database)
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,14 @@ from ahriman.web.middlewares.auth_handler import AuthorizationPolicy
 | 
			
		||||
def authorization_policy(configuration: Configuration, database: SQLite, user: User) -> AuthorizationPolicy:
 | 
			
		||||
    """
 | 
			
		||||
    fixture for authorization policy
 | 
			
		||||
    :return: authorization policy fixture
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        configuration(Configuration): configuration fixture
 | 
			
		||||
        database(SQLite): database fixture
 | 
			
		||||
        user(User): user fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        AuthorizationPolicy: authorization policy fixture
 | 
			
		||||
    """
 | 
			
		||||
    configuration.set_option("auth", "target", "configuration")
 | 
			
		||||
    validator = Auth.load(configuration, database)
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,12 @@ from ahriman.web.middlewares.auth_handler import auth_handler, AuthorizationPoli
 | 
			
		||||
def _identity(username: str) -> str:
 | 
			
		||||
    """
 | 
			
		||||
    generate identity from user
 | 
			
		||||
    :param username: name of the user
 | 
			
		||||
    :return: user identity string
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        username(str): name of the user
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        str: user identity string
 | 
			
		||||
    """
 | 
			
		||||
    return f"{username} {UserIdentity.expire_when(60)}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,8 +13,12 @@ from ahriman.web.middlewares.exception_handler import exception_handler
 | 
			
		||||
def _extract_body(response: Any) -> Any:
 | 
			
		||||
    """
 | 
			
		||||
    extract json body from given object
 | 
			
		||||
    :param response: response (any actually) object
 | 
			
		||||
    :return: body key from the object converted to json
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        response(Any): response (any actually) object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        Any: body key from the object converted to json
 | 
			
		||||
    """
 | 
			
		||||
    return json.loads(getattr(response, "body"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -15,8 +15,12 @@ from ahriman.web.views.base import BaseView
 | 
			
		||||
def base(application: web.Application) -> BaseView:
 | 
			
		||||
    """
 | 
			
		||||
    base view fixture
 | 
			
		||||
    :param application: application fixture
 | 
			
		||||
    :return: generated base view fixture
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        application(web.Application): application fixture
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        BaseView: generated base view fixture
 | 
			
		||||
    """
 | 
			
		||||
    return BaseView(pytest.helpers.request(application, "", ""))
 | 
			
		||||
 | 
			
		||||
@ -26,11 +30,15 @@ def client(application: web.Application, event_loop: BaseEventLoop,
 | 
			
		||||
           aiohttp_client: Any, mocker: MockerFixture) -> TestClient:
 | 
			
		||||
    """
 | 
			
		||||
    web client fixture
 | 
			
		||||
    :param application: application fixture
 | 
			
		||||
    :param event_loop: context event loop
 | 
			
		||||
    :param aiohttp_client: aiohttp client fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: web client test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        application(web.Application): application fixture
 | 
			
		||||
        event_loop(BaseEventLoop): context event loop
 | 
			
		||||
        aiohttp_client(Any): aiohttp client fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        TestClient: web client test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.iterdir", return_value=[])
 | 
			
		||||
    return event_loop.run_until_complete(aiohttp_client(application))
 | 
			
		||||
@ -41,11 +49,15 @@ def client_with_auth(application_with_auth: web.Application, event_loop: BaseEve
 | 
			
		||||
                     aiohttp_client: Any, mocker: MockerFixture) -> TestClient:
 | 
			
		||||
    """
 | 
			
		||||
    web client fixture with full authorization functions
 | 
			
		||||
    :param application_with_auth: application fixture
 | 
			
		||||
    :param event_loop: context event loop
 | 
			
		||||
    :param aiohttp_client: aiohttp client fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: web client test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        application_with_auth(web.Application): application fixture
 | 
			
		||||
        event_loop(BaseEventLoop): context event loop
 | 
			
		||||
        aiohttp_client(Any): aiohttp client fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        TestClient: web client test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.iterdir", return_value=[])
 | 
			
		||||
    return event_loop.run_until_complete(aiohttp_client(application_with_auth))
 | 
			
		||||
@ -56,11 +68,15 @@ def client_with_oauth_auth(application_with_auth: web.Application, event_loop: B
 | 
			
		||||
                           aiohttp_client: Any, mocker: MockerFixture) -> TestClient:
 | 
			
		||||
    """
 | 
			
		||||
    web client fixture with full authorization functions
 | 
			
		||||
    :param application_with_auth: application fixture
 | 
			
		||||
    :param event_loop: context event loop
 | 
			
		||||
    :param aiohttp_client: aiohttp client fixture
 | 
			
		||||
    :param mocker: mocker object
 | 
			
		||||
    :return: web client test instance
 | 
			
		||||
 | 
			
		||||
    Args:
 | 
			
		||||
        application_with_auth(web.Application): application fixture
 | 
			
		||||
        event_loop(BaseEventLoop): context event loop
 | 
			
		||||
        aiohttp_client(Any): aiohttp client fixture
 | 
			
		||||
        mocker(MockerFixture): mocker object
 | 
			
		||||
 | 
			
		||||
    Returns:
 | 
			
		||||
        TestClient: web client test instance
 | 
			
		||||
    """
 | 
			
		||||
    mocker.patch("pathlib.Path.iterdir", return_value=[])
 | 
			
		||||
    application_with_auth["validator"] = MagicMock(spec=OAuth)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user