mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 23:37:18 +00:00
add docstrings for every fixture and test methods
also add tests for missing components
This commit is contained in:
parent
581401d60f
commit
50af309c80
@ -13,17 +13,32 @@ from ahriman.models.package import Package
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def application(configuration: Configuration, mocker: MockerFixture) -> Application:
|
def application(configuration: Configuration, mocker: MockerFixture) -> Application:
|
||||||
|
"""
|
||||||
|
fixture for application
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: application test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
return Application("x86_64", configuration)
|
return Application("x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def args() -> argparse.Namespace:
|
def args() -> argparse.Namespace:
|
||||||
|
"""
|
||||||
|
fixture for command line arguments
|
||||||
|
:return: command line arguments test instance
|
||||||
|
"""
|
||||||
return argparse.Namespace(lock=None, force=False, unsafe=False, no_report=True)
|
return argparse.Namespace(lock=None, force=False, unsafe=False, no_report=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def aur_package_ahriman(package_ahriman: Package) -> aur.Package:
|
def aur_package_ahriman(package_ahriman: Package) -> aur.Package:
|
||||||
|
"""
|
||||||
|
fixture for AUR package
|
||||||
|
:param package_ahriman: package fixture
|
||||||
|
:return: AUR package test instance
|
||||||
|
"""
|
||||||
return aur.Package(
|
return aur.Package(
|
||||||
num_votes=None,
|
num_votes=None,
|
||||||
description=package_ahriman.packages[package_ahriman.base].description,
|
description=package_ahriman.packages[package_ahriman.base].description,
|
||||||
@ -44,9 +59,19 @@ def aur_package_ahriman(package_ahriman: Package) -> aur.Package:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def lock(args: argparse.Namespace, configuration: Configuration) -> Lock:
|
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
|
||||||
|
"""
|
||||||
return Lock(args, "x86_64", configuration)
|
return Lock(args, "x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def parser() -> argparse.ArgumentParser:
|
def parser() -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
fixture for command line arguments parser
|
||||||
|
:return: command line arguments parser test instance
|
||||||
|
"""
|
||||||
return _parser()
|
return _parser()
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.package = []
|
||||||
args.now = False
|
args.now = False
|
||||||
args.without_dependencies = False
|
args.without_dependencies = False
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.no_build = False
|
args.no_build = False
|
||||||
args.no_cache = False
|
args.no_cache = False
|
||||||
args.no_chroot = False
|
args.no_chroot = False
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.key = "0xE989490C"
|
args.key = "0xE989490C"
|
||||||
args.key_server = "keys.gnupg.net"
|
args.key_server = "keys.gnupg.net"
|
||||||
return args
|
return args
|
||||||
|
@ -8,6 +8,11 @@ from ahriman.models.package import Package
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.depends_on = []
|
args.depends_on = []
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.package = []
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.target = []
|
args.target = []
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.search = ["ahriman"]
|
args.search = ["ahriman"]
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -11,6 +11,11 @@ from ahriman.models.sign_settings import SignSettings
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.build_command = "ahriman"
|
args.build_command = "ahriman"
|
||||||
args.from_configuration = Path("/usr/share/devtools/pacman-extra.conf")
|
args.from_configuration = Path("/usr/share/devtools/pacman-extra.conf")
|
||||||
args.no_multilib = False
|
args.no_multilib = False
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.package = []
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ from ahriman.models.package import Package
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.ahriman = True
|
args.ahriman = True
|
||||||
args.package = []
|
args.package = []
|
||||||
return args
|
return args
|
||||||
|
@ -9,6 +9,11 @@ from ahriman.models.package import Package
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.status = BuildStatusEnum.Success
|
args.status = BuildStatusEnum.Success
|
||||||
args.package = None
|
args.package = None
|
||||||
args.remove = False
|
args.remove = False
|
||||||
|
@ -7,6 +7,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.target = []
|
args.target = []
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ from ahriman.core.configuration import Configuration
|
|||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
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.package = []
|
||||||
args.dry_run = False
|
args.dry_run = False
|
||||||
args.no_aur = False
|
args.no_aur = False
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -10,6 +12,7 @@ from ahriman.models.package import Package
|
|||||||
from ahriman.models.package_description import PackageDescription
|
from ahriman.models.package_description import PackageDescription
|
||||||
from ahriman.models.repository_paths import RepositoryPaths
|
from ahriman.models.repository_paths import RepositoryPaths
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
@ -17,21 +20,63 @@ T = TypeVar("T")
|
|||||||
# https://stackoverflow.com/a/21611963
|
# https://stackoverflow.com/a/21611963
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def anyvar(cls: Type[T], strict: bool = False) -> 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
|
||||||
|
"""
|
||||||
class AnyVar(cls):
|
class AnyVar(cls):
|
||||||
|
"""
|
||||||
|
any value wrapper
|
||||||
|
"""
|
||||||
|
|
||||||
def __eq__(self, other: Any) -> bool:
|
def __eq__(self, other: Any) -> bool:
|
||||||
|
"""
|
||||||
|
compare object to other
|
||||||
|
:param other: other object to compare
|
||||||
|
:return: True in case if objects are equal
|
||||||
|
"""
|
||||||
return not strict or isinstance(other, cls)
|
return not strict or isinstance(other, cls)
|
||||||
|
|
||||||
return AnyVar()
|
return AnyVar()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.helpers.register
|
||||||
|
class AsyncMock(MagicMock):
|
||||||
|
"""
|
||||||
|
async magic mock object
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
||||||
|
"""
|
||||||
|
async call function
|
||||||
|
:param args:
|
||||||
|
:param kwargs:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return MagicMock.__call__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
# generic fixtures
|
# generic fixtures
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def configuration(resource_path_root: Path) -> Configuration:
|
def configuration(resource_path_root: Path) -> Configuration:
|
||||||
|
"""
|
||||||
|
configuration fixture
|
||||||
|
:param resource_path_root: resource path root directory
|
||||||
|
:return: configuration test instance
|
||||||
|
"""
|
||||||
path = resource_path_root / "core" / "ahriman.ini"
|
path = resource_path_root / "core" / "ahriman.ini"
|
||||||
return Configuration.from_path(path=path, architecture="x86_64", logfile=False)
|
return Configuration.from_path(path=path, architecture="x86_64", logfile=False)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def package_ahriman(package_description_ahriman: PackageDescription) -> Package:
|
def package_ahriman(package_description_ahriman: PackageDescription) -> Package:
|
||||||
|
"""
|
||||||
|
package fixture
|
||||||
|
:param package_description_ahriman: description fixture
|
||||||
|
:return: package test instance
|
||||||
|
"""
|
||||||
packages = {"ahriman": package_description_ahriman}
|
packages = {"ahriman": package_description_ahriman}
|
||||||
return Package(
|
return Package(
|
||||||
base="ahriman",
|
base="ahriman",
|
||||||
@ -44,6 +89,12 @@ def package_ahriman(package_description_ahriman: PackageDescription) -> Package:
|
|||||||
def package_python_schedule(
|
def package_python_schedule(
|
||||||
package_description_python_schedule: PackageDescription,
|
package_description_python_schedule: PackageDescription,
|
||||||
package_description_python2_schedule: PackageDescription) -> Package:
|
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
|
||||||
|
"""
|
||||||
packages = {
|
packages = {
|
||||||
"python-schedule": package_description_python_schedule,
|
"python-schedule": package_description_python_schedule,
|
||||||
"python2-schedule": package_description_python2_schedule
|
"python2-schedule": package_description_python2_schedule
|
||||||
@ -57,6 +108,10 @@ def package_python_schedule(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def package_description_ahriman() -> PackageDescription:
|
def package_description_ahriman() -> PackageDescription:
|
||||||
|
"""
|
||||||
|
package description fixture
|
||||||
|
:return: package description test instance
|
||||||
|
"""
|
||||||
return PackageDescription(
|
return PackageDescription(
|
||||||
architecture="x86_64",
|
architecture="x86_64",
|
||||||
archive_size=4200,
|
archive_size=4200,
|
||||||
@ -72,6 +127,10 @@ def package_description_ahriman() -> PackageDescription:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def package_description_python_schedule() -> PackageDescription:
|
def package_description_python_schedule() -> PackageDescription:
|
||||||
|
"""
|
||||||
|
package description fixture
|
||||||
|
:return: package description test instance
|
||||||
|
"""
|
||||||
return PackageDescription(
|
return PackageDescription(
|
||||||
architecture="x86_64",
|
architecture="x86_64",
|
||||||
archive_size=4201,
|
archive_size=4201,
|
||||||
@ -87,6 +146,10 @@ def package_description_python_schedule() -> PackageDescription:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def package_description_python2_schedule() -> PackageDescription:
|
def package_description_python2_schedule() -> PackageDescription:
|
||||||
|
"""
|
||||||
|
package description fixture
|
||||||
|
:return: package description test instance
|
||||||
|
"""
|
||||||
return PackageDescription(
|
return PackageDescription(
|
||||||
architecture="x86_64",
|
architecture="x86_64",
|
||||||
archive_size=4202,
|
archive_size=4202,
|
||||||
@ -102,6 +165,10 @@ def package_description_python2_schedule() -> PackageDescription:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def repository_paths(configuration: Configuration) -> RepositoryPaths:
|
def repository_paths(configuration: Configuration) -> RepositoryPaths:
|
||||||
|
"""
|
||||||
|
repository paths fixture
|
||||||
|
:return: repository paths test instance
|
||||||
|
"""
|
||||||
return RepositoryPaths(
|
return RepositoryPaths(
|
||||||
architecture="x86_64",
|
architecture="x86_64",
|
||||||
root=configuration.getpath("repository", "root"))
|
root=configuration.getpath("repository", "root"))
|
||||||
@ -109,5 +176,11 @@ def repository_paths(configuration: Configuration) -> RepositoryPaths:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def watcher(configuration: Configuration, mocker: MockerFixture) -> Watcher:
|
def watcher(configuration: Configuration, mocker: MockerFixture) -> Watcher:
|
||||||
|
"""
|
||||||
|
package status watcher fixture
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: package status watcher test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
return Watcher("x86_64", configuration)
|
return Watcher("x86_64", configuration)
|
||||||
|
@ -11,24 +11,52 @@ from ahriman.models.repository_paths import RepositoryPaths
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def leaf_ahriman(package_ahriman: Package) -> Leaf:
|
def leaf_ahriman(package_ahriman: Package) -> Leaf:
|
||||||
|
"""
|
||||||
|
fixture for tree leaf with package
|
||||||
|
:param package_ahriman: package fixture
|
||||||
|
:return: tree leaf test instance
|
||||||
|
"""
|
||||||
return Leaf(package_ahriman, set())
|
return Leaf(package_ahriman, set())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def leaf_python_schedule(package_python_schedule: 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
|
||||||
|
"""
|
||||||
return Leaf(package_python_schedule, set())
|
return Leaf(package_python_schedule, set())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pacman(configuration: Configuration) -> Pacman:
|
def pacman(configuration: Configuration) -> Pacman:
|
||||||
|
"""
|
||||||
|
fixture for pacman wrapper
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:return: pacman wrapper test instance
|
||||||
|
"""
|
||||||
return Pacman(configuration)
|
return Pacman(configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def repo(configuration: Configuration, repository_paths: RepositoryPaths) -> Repo:
|
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
|
||||||
|
"""
|
||||||
return Repo(configuration.get("repository", "name"), repository_paths, [])
|
return Repo(configuration.get("repository", "name"), repository_paths, [])
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def task_ahriman(package_ahriman: Package, configuration: Configuration, repository_paths: RepositoryPaths) -> Task:
|
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
|
||||||
|
"""
|
||||||
return Task(package_ahriman, configuration, repository_paths)
|
return Task(package_ahriman, configuration, repository_paths)
|
||||||
|
@ -12,12 +12,24 @@ from ahriman.core.repository.update_handler import UpdateHandler
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cleaner(configuration: Configuration, mocker: MockerFixture) -> Cleaner:
|
def cleaner(configuration: Configuration, mocker: MockerFixture) -> Cleaner:
|
||||||
|
"""
|
||||||
|
fixture for cleaner
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: cleaner test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
return Cleaner("x86_64", configuration)
|
return Cleaner("x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def executor(configuration: Configuration, mocker: MockerFixture) -> Executor:
|
def executor(configuration: Configuration, mocker: MockerFixture) -> Executor:
|
||||||
|
"""
|
||||||
|
fixture for executor
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: executor test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_build")
|
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_build")
|
||||||
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
|
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
|
||||||
@ -29,17 +41,34 @@ def executor(configuration: Configuration, mocker: MockerFixture) -> Executor:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def repository(configuration: Configuration, mocker: MockerFixture) -> Repository:
|
def repository(configuration: Configuration, mocker: MockerFixture) -> Repository:
|
||||||
|
"""
|
||||||
|
fixture for repository
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: repository test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
return Repository("x86_64", configuration)
|
return Repository("x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def properties(configuration: Configuration) -> Properties:
|
def properties(configuration: Configuration) -> Properties:
|
||||||
|
"""
|
||||||
|
fixture for properties
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:return: properties test instance
|
||||||
|
"""
|
||||||
return Properties("x86_64", configuration)
|
return Properties("x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def update_handler(configuration: Configuration, mocker: MockerFixture) -> UpdateHandler:
|
def update_handler(configuration: Configuration, mocker: MockerFixture) -> UpdateHandler:
|
||||||
|
"""
|
||||||
|
fixture for update handler
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: update handler test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_build")
|
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_build")
|
||||||
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
|
mocker.patch("ahriman.core.repository.cleaner.Cleaner.clear_cache")
|
||||||
|
@ -9,11 +9,18 @@ from ahriman.core.repository.cleaner import Cleaner
|
|||||||
|
|
||||||
|
|
||||||
def _mock_clear(mocker: MockerFixture) -> None:
|
def _mock_clear(mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
mocker helper for clear function
|
||||||
|
:param mocker: mocker object
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.iterdir", return_value=[Path("a"), Path("b"), Path("c")])
|
mocker.patch("pathlib.Path.iterdir", return_value=[Path("a"), Path("b"), Path("c")])
|
||||||
mocker.patch("shutil.rmtree")
|
mocker.patch("shutil.rmtree")
|
||||||
|
|
||||||
|
|
||||||
def _mock_clear_check() -> None:
|
def _mock_clear_check() -> None:
|
||||||
|
"""
|
||||||
|
mocker helper for clear tests
|
||||||
|
"""
|
||||||
shutil.rmtree.assert_has_calls([
|
shutil.rmtree.assert_has_calls([
|
||||||
mock.call(Path("a")),
|
mock.call(Path("a")),
|
||||||
mock.call(Path("b")),
|
mock.call(Path("b")),
|
||||||
|
@ -6,10 +6,20 @@ from ahriman.core.sign.gpg import GPG
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def gpg(configuration: Configuration) -> GPG:
|
def gpg(configuration: Configuration) -> GPG:
|
||||||
|
"""
|
||||||
|
fixture for empty GPG
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:return: GPG test instance
|
||||||
|
"""
|
||||||
return GPG("x86_64", configuration)
|
return GPG("x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def gpg_with_key(gpg: GPG) -> GPG:
|
def gpg_with_key(gpg: GPG) -> GPG:
|
||||||
|
"""
|
||||||
|
fixture for correct GPG
|
||||||
|
:param gpg: empty GPG fixture
|
||||||
|
:return: GPG test instance
|
||||||
|
"""
|
||||||
gpg.default_key = "key"
|
gpg.default_key = "key"
|
||||||
return gpg
|
return gpg
|
||||||
|
@ -11,20 +11,38 @@ from ahriman.models.package import Package
|
|||||||
# helpers
|
# helpers
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def get_package_status(package: Package) -> Dict[str, Any]:
|
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)
|
||||||
|
"""
|
||||||
return {"status": BuildStatusEnum.Unknown.value, "package": package.view()}
|
return {"status": BuildStatusEnum.Unknown.value, "package": package.view()}
|
||||||
|
|
||||||
|
|
||||||
@pytest.helpers.register
|
@pytest.helpers.register
|
||||||
def get_package_status_extended(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)
|
||||||
|
"""
|
||||||
return {"status": BuildStatus().view(), "package": package.view()}
|
return {"status": BuildStatus().view(), "package": package.view()}
|
||||||
|
|
||||||
|
|
||||||
# fixtures
|
# fixtures
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client() -> Client:
|
def client() -> Client:
|
||||||
|
"""
|
||||||
|
fixture for dummy client
|
||||||
|
:return: dummy client test instance
|
||||||
|
"""
|
||||||
return Client()
|
return Client()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def web_client() -> WebClient:
|
def web_client() -> WebClient:
|
||||||
|
"""
|
||||||
|
fixture for web client
|
||||||
|
:return: web client test instance
|
||||||
|
"""
|
||||||
return WebClient("localhost", 8080)
|
return WebClient("localhost", 8080)
|
||||||
|
@ -13,10 +13,19 @@ _s3_object = namedtuple("s3_object", ["key", "e_tag", "delete"])
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def s3(configuration: Configuration) -> S3:
|
def s3(configuration: Configuration) -> S3:
|
||||||
|
"""
|
||||||
|
fixture for S3 synchronization
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:return: S3 test instance
|
||||||
|
"""
|
||||||
return S3("x86_64", configuration)
|
return S3("x86_64", configuration)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def s3_remote_objects() -> List[_s3_object]:
|
def s3_remote_objects() -> List[_s3_object]:
|
||||||
|
"""
|
||||||
|
fixture for boto3 like S3 objects
|
||||||
|
:return: boto3 like S3 objects test instance
|
||||||
|
"""
|
||||||
delete_mock = MagicMock()
|
delete_mock = MagicMock()
|
||||||
return list(map(lambda item: _s3_object(f"x86_64/{item}", f"\"{item}\"", delete_mock), ["a", "b", "c"]))
|
return list(map(lambda item: _s3_object(f"x86_64/{item}", f"\"{item}\"", delete_mock), ["a", "b", "c"]))
|
||||||
|
@ -12,11 +12,19 @@ from ahriman.models.package_description import PackageDescription
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def build_status_failed() -> BuildStatus:
|
def build_status_failed() -> BuildStatus:
|
||||||
|
"""
|
||||||
|
build result fixture with failed status
|
||||||
|
:return: failed build status test instance
|
||||||
|
"""
|
||||||
return BuildStatus(BuildStatusEnum.Failed, 42)
|
return BuildStatus(BuildStatusEnum.Failed, 42)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def counters() -> Counters:
|
def counters() -> Counters:
|
||||||
|
"""
|
||||||
|
counters fixture
|
||||||
|
:return: counters test instance
|
||||||
|
"""
|
||||||
return Counters(total=10,
|
return Counters(total=10,
|
||||||
unknown=1,
|
unknown=1,
|
||||||
pending=2,
|
pending=2,
|
||||||
@ -27,6 +35,11 @@ def counters() -> Counters:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def internal_status(counters: Counters) -> InternalStatus:
|
def internal_status(counters: Counters) -> InternalStatus:
|
||||||
|
"""
|
||||||
|
internal status fixture
|
||||||
|
:param counters: counters fixture
|
||||||
|
:return: internal status test instance
|
||||||
|
"""
|
||||||
return InternalStatus(architecture="x86_64",
|
return InternalStatus(architecture="x86_64",
|
||||||
packages=counters,
|
packages=counters,
|
||||||
version=version.__version__,
|
version=version.__version__,
|
||||||
@ -35,6 +48,10 @@ def internal_status(counters: Counters) -> InternalStatus:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def package_tpacpi_bat_git() -> Package:
|
def package_tpacpi_bat_git() -> Package:
|
||||||
|
"""
|
||||||
|
git package fixture
|
||||||
|
:return: git package test instance
|
||||||
|
"""
|
||||||
return Package(
|
return Package(
|
||||||
base="tpacpi-bat-git",
|
base="tpacpi-bat-git",
|
||||||
version="3.1.r12.g4959b52-1",
|
version="3.1.r12.g4959b52-1",
|
||||||
@ -44,6 +61,11 @@ def package_tpacpi_bat_git() -> Package:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
|
def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
|
||||||
|
"""
|
||||||
|
mock object for pyalpm
|
||||||
|
:param pyalpm_package_ahriman: mock object for pyalpm package
|
||||||
|
:return: pyalpm mock
|
||||||
|
"""
|
||||||
mock = MagicMock()
|
mock = MagicMock()
|
||||||
mock.handle.load_pkg.return_value = pyalpm_package_ahriman
|
mock.handle.load_pkg.return_value = pyalpm_package_ahriman
|
||||||
return mock
|
return mock
|
||||||
@ -51,6 +73,11 @@ def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pyalpm_package_ahriman(package_ahriman: Package) -> MagicMock:
|
def pyalpm_package_ahriman(package_ahriman: Package) -> MagicMock:
|
||||||
|
"""
|
||||||
|
mock object for pyalpm package
|
||||||
|
:param package_ahriman: package fixture
|
||||||
|
:return: pyalpm package mock
|
||||||
|
"""
|
||||||
mock = MagicMock()
|
mock = MagicMock()
|
||||||
type(mock).base = PropertyMock(return_value=package_ahriman.base)
|
type(mock).base = PropertyMock(return_value=package_ahriman.base)
|
||||||
type(mock).name = PropertyMock(return_value=package_ahriman.base)
|
type(mock).name = PropertyMock(return_value=package_ahriman.base)
|
||||||
@ -60,6 +87,11 @@ def pyalpm_package_ahriman(package_ahriman: Package) -> MagicMock:
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescription) -> 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
|
||||||
|
"""
|
||||||
mock = MagicMock()
|
mock = MagicMock()
|
||||||
type(mock).arch = PropertyMock(return_value=package_description_ahriman.architecture)
|
type(mock).arch = PropertyMock(return_value=package_description_ahriman.architecture)
|
||||||
type(mock).builddate = PropertyMock(return_value=package_description_ahriman.build_date)
|
type(mock).builddate = PropertyMock(return_value=package_description_ahriman.build_date)
|
||||||
|
@ -9,5 +9,11 @@ from ahriman.web.web import setup_service
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def application(configuration: Configuration, mocker: MockerFixture) -> web.Application:
|
def application(configuration: Configuration, mocker: MockerFixture) -> web.Application:
|
||||||
|
"""
|
||||||
|
application fixture
|
||||||
|
:param configuration: configuration fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: application test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.mkdir")
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
return setup_service("x86_64", configuration)
|
return setup_service("x86_64", configuration)
|
||||||
|
15
tests/ahriman/web/middlewares/conftest.py
Normal file
15
tests/ahriman/web/middlewares/conftest.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
_request = namedtuple("_request", ["path"])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def aiohttp_request() -> _request:
|
||||||
|
"""
|
||||||
|
fixture for aiohttp like object
|
||||||
|
:return: aiohttp like request test instance
|
||||||
|
"""
|
||||||
|
return _request("path")
|
@ -0,0 +1,48 @@
|
|||||||
|
import logging
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from aiohttp.web_exceptions import HTTPBadRequest
|
||||||
|
from pytest_mock import MockerFixture
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from ahriman.web.middlewares.exception_handler import exception_handler
|
||||||
|
|
||||||
|
|
||||||
|
async def test_exception_handler(aiohttp_request: Any, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must pass success response
|
||||||
|
"""
|
||||||
|
request_handler = pytest.helpers.AsyncMock()
|
||||||
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
|
handler = exception_handler(logging.getLogger())
|
||||||
|
await handler(aiohttp_request, request_handler)
|
||||||
|
logging_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_exception_handler_client_error(aiohttp_request: Any, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must pass client exception
|
||||||
|
"""
|
||||||
|
request_handler = pytest.helpers.AsyncMock()
|
||||||
|
request_handler.side_effect = HTTPBadRequest()
|
||||||
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
|
handler = exception_handler(logging.getLogger())
|
||||||
|
with pytest.raises(HTTPBadRequest):
|
||||||
|
await handler(aiohttp_request, request_handler)
|
||||||
|
logging_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_exception_handler_server_error(aiohttp_request: Any, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must log server exception and re-raise it
|
||||||
|
"""
|
||||||
|
request_handler = pytest.helpers.AsyncMock()
|
||||||
|
request_handler.side_effect = Exception()
|
||||||
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
|
handler = exception_handler(logging.getLogger())
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
await handler(aiohttp_request, request_handler)
|
||||||
|
logging_mock.assert_called_once()
|
@ -0,0 +1,11 @@
|
|||||||
|
from aiohttp import web
|
||||||
|
|
||||||
|
from ahriman.web.routes import setup_routes
|
||||||
|
|
||||||
|
|
||||||
|
def test_setup_routes(application: web.Application) -> None:
|
||||||
|
"""
|
||||||
|
must generate non empty list of routes
|
||||||
|
"""
|
||||||
|
setup_routes(application)
|
||||||
|
assert application.router.routes()
|
@ -10,5 +10,13 @@ from typing import Any
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client(application: web.Application, loop: BaseEventLoop,
|
def client(application: web.Application, loop: BaseEventLoop,
|
||||||
aiohttp_client: Any, mocker: MockerFixture) -> TestClient:
|
aiohttp_client: Any, mocker: MockerFixture) -> TestClient:
|
||||||
|
"""
|
||||||
|
web client fixture
|
||||||
|
:param application: application fixture
|
||||||
|
:param loop: context event loop
|
||||||
|
:param aiohttp_client: aiohttp client fixture
|
||||||
|
:param mocker: mocker object
|
||||||
|
:return: web client test instance
|
||||||
|
"""
|
||||||
mocker.patch("pathlib.Path.iterdir", return_value=[])
|
mocker.patch("pathlib.Path.iterdir", return_value=[])
|
||||||
return loop.run_until_complete(aiohttp_client(application))
|
return loop.run_until_complete(aiohttp_client(application))
|
||||||
|
Loading…
Reference in New Issue
Block a user