mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
packagers support (#100)
This commit is contained in:
@ -72,16 +72,16 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
"python-installer": create_package_mock("python-installer"),
|
||||
}
|
||||
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda p, _: packages[p])
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda *args: packages[args[0]])
|
||||
packages_mock = mocker.patch("ahriman.application.application.Application._known_packages",
|
||||
return_value=["devtools", "python-build", "python-pytest"])
|
||||
return_value={"devtools", "python-build", "python-pytest"})
|
||||
|
||||
result = application.with_dependencies([package_ahriman], process_dependencies=True)
|
||||
assert {package.base: package for package in result} == packages
|
||||
package_mock.assert_has_calls([
|
||||
MockCall(package_python_schedule.base, application.repository.pacman),
|
||||
MockCall("python", application.repository.pacman),
|
||||
MockCall("python-installer", application.repository.pacman),
|
||||
MockCall(package_python_schedule.base, application.repository.pacman, package_ahriman.packager),
|
||||
MockCall("python", application.repository.pacman, package_ahriman.packager),
|
||||
MockCall("python-installer", application.repository.pacman, package_ahriman.packager),
|
||||
], any_order=True)
|
||||
packages_mock.assert_called_once_with()
|
||||
|
||||
|
@ -43,7 +43,7 @@ def test_add_aur(application_packages: ApplicationPackages, package_ahriman: Pac
|
||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||
update_remote_mock = mocker.patch("ahriman.core.database.SQLite.remote_update")
|
||||
|
||||
application_packages._add_aur(package_ahriman.base)
|
||||
application_packages._add_aur(package_ahriman.base, "packager")
|
||||
build_queue_mock.assert_called_once_with(package_ahriman)
|
||||
update_remote_mock.assert_called_once_with(package_ahriman)
|
||||
|
||||
@ -83,7 +83,7 @@ def test_add_local(application_packages: ApplicationPackages, package_ahriman: P
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||
|
||||
application_packages._add_local(package_ahriman.base)
|
||||
application_packages._add_local(package_ahriman.base, "packager")
|
||||
is_dir_mock.assert_called_once_with()
|
||||
copytree_mock.assert_called_once_with(
|
||||
Path(package_ahriman.base), application_packages.repository.paths.cache_for(package_ahriman.base))
|
||||
@ -103,7 +103,7 @@ def test_add_local_cache(application_packages: ApplicationPackages, package_ahri
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||
|
||||
application_packages._add_local(package_ahriman.base)
|
||||
application_packages._add_local(package_ahriman.base, "packager")
|
||||
copytree_mock.assert_not_called()
|
||||
init_mock.assert_not_called()
|
||||
build_queue_mock.assert_called_once_with(package_ahriman)
|
||||
@ -115,7 +115,7 @@ def test_add_local_missing(application_packages: ApplicationPackages, mocker: Mo
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
with pytest.raises(UnknownPackageError):
|
||||
application_packages._add_local("package")
|
||||
application_packages._add_local("package", "packager")
|
||||
|
||||
|
||||
def test_add_remote(application_packages: ApplicationPackages, package_description_ahriman: PackageDescription,
|
||||
@ -153,7 +153,7 @@ def test_add_repository(application_packages: ApplicationPackages, package_ahrim
|
||||
build_queue_mock = mocker.patch("ahriman.core.database.SQLite.build_queue_insert")
|
||||
update_remote_mock = mocker.patch("ahriman.core.database.SQLite.remote_update")
|
||||
|
||||
application_packages._add_repository(package_ahriman.base)
|
||||
application_packages._add_repository(package_ahriman.base, "packager")
|
||||
build_queue_mock.assert_called_once_with(package_ahriman)
|
||||
update_remote_mock.assert_called_once_with(package_ahriman)
|
||||
|
||||
@ -165,8 +165,8 @@ def test_add_add_archive(application_packages: ApplicationPackages, package_ahri
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_archive")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.Archive)
|
||||
add_mock.assert_called_once_with(package_ahriman.base)
|
||||
application_packages.add([package_ahriman.base], PackageSource.Archive, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
def test_add_add_aur(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
@ -176,8 +176,8 @@ def test_add_add_aur(application_packages: ApplicationPackages, package_ahriman:
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_aur")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.AUR)
|
||||
add_mock.assert_called_once_with(package_ahriman.base)
|
||||
application_packages.add([package_ahriman.base], PackageSource.AUR, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
def test_add_add_directory(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
@ -187,8 +187,8 @@ def test_add_add_directory(application_packages: ApplicationPackages, package_ah
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_directory")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.Directory)
|
||||
add_mock.assert_called_once_with(package_ahriman.base)
|
||||
application_packages.add([package_ahriman.base], PackageSource.Directory, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
def test_add_add_local(application_packages: ApplicationPackages, package_ahriman: Package,
|
||||
@ -198,8 +198,8 @@ def test_add_add_local(application_packages: ApplicationPackages, package_ahrima
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_local")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.Local)
|
||||
add_mock.assert_called_once_with(package_ahriman.base)
|
||||
application_packages.add([package_ahriman.base], PackageSource.Local, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
def test_add_add_remote(application_packages: ApplicationPackages, package_description_ahriman: PackageDescription,
|
||||
@ -210,8 +210,8 @@ def test_add_add_remote(application_packages: ApplicationPackages, package_descr
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_remote")
|
||||
url = f"https://host/{package_description_ahriman.filename}"
|
||||
|
||||
application_packages.add([url], PackageSource.Remote)
|
||||
add_mock.assert_called_once_with(url)
|
||||
application_packages.add([url], PackageSource.Remote, "packager")
|
||||
add_mock.assert_called_once_with(url, "packager")
|
||||
|
||||
|
||||
def test_on_result(application_packages: ApplicationPackages) -> None:
|
||||
|
@ -76,9 +76,9 @@ def test_sign(application_repository: ApplicationRepository, package_ahriman: Pa
|
||||
|
||||
application_repository.sign([])
|
||||
sign_package_mock.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(int), package_ahriman.base),
|
||||
MockCall(pytest.helpers.anyvar(int), package_python_schedule.base),
|
||||
MockCall(pytest.helpers.anyvar(int), package_python_schedule.base),
|
||||
MockCall(pytest.helpers.anyvar(int), None),
|
||||
MockCall(pytest.helpers.anyvar(int), None),
|
||||
MockCall(pytest.helpers.anyvar(int), None),
|
||||
])
|
||||
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
|
||||
on_result_mock.assert_called_once_with(Result())
|
||||
@ -111,7 +111,7 @@ def test_sign_specific(application_repository: ApplicationRepository, package_ah
|
||||
|
||||
filename = package_ahriman.packages[package_ahriman.base].filepath
|
||||
application_repository.sign([package_ahriman.base])
|
||||
sign_package_mock.assert_called_once_with(filename, package_ahriman.base)
|
||||
sign_package_mock.assert_called_once_with(filename, None)
|
||||
sign_repository_mock.assert_called_once_with(application_repository.repository.repo.repo_path)
|
||||
on_result_mock.assert_called_once_with(Result())
|
||||
|
||||
@ -170,9 +170,9 @@ def test_update(application_repository: ApplicationRepository, package_ahriman:
|
||||
on_result_mock = mocker.patch(
|
||||
"ahriman.application.application.application_repository.ApplicationRepository.on_result")
|
||||
|
||||
application_repository.update([package_ahriman])
|
||||
build_mock.assert_called_once_with([package_ahriman])
|
||||
update_mock.assert_has_calls([MockCall(paths), MockCall(paths)])
|
||||
application_repository.update([package_ahriman], "username")
|
||||
build_mock.assert_called_once_with([package_ahriman], "username")
|
||||
update_mock.assert_has_calls([MockCall(paths, "username"), MockCall(paths, "username")])
|
||||
on_result_mock.assert_has_calls([MockCall(result), MockCall(result)])
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
@ -27,6 +28,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.refresh = 0
|
||||
args.source = PackageSource.Auto
|
||||
args.dependencies = True
|
||||
args.username = "username"
|
||||
return args
|
||||
|
||||
|
||||
@ -42,7 +44,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Add.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_mock.assert_called_once_with(args.package, args.source)
|
||||
application_mock.assert_called_once_with(args.package, args.source, args.username)
|
||||
dependencies_mock.assert_not_called()
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
@ -67,7 +69,8 @@ def test_run_with_updates(args: argparse.Namespace, configuration: Configuration
|
||||
Add.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
updates_mock.assert_called_once_with(args.package, aur=False, local=False, manual=True, vcs=False,
|
||||
log_fn=pytest.helpers.anyvar(int))
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
application_mock.assert_called_once_with([package_ahriman],
|
||||
Packagers(args.username, {package_ahriman.base: "packager"}))
|
||||
dependencies_mock.assert_called_once_with([package_ahriman], process_dependencies=args.dependencies)
|
||||
check_mock.assert_called_once_with(False, False)
|
||||
|
||||
|
@ -109,7 +109,7 @@ def test_patch_create_from_diff(package_ahriman: Package, mocker: MockerFixture)
|
||||
sources_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.patch_create", return_value=patch.value)
|
||||
|
||||
assert Patch.patch_create_from_diff(path, "x86_64", ["*.diff"]) == (package_ahriman.base, patch)
|
||||
package_mock.assert_called_once_with(path, "x86_64")
|
||||
package_mock.assert_called_once_with(path, "x86_64", None)
|
||||
sources_mock.assert_called_once_with(path, "*.diff")
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.from_database = False
|
||||
args.exit_code = False
|
||||
args.status = None
|
||||
args.username = "username"
|
||||
return args
|
||||
|
||||
|
||||
@ -50,7 +51,7 @@ def test_run(args: argparse.Namespace, package_ahriman: Package, configuration:
|
||||
Rebuild.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
extract_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.status, from_database=args.from_database)
|
||||
application_packages_mock.assert_called_once_with([package_ahriman], None)
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
application_mock.assert_called_once_with([package_ahriman], args.username)
|
||||
check_mock.assert_has_calls([MockCall(False, False), MockCall(False, False)])
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
@ -36,7 +36,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
|
||||
ServiceUpdates.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
package_mock.assert_called_once_with(package_ahriman.base, repository.pacman)
|
||||
package_mock.assert_called_once_with(package_ahriman.base, repository.pacman, None)
|
||||
application_mock.assert_called_once_with(verbose=True, separator=" -> ")
|
||||
check_mock.assert_called_once_with(args.exit_code, True)
|
||||
|
||||
|
@ -19,7 +19,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.parser = _parser
|
||||
args.command = None
|
||||
args.command = []
|
||||
return args
|
||||
|
||||
|
||||
@ -42,14 +42,14 @@ def test_run_check(args: argparse.Namespace, configuration: Configuration, mocke
|
||||
must run command and check if command is unsafe
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.command = "clean"
|
||||
args.command = ["clean"]
|
||||
commands_mock = mocker.patch("ahriman.application.handlers.UnsafeCommands.get_unsafe_commands",
|
||||
return_value=["command"])
|
||||
check_mock = mocker.patch("ahriman.application.handlers.UnsafeCommands.check_unsafe")
|
||||
|
||||
UnsafeCommands.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
commands_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
check_mock.assert_called_once_with("clean", ["command"], pytest.helpers.anyvar(int))
|
||||
check_mock.assert_called_once_with(["clean"], ["command"], pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_check_unsafe(mocker: MockerFixture) -> None:
|
||||
@ -57,7 +57,7 @@ def test_check_unsafe(mocker: MockerFixture) -> None:
|
||||
must check if command is unsafe
|
||||
"""
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
UnsafeCommands.check_unsafe("service-clean", ["service-clean"], _parser())
|
||||
UnsafeCommands.check_unsafe(["service-clean"], ["service-clean"], _parser())
|
||||
check_mock.assert_called_once_with(True, True)
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ def test_check_unsafe_safe(mocker: MockerFixture) -> None:
|
||||
must check if command is safe
|
||||
"""
|
||||
check_mock = mocker.patch("ahriman.application.handlers.Handler.check_if_empty")
|
||||
UnsafeCommands.check_unsafe("package-status", ["service-clean"], _parser())
|
||||
UnsafeCommands.check_unsafe(["package-status"], ["service-clean"], _parser())
|
||||
check_mock.assert_called_once_with(True, False)
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ from ahriman.application.handlers import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
@ -31,6 +32,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.manual = True
|
||||
args.vcs = True
|
||||
args.refresh = 0
|
||||
args.username = "username"
|
||||
return args
|
||||
|
||||
|
||||
@ -51,7 +53,8 @@ def test_run(args: argparse.Namespace, package_ahriman: Package, configuration:
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
Update.run(args, "x86_64", configuration, report=False, unsafe=False)
|
||||
application_mock.assert_called_once_with([package_ahriman])
|
||||
application_mock.assert_called_once_with([package_ahriman],
|
||||
Packagers(args.username, {package_ahriman.base: "packager"}))
|
||||
updates_mock.assert_called_once_with(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
||||
log_fn=pytest.helpers.anyvar(int))
|
||||
dependencies_mock.assert_called_once_with([package_ahriman], process_dependencies=args.dependencies)
|
||||
|
@ -27,6 +27,8 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.username = "user"
|
||||
args.action = Action.Update
|
||||
args.exit_code = False
|
||||
args.key = "key"
|
||||
args.packager = "packager"
|
||||
args.password = "pa55w0rd"
|
||||
args.role = UserAccess.Reporter
|
||||
args.secure = False
|
||||
@ -38,7 +40,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, database: S
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
user = User(username=args.username, password=args.password, access=args.role)
|
||||
user = User(username=args.username, password=args.password, access=args.role,
|
||||
packager_id=args.packager, key=args.key)
|
||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
||||
mocker.patch("ahriman.models.user.User.hash_password", return_value=user)
|
||||
get_auth_configuration_mock = mocker.patch("ahriman.application.handlers.Users.configuration_get")
|
||||
@ -61,7 +64,8 @@ def test_run_empty_salt(args: argparse.Namespace, configuration: Configuration,
|
||||
must create configuration if salt was not set
|
||||
"""
|
||||
args = _default_args(args)
|
||||
user = User(username=args.username, password=args.password, access=args.role)
|
||||
user = User(username=args.username, password=args.password, access=args.role,
|
||||
packager_id=args.packager, key=args.key)
|
||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
||||
mocker.patch("ahriman.models.user.User.hash_password", return_value=user)
|
||||
get_auth_configuration_mock = mocker.patch("ahriman.application.handlers.Users.configuration_get")
|
||||
|
@ -351,13 +351,14 @@ def test_subparsers_repo_backup_architecture(parser: argparse.ArgumentParser) ->
|
||||
|
||||
def test_subparsers_repo_check(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
repo-check command must imply dependencies, dry-run, aur and manual
|
||||
repo-check command must imply dependencies, dry-run, aur, manual and username
|
||||
"""
|
||||
args = parser.parse_args(["repo-check"])
|
||||
assert not args.dependencies
|
||||
assert args.dry_run
|
||||
assert args.aur
|
||||
assert not args.manual
|
||||
assert args.username is None
|
||||
|
||||
|
||||
def test_subparsers_repo_check_architecture(parser: argparse.ArgumentParser) -> None:
|
||||
@ -757,14 +758,13 @@ def test_subparsers_user_add_option_role(parser: argparse.ArgumentParser) -> Non
|
||||
|
||||
def test_subparsers_user_list(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
user-list command must imply action, architecture, lock, report, password, quiet and unsafe
|
||||
user-list command must imply action, architecture, lock, report, quiet and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["user-list"])
|
||||
assert args.action == Action.List
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert not args.report
|
||||
assert args.password is not None
|
||||
assert args.quiet
|
||||
assert args.unsafe
|
||||
|
||||
@ -787,14 +787,13 @@ def test_subparsers_user_list_option_role(parser: argparse.ArgumentParser) -> No
|
||||
|
||||
def test_subparsers_user_remove(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
user-remove command must imply action, architecture, lock, report, password and quiet
|
||||
user-remove command must imply action, architecture, lock, report and quiet
|
||||
"""
|
||||
args = parser.parse_args(["user-remove", "username"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.architecture == [""]
|
||||
assert args.lock is None
|
||||
assert not args.report
|
||||
assert args.password is not None
|
||||
assert args.quiet
|
||||
|
||||
|
||||
|
@ -265,7 +265,8 @@ def package_ahriman(package_description_ahriman: PackageDescription, remote_sour
|
||||
base="ahriman",
|
||||
version="2.6.0-1",
|
||||
remote=remote_source,
|
||||
packages=packages)
|
||||
packages=packages,
|
||||
packager="packager")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -499,7 +500,7 @@ def user() -> User:
|
||||
Returns:
|
||||
User: user descriptor instance
|
||||
"""
|
||||
return User(username="user", password="pa55w0rd", access=UserAccess.Reporter)
|
||||
return User(username="user", password="pa55w0rd", access=UserAccess.Reporter, packager_id="packager", key="key")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -10,7 +10,7 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
must build package
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.task.Task._check_output")
|
||||
task_ahriman.build(Path("ahriman"))
|
||||
task_ahriman.build(Path("ahriman"), "packager")
|
||||
check_output_mock.assert_called()
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@ def test_migrate_data(connection: Connection, configuration: Configuration, mock
|
||||
def test_migrate_package_depends(connection: Connection, configuration: Configuration, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update make and opt depends list
|
||||
must update check depends list
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.iterdir", return_value=[package_ahriman.packages[package_ahriman.base].filepath])
|
||||
@ -45,7 +45,7 @@ def test_migrate_package_depends(connection: Connection, configuration: Configur
|
||||
def test_migrate_package_depends_skip(connection: Connection, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip update make and opt depends list if no repository directory found
|
||||
must skip update check depends list if no repository directory found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
migrate_package_check_depends(connection, configuration)
|
||||
|
@ -0,0 +1,52 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlite3 import Connection
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database.migrations.m008_packagers import migrate_data, migrate_package_base_packager, steps
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_migration_packagers() -> None:
|
||||
"""
|
||||
migration must not be empty
|
||||
"""
|
||||
assert steps
|
||||
|
||||
|
||||
def test_migrate_data(connection: Connection, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must perform data migration
|
||||
"""
|
||||
depends_mock = mocker.patch("ahriman.core.database.migrations.m008_packagers.migrate_package_base_packager")
|
||||
migrate_data(connection, configuration)
|
||||
depends_mock.assert_called_once_with(connection, configuration)
|
||||
|
||||
|
||||
def test_migrate_package_base_packager(connection: Connection, configuration: Configuration, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update packagers
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.iterdir", return_value=[package_ahriman.packages[package_ahriman.base].filepath])
|
||||
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
||||
|
||||
migrate_package_base_packager(connection, configuration)
|
||||
package_mock.assert_called_once_with(
|
||||
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int), remote=None)
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||
"package_base": package_ahriman.base,
|
||||
"packager": package_ahriman.packager,
|
||||
}])
|
||||
|
||||
|
||||
def test_migrate_package_depends_skip(connection: Connection, configuration: Configuration,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip update packagers if no repository directory found
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
migrate_package_base_packager(connection, configuration)
|
||||
connection.executemany.assert_not_called()
|
@ -16,21 +16,22 @@ def test_user_list(database: SQLite, user: User) -> None:
|
||||
must return all users
|
||||
"""
|
||||
database.user_update(user)
|
||||
database.user_update(User(username=user.password, password=user.username, access=user.access))
|
||||
second = User(username=user.password, password=user.username, access=user.access, packager_id=None, key=None)
|
||||
database.user_update(second)
|
||||
|
||||
users = database.user_list(None, None)
|
||||
assert len(users) == 2
|
||||
assert user in users
|
||||
assert User(username=user.password, password=user.username, access=user.access) in users
|
||||
assert second in users
|
||||
|
||||
|
||||
def test_user_list_filter_by_username(database: SQLite) -> None:
|
||||
"""
|
||||
must return users filtered by its id
|
||||
"""
|
||||
first = User(username="1", password="", access=UserAccess.Read)
|
||||
second = User(username="2", password="", access=UserAccess.Full)
|
||||
third = User(username="3", password="", access=UserAccess.Read)
|
||||
first = User(username="1", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.Full, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
|
||||
database.user_update(first)
|
||||
database.user_update(second)
|
||||
@ -45,9 +46,9 @@ def test_user_list_filter_by_access(database: SQLite) -> None:
|
||||
"""
|
||||
must return users filtered by its access
|
||||
"""
|
||||
first = User(username="1", password="", access=UserAccess.Read)
|
||||
second = User(username="2", password="", access=UserAccess.Full)
|
||||
third = User(username="3", password="", access=UserAccess.Read)
|
||||
first = User(username="1", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.Full, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
|
||||
database.user_update(first)
|
||||
database.user_update(second)
|
||||
@ -63,9 +64,9 @@ def test_user_list_filter_by_username_access(database: SQLite) -> None:
|
||||
"""
|
||||
must return users filtered by its access and username
|
||||
"""
|
||||
first = User(username="1", password="", access=UserAccess.Read)
|
||||
second = User(username="2", password="", access=UserAccess.Full)
|
||||
third = User(username="3", password="", access=UserAccess.Read)
|
||||
first = User(username="1", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.Full, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
|
||||
database.user_update(first)
|
||||
database.user_update(second)
|
||||
@ -91,6 +92,7 @@ def test_user_update(database: SQLite, user: User) -> None:
|
||||
database.user_update(user)
|
||||
assert database.user_get(user.username) == user
|
||||
|
||||
new_user = User(username=user.username, password=user.hash_password("salt").password, access=UserAccess.Full)
|
||||
new_user = User(username=user.username, password=user.hash_password("salt").password, access=UserAccess.Full,
|
||||
packager_id=None, key="new key")
|
||||
database.user_update(new_user)
|
||||
assert database.user_get(new_user.username) == new_user
|
||||
|
@ -32,7 +32,7 @@ def test_package_update(database: SQLite, configuration: Configuration, package_
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
patches_mock = mocker.patch("ahriman.core.database.SQLite.patches_get", return_value=[patch1, patch2])
|
||||
patches_write_mock = mocker.patch("ahriman.models.pkgbuild_patch.PkgbuildPatch.write")
|
||||
runner = RemotePush(configuration, database, "gitremote")
|
||||
runner = RemotePush(database, configuration, "gitremote")
|
||||
|
||||
assert runner.package_update(package_ahriman, local) == package_ahriman.base
|
||||
glob_mock.assert_called_once_with(".git*")
|
||||
@ -56,7 +56,7 @@ def test_packages_update(database: SQLite, configuration: Configuration, result:
|
||||
"""
|
||||
update_mock = mocker.patch("ahriman.core.gitremote.remote_push.RemotePush.package_update",
|
||||
return_value=[package_ahriman.base])
|
||||
runner = RemotePush(configuration, database, "gitremote")
|
||||
runner = RemotePush(database, configuration, "gitremote")
|
||||
|
||||
local = Path("local")
|
||||
assert list(runner.packages_update(result, local))
|
||||
@ -71,7 +71,7 @@ def test_run(database: SQLite, configuration: Configuration, result: Result, pac
|
||||
mocker.patch("ahriman.core.gitremote.remote_push.RemotePush.packages_update", return_value=[package_ahriman.base])
|
||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
|
||||
push_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.push")
|
||||
runner = RemotePush(configuration, database, "gitremote")
|
||||
runner = RemotePush(database, configuration, "gitremote")
|
||||
|
||||
runner.run(result)
|
||||
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.remote_source)
|
||||
@ -85,7 +85,7 @@ def test_run_failed(database: SQLite, configuration: Configuration, result: Resu
|
||||
must reraise exception on error occurred
|
||||
"""
|
||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch", side_effect=Exception())
|
||||
runner = RemotePush(configuration, database, "gitremote")
|
||||
runner = RemotePush(database, configuration, "gitremote")
|
||||
|
||||
with pytest.raises(GitRemoteError):
|
||||
runner.run(result)
|
||||
|
@ -6,6 +6,8 @@ from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.repository.executor import Executor
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.user import User
|
||||
|
||||
|
||||
def test_load_archives(executor: Executor) -> None:
|
||||
@ -33,7 +35,7 @@ def test_process_build(executor: Executor, package_ahriman: Package, mocker: Moc
|
||||
move_mock = mocker.patch("shutil.move")
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_building")
|
||||
|
||||
executor.process_build([package_ahriman])
|
||||
executor.process_build([package_ahriman], Packagers("packager"))
|
||||
# must move files (once)
|
||||
move_mock.assert_called_once_with(Path(package_ahriman.base), executor.paths.packages / package_ahriman.base)
|
||||
# must update status
|
||||
@ -157,7 +159,7 @@ def test_process_remove_unknown(executor: Executor, package_ahriman: Package, mo
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_process_update(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
def test_process_update(executor: Executor, package_ahriman: Package, user: User, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run update process
|
||||
"""
|
||||
@ -168,14 +170,16 @@ def test_process_update(executor: Executor, package_ahriman: Package, mocker: Mo
|
||||
sign_package_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process_sign_package", side_effect=lambda fn, _: [fn])
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_success")
|
||||
remove_mock = mocker.patch("ahriman.core.repository.executor.Executor.process_remove")
|
||||
packager_mock = mocker.patch("ahriman.core.repository.executor.Executor.packager", return_value=user)
|
||||
filepath = next(package.filepath for package in package_ahriman.packages.values())
|
||||
|
||||
# must return complete
|
||||
assert executor.process_update([filepath])
|
||||
assert executor.process_update([filepath], Packagers("packager"))
|
||||
packager_mock.assert_called_once_with(Packagers("packager"), "ahriman")
|
||||
# must move files (once)
|
||||
move_mock.assert_called_once_with(executor.paths.packages / filepath, executor.paths.repository / filepath)
|
||||
# must sign package
|
||||
sign_package_mock.assert_called_once_with(executor.paths.packages / filepath, package_ahriman.base)
|
||||
sign_package_mock.assert_called_once_with(executor.paths.packages / filepath, user.key)
|
||||
# must add package
|
||||
repo_add_mock.assert_called_once_with(executor.paths.repository / filepath)
|
||||
# must update status
|
||||
|
@ -4,6 +4,10 @@ from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.exceptions import UnsafeRunError
|
||||
from ahriman.core.repository.repository_properties import RepositoryProperties
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||
from ahriman.models.user import User
|
||||
from ahriman.models.user_access import UserAccess
|
||||
|
||||
|
||||
def test_create_tree_on_load(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> None:
|
||||
@ -12,7 +16,8 @@ def test_create_tree_on_load(configuration: Configuration, database: SQLite, moc
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.repository_properties.check_user")
|
||||
tree_create_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
RepositoryProperties("x86_64", configuration, database, report=False, unsafe=False, refresh_pacman_database=0)
|
||||
RepositoryProperties("x86_64", configuration, database, report=False, unsafe=False,
|
||||
refresh_pacman_database=PacmanSynchronization.Disabled)
|
||||
|
||||
tree_create_mock.assert_called_once_with()
|
||||
|
||||
@ -23,6 +28,36 @@ def test_create_tree_on_load_unsafe(configuration: Configuration, database: SQLi
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.repository_properties.check_user", side_effect=UnsafeRunError(0, 1))
|
||||
tree_create_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
RepositoryProperties("x86_64", configuration, database, report=False, unsafe=False, refresh_pacman_database=0)
|
||||
RepositoryProperties("x86_64", configuration, database, report=False, unsafe=False,
|
||||
refresh_pacman_database=PacmanSynchronization.Disabled)
|
||||
|
||||
tree_create_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_packager(repository: RepositoryProperties, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must extract packager
|
||||
"""
|
||||
database_mock = mocker.patch("ahriman.core.database.SQLite.user_get")
|
||||
assert repository.packager(Packagers("username", {}), "base")
|
||||
database_mock.assert_called_once_with("username")
|
||||
|
||||
|
||||
def test_packager_empty(repository: RepositoryProperties, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return empty user if username was not set
|
||||
"""
|
||||
database_mock = mocker.patch("ahriman.core.database.SQLite.user_get")
|
||||
user = User(username="", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
assert repository.packager(Packagers(), "base") == user
|
||||
database_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_packager_empty_result(repository: RepositoryProperties, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return empty user if it wasn't found in database
|
||||
"""
|
||||
database_mock = mocker.patch("ahriman.core.database.SQLite.user_get", return_value=None)
|
||||
user = User(username="username", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
assert repository.packager(Packagers(user.username), "base") == user
|
||||
database_mock.assert_called_once_with(user.username)
|
||||
|
@ -74,7 +74,7 @@ def test_updates_aur_filter(update_handler: UpdateHandler, package_ahriman: Pack
|
||||
package_load_mock = mocker.patch("ahriman.models.package.Package.from_aur", return_value=package_ahriman)
|
||||
|
||||
assert update_handler.updates_aur([package_ahriman.base], vcs=True) == [package_ahriman]
|
||||
package_load_mock.assert_called_once_with(package_ahriman.base, update_handler.pacman)
|
||||
package_load_mock.assert_called_once_with(package_ahriman.base, update_handler.pacman, None)
|
||||
|
||||
|
||||
def test_updates_aur_ignore(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
@ -120,7 +120,7 @@ def test_updates_local(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
|
||||
assert update_handler.updates_local(vcs=True) == [package_ahriman]
|
||||
fetch_mock.assert_called_once_with(Path(package_ahriman.base), remote=None)
|
||||
package_load_mock.assert_called_once_with(Path(package_ahriman.base), "x86_64")
|
||||
package_load_mock.assert_called_once_with(Path(package_ahriman.base), "x86_64", None)
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
package_is_outdated_mock.assert_called_once_with(
|
||||
package_ahriman, update_handler.paths,
|
||||
|
@ -135,21 +135,6 @@ def test_key_import(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
check_output_mock.assert_called_once_with("gpg", "--import", input_data="key", logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_keys(gpg: GPG) -> None:
|
||||
"""
|
||||
must extract keys
|
||||
"""
|
||||
assert gpg.keys() == []
|
||||
|
||||
gpg.default_key = "key"
|
||||
assert gpg.keys() == [gpg.default_key]
|
||||
|
||||
gpg.configuration.set_option("sign", "key_a", "key1")
|
||||
gpg.configuration.set_option("sign", "key_b", "key1")
|
||||
gpg.configuration.set_option("sign", "key_c", "key2")
|
||||
assert gpg.keys() == ["key", "key1", "key2"]
|
||||
|
||||
|
||||
def test_process(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call process method correctly
|
||||
@ -170,7 +155,7 @@ def test_process_sign_package_1(gpg_with_key: GPG, mocker: MockerFixture) -> Non
|
||||
|
||||
gpg_with_key.targets = {SignSettings.Packages}
|
||||
assert gpg_with_key.process_sign_package(Path("a"), "a") == result
|
||||
process_mock.assert_called_once_with(Path("a"), "key")
|
||||
process_mock.assert_called_once_with(Path("a"), "a")
|
||||
|
||||
|
||||
def test_process_sign_package_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
@ -182,7 +167,19 @@ def test_process_sign_package_2(gpg_with_key: GPG, mocker: MockerFixture) -> Non
|
||||
|
||||
gpg_with_key.targets = {SignSettings.Packages, SignSettings.Repository}
|
||||
assert gpg_with_key.process_sign_package(Path("a"), "a") == result
|
||||
process_mock.assert_called_once_with(Path("a"), "key")
|
||||
process_mock.assert_called_once_with(Path("a"), "a")
|
||||
|
||||
|
||||
def test_process_sign_package_3(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must sign package with default key if none passed
|
||||
"""
|
||||
result = [Path("a"), Path("a.sig")]
|
||||
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process", return_value=result)
|
||||
|
||||
gpg_with_key.targets = {SignSettings.Packages}
|
||||
assert gpg_with_key.process_sign_package(Path("a"), None) == result
|
||||
process_mock.assert_called_once_with(Path("a"), gpg_with_key.default_key)
|
||||
|
||||
|
||||
def test_process_sign_package_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
@ -211,7 +208,7 @@ def test_process_sign_package_skip_3(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
|
||||
gpg.targets = {SignSettings.Packages}
|
||||
gpg.process_sign_package(Path("a"), "a")
|
||||
gpg.process_sign_package(Path("a"), None)
|
||||
process_mock.assert_not_called()
|
||||
|
||||
|
||||
@ -221,7 +218,7 @@ def test_process_sign_package_skip_4(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
process_mock = mocker.patch("ahriman.core.sign.gpg.GPG.process")
|
||||
gpg.targets = {SignSettings.Packages, SignSettings.Repository}
|
||||
gpg.process_sign_package(Path("a"), "a")
|
||||
gpg.process_sign_package(Path("a"), None)
|
||||
process_mock.assert_not_called()
|
||||
|
||||
|
||||
|
@ -1,24 +1,26 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
from ahriman.core.support.pkgbuild.keyring_generator import KeyringGenerator
|
||||
from ahriman.core.support.pkgbuild.pkgbuild_generator import PkgbuildGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def keyring_generator(gpg: GPG, configuration: Configuration) -> KeyringGenerator:
|
||||
def keyring_generator(database: SQLite, gpg: GPG, configuration: Configuration) -> KeyringGenerator:
|
||||
"""
|
||||
fixture for keyring pkgbuild generator
|
||||
|
||||
Args:
|
||||
database(SQLite): database fixture
|
||||
gpg(GPG): empty GPG fixture
|
||||
configuration(Configuration): configuration fixture
|
||||
|
||||
Returns:
|
||||
KeyringGenerator: keyring generator test instance
|
||||
"""
|
||||
return KeyringGenerator(gpg, configuration, "keyring")
|
||||
return KeyringGenerator(database, gpg, configuration, "keyring")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -5,84 +5,87 @@ from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.exceptions import PkgbuildGeneratorError
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
from ahriman.core.support.pkgbuild.keyring_generator import KeyringGenerator
|
||||
from ahriman.models.user import User
|
||||
|
||||
|
||||
def test_init_packagers(gpg: GPG, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
def test_init_packagers(database: SQLite, gpg: GPG, configuration: Configuration, user: User,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must extract packagers keys
|
||||
"""
|
||||
mocker.patch("ahriman.core.sign.gpg.GPG.keys", return_value=["key"])
|
||||
mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[user])
|
||||
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").packagers == ["key"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").packagers == ["key"]
|
||||
|
||||
configuration.set_option("keyring", "packagers", "key1")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").packagers == ["key1"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").packagers == ["key1"]
|
||||
|
||||
|
||||
def test_init_revoked(gpg: GPG, configuration: Configuration) -> None:
|
||||
def test_init_revoked(database: SQLite, gpg: GPG, configuration: Configuration) -> None:
|
||||
"""
|
||||
must extract revoked keys
|
||||
"""
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").revoked == []
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").revoked == []
|
||||
|
||||
configuration.set_option("keyring", "revoked", "key1")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").revoked == ["key1"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").revoked == ["key1"]
|
||||
|
||||
|
||||
def test_init_trusted(gpg: GPG, configuration: Configuration) -> None:
|
||||
def test_init_trusted(database: SQLite, gpg: GPG, configuration: Configuration) -> None:
|
||||
"""
|
||||
must extract trusted keys
|
||||
"""
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").trusted == []
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").trusted == []
|
||||
|
||||
gpg.default_key = "key"
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").trusted == ["key"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").trusted == ["key"]
|
||||
|
||||
configuration.set_option("keyring", "trusted", "key1")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").trusted == ["key1"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").trusted == ["key1"]
|
||||
|
||||
|
||||
def test_license(gpg: GPG, configuration: Configuration) -> None:
|
||||
def test_license(database: SQLite, gpg: GPG, configuration: Configuration) -> None:
|
||||
"""
|
||||
must generate correct licenses list
|
||||
"""
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").license == ["Unlicense"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").license == ["Unlicense"]
|
||||
|
||||
configuration.set_option("keyring", "license", "GPL MPL")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").license == ["GPL", "MPL"]
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").license == ["GPL", "MPL"]
|
||||
|
||||
|
||||
def test_pkgdesc(gpg: GPG, configuration: Configuration) -> None:
|
||||
def test_pkgdesc(database: SQLite, gpg: GPG, configuration: Configuration) -> None:
|
||||
"""
|
||||
must generate correct pkgdesc property
|
||||
"""
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").pkgdesc == "aur-clone PGP keyring"
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").pkgdesc == "aur-clone PGP keyring"
|
||||
|
||||
configuration.set_option("keyring", "description", "description")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").pkgdesc == "description"
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").pkgdesc == "description"
|
||||
|
||||
|
||||
def test_pkgname(gpg: GPG, configuration: Configuration) -> None:
|
||||
def test_pkgname(database: SQLite, gpg: GPG, configuration: Configuration) -> None:
|
||||
"""
|
||||
must generate correct pkgname property
|
||||
"""
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").pkgname == "aur-clone-keyring"
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").pkgname == "aur-clone-keyring"
|
||||
|
||||
configuration.set_option("keyring", "package", "keyring")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").pkgname == "keyring"
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").pkgname == "keyring"
|
||||
|
||||
|
||||
def test_url(gpg: GPG, configuration: Configuration) -> None:
|
||||
def test_url(database: SQLite, gpg: GPG, configuration: Configuration) -> None:
|
||||
"""
|
||||
must generate correct url property
|
||||
"""
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").url == ""
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").url == ""
|
||||
|
||||
configuration.set_option("keyring", "homepage", "homepage")
|
||||
assert KeyringGenerator(gpg, configuration, "keyring").url == "homepage"
|
||||
assert KeyringGenerator(database, gpg, configuration, "keyring").url == "homepage"
|
||||
|
||||
|
||||
def test_generate_gpg(keyring_generator: KeyringGenerator, mocker: MockerFixture) -> None:
|
||||
|
@ -1,6 +1,8 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.sign.gpg import GPG
|
||||
from ahriman.core.support import KeyringTrigger
|
||||
from ahriman.models.context_key import ContextKey
|
||||
@ -21,10 +23,10 @@ def test_on_start(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run report for specified targets
|
||||
"""
|
||||
gpg_mock = mocker.patch("ahriman.core._Context.get")
|
||||
context_mock = mocker.patch("ahriman.core._Context.get")
|
||||
run_mock = mocker.patch("ahriman.core.support.package_creator.PackageCreator.run")
|
||||
|
||||
trigger = KeyringTrigger("x86_64", configuration)
|
||||
trigger.on_start()
|
||||
gpg_mock.assert_called_once_with(ContextKey("sign", GPG))
|
||||
context_mock.assert_has_calls([MockCall(ContextKey("sign", GPG)), MockCall(ContextKey("database", SQLite))])
|
||||
run_mock.assert_called_once_with()
|
||||
|
@ -35,6 +35,6 @@ def test_run(package_creator: PackageCreator, database: SQLite, mocker: MockerFi
|
||||
write_mock.assert_called_once_with(local_path)
|
||||
init_mock.assert_called_once_with(local_path)
|
||||
|
||||
package_mock.assert_called_once_with(local_path, "x86_64")
|
||||
package_mock.assert_called_once_with(local_path, "x86_64", None)
|
||||
database_mock.assert_called_once_with(ContextKey("database", SQLite))
|
||||
insert_mock.assert_called_once_with(package, pytest.helpers.anyvar(int))
|
||||
|
@ -42,7 +42,7 @@ def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
start_mock = mocker.patch("multiprocessing.Process.start")
|
||||
|
||||
spawner._spawn_process("add", "ahriman", now="", maybe="?")
|
||||
spawner._spawn_process("add", "ahriman", now="", maybe="?", none=None)
|
||||
start_mock.assert_called_once_with()
|
||||
spawner.args_parser.parse_args.assert_called_once_with(
|
||||
spawner.command_arguments + [
|
||||
@ -74,8 +74,8 @@ def test_packages_add(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package addition
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur")
|
||||
spawner.packages_add(["ahriman", "linux"], None, now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", username=None)
|
||||
|
||||
|
||||
def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
@ -83,8 +83,17 @@ def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package addition with update
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], now=True)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", now="")
|
||||
spawner.packages_add(["ahriman", "linux"], None, now=True)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", username=None, now="")
|
||||
|
||||
|
||||
def test_packages_add_with_username(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call package addition with username
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_add(["ahriman", "linux"], "username", now=False)
|
||||
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", username="username")
|
||||
|
||||
|
||||
def test_packages_rebuild(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
@ -92,8 +101,8 @@ def test_packages_rebuild(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call package rebuild
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_rebuild("python")
|
||||
spawn_mock.assert_called_once_with("repo-rebuild", **{"depends-on": "python"})
|
||||
spawner.packages_rebuild("python", "packager")
|
||||
spawn_mock.assert_called_once_with("repo-rebuild", **{"depends-on": "python", "username": "packager"})
|
||||
|
||||
|
||||
def test_packages_remove(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
@ -110,8 +119,8 @@ def test_packages_update(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
must call repo update
|
||||
"""
|
||||
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn._spawn_process")
|
||||
spawner.packages_update()
|
||||
spawn_mock.assert_called_once_with("repo-update")
|
||||
spawner.packages_update("packager")
|
||||
spawn_mock.assert_called_once_with("repo-update", username="packager")
|
||||
|
||||
|
||||
def test_run(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
|
@ -11,9 +11,9 @@ from typing import Any
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.exceptions import BuildError, OptionError, UnsafeRunError
|
||||
from ahriman.core.util import check_output, check_user, enum_values, exception_response_text, filter_json, \
|
||||
full_version, package_like, partition, pretty_datetime, pretty_size, safe_filename, srcinfo_property, \
|
||||
srcinfo_property_list, trim_package, utcnow, walk
|
||||
from ahriman.core.util import check_output, check_user, dataclass_view, enum_values, exception_response_text,\
|
||||
extract_user, filter_json, full_version, package_like, partition, pretty_datetime, pretty_size, safe_filename, \
|
||||
srcinfo_property, srcinfo_property_list, trim_package, utcnow, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
@ -91,6 +91,16 @@ def test_check_output_with_user(passwd: Any, mocker: MockerFixture) -> None:
|
||||
getpwuid_mock.assert_called_once_with(user)
|
||||
|
||||
|
||||
def test_check_output_with_user_and_environment(passwd: Any, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run set environment if both environment and user are set
|
||||
"""
|
||||
mocker.patch("ahriman.core.util.getpwuid", return_value=passwd)
|
||||
user = os.getuid()
|
||||
assert check_output("python", "-c", """import os; print(os.getenv("HOME"), os.getenv("VAR"))""",
|
||||
environment={"VAR": "VALUE"}, user=user) == f"{passwd.pw_dir} VALUE"
|
||||
|
||||
|
||||
def test_check_output_failure(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process exception correctly
|
||||
@ -155,6 +165,23 @@ def test_check_user_unsafe(mocker: MockerFixture) -> None:
|
||||
check_user(paths, unsafe=True)
|
||||
|
||||
|
||||
def test_dataclass_view(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must serialize dataclasses
|
||||
"""
|
||||
assert Package.from_json(dataclass_view(package_ahriman)) == package_ahriman
|
||||
|
||||
|
||||
def test_dataclass_view_without_none(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must serialize dataclasses with None fields removed
|
||||
"""
|
||||
package_ahriman.packager = None
|
||||
result = dataclass_view(package_ahriman)
|
||||
assert "packager" not in result
|
||||
assert Package.from_json(result) == package_ahriman
|
||||
|
||||
|
||||
def test_exception_response_text() -> None:
|
||||
"""
|
||||
must parse HTTP response to string
|
||||
@ -174,6 +201,23 @@ def test_exception_response_text_empty() -> None:
|
||||
assert exception_response_text(exception) == ""
|
||||
|
||||
|
||||
def test_extract_user() -> None:
|
||||
"""
|
||||
must extract user from system environment
|
||||
"""
|
||||
os.environ["USER"] = "user"
|
||||
assert extract_user() == "user"
|
||||
|
||||
os.environ["SUDO_USER"] = "sudo"
|
||||
assert extract_user() == "sudo"
|
||||
|
||||
os.environ["DOAS_USER"] = "doas"
|
||||
assert extract_user() == "sudo"
|
||||
|
||||
del os.environ["SUDO_USER"]
|
||||
assert extract_user() == "doas"
|
||||
|
||||
|
||||
def test_filter_json(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must filter fields by known list
|
||||
|
@ -116,6 +116,7 @@ def pyalpm_package_ahriman(aur_package_ahriman: AURPackage) -> MagicMock:
|
||||
type(mock).name = PropertyMock(return_value=aur_package_ahriman.name)
|
||||
type(mock).optdepends = PropertyMock(return_value=aur_package_ahriman.opt_depends)
|
||||
type(mock).checkdepends = PropertyMock(return_value=aur_package_ahriman.check_depends)
|
||||
type(mock).packager = PropertyMock(return_value="packager")
|
||||
type(mock).provides = PropertyMock(return_value=aur_package_ahriman.provides)
|
||||
type(mock).version = PropertyMock(return_value=aur_package_ahriman.version)
|
||||
type(mock).url = PropertyMock(return_value=aur_package_ahriman.url)
|
||||
|
@ -56,7 +56,7 @@ def test_depends_build_with_version_and_overlap(mocker: MockerFixture, resource_
|
||||
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package_gcc10 = Package.from_build(Path("local"), "x86_64")
|
||||
package_gcc10 = Package.from_build(Path("local"), "x86_64", None)
|
||||
assert package_gcc10.depends_build == {
|
||||
"glibc", "zstd", # depends
|
||||
"doxygen", "binutils", "git", "libmpc", "python", # make depends
|
||||
@ -168,10 +168,11 @@ def test_from_aur(package_ahriman: Package, aur_package_ahriman: AURPackage, pac
|
||||
"""
|
||||
mocker.patch("ahriman.core.alpm.remote.AUR.info", return_value=aur_package_ahriman)
|
||||
|
||||
package = Package.from_aur(package_ahriman.base, pacman)
|
||||
package = Package.from_aur(package_ahriman.base, pacman, package_ahriman.packager)
|
||||
assert package_ahriman.base == package.base
|
||||
assert package_ahriman.version == package.version
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
assert package_ahriman.packager == package.packager
|
||||
|
||||
|
||||
def test_from_build(package_ahriman: Package, mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
@ -181,7 +182,7 @@ def test_from_build(package_ahriman: Package, mocker: MockerFixture, resource_pa
|
||||
srcinfo = (resource_path_root / "models" / "package_ahriman_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package = Package.from_build(Path("path"), "x86_64")
|
||||
package = Package.from_build(Path("path"), "x86_64", "packager")
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
package_ahriman.packages = package.packages # we are not going to test PackageDescription here
|
||||
package_ahriman.remote = package.remote
|
||||
@ -195,7 +196,7 @@ def test_from_build_multiple_packages(mocker: MockerFixture, resource_path_root:
|
||||
srcinfo = (resource_path_root / "models" / "package_gcc10_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package = Package.from_build(Path("path"), "x86_64")
|
||||
package = Package.from_build(Path("path"), "x86_64", None)
|
||||
assert package.packages == {
|
||||
"gcc10": PackageDescription(
|
||||
depends=["gcc10-libs=10.3.0-2", "binutils>=2.28", "libmpc", "zstd"],
|
||||
@ -225,7 +226,7 @@ def test_from_build_architecture(mocker: MockerFixture, resource_path_root: Path
|
||||
srcinfo = (resource_path_root / "models" / "package_jellyfin-ffmpeg5-bin_srcinfo").read_text()
|
||||
mocker.patch("ahriman.models.package.Package._check_output", return_value=srcinfo)
|
||||
|
||||
package = Package.from_build(Path("path"), "x86_64")
|
||||
package = Package.from_build(Path("path"), "x86_64", None)
|
||||
assert package.packages == {
|
||||
"jellyfin-ffmpeg5-bin": PackageDescription(
|
||||
depends=["glibc"],
|
||||
@ -254,7 +255,7 @@ def test_from_build_failed(package_ahriman: Package, mocker: MockerFixture) -> N
|
||||
mocker.patch("ahriman.models.package.parse_srcinfo", return_value=({"packages": {}}, ["an error"]))
|
||||
|
||||
with pytest.raises(PackageInfoError):
|
||||
Package.from_build(Path("path"), "x86_64")
|
||||
Package.from_build(Path("path"), "x86_64", None)
|
||||
|
||||
|
||||
def test_from_json_view_1(package_ahriman: Package) -> None:
|
||||
@ -285,10 +286,11 @@ def test_from_official(package_ahriman: Package, aur_package_ahriman: AURPackage
|
||||
"""
|
||||
mocker.patch("ahriman.core.alpm.remote.Official.info", return_value=aur_package_ahriman)
|
||||
|
||||
package = Package.from_official(package_ahriman.base, pacman)
|
||||
package = Package.from_official(package_ahriman.base, pacman, package_ahriman.packager)
|
||||
assert package_ahriman.base == package.base
|
||||
assert package_ahriman.version == package.version
|
||||
assert package_ahriman.packages.keys() == package.packages.keys()
|
||||
assert package_ahriman.packager == package.packager
|
||||
|
||||
|
||||
def test_local_files(mocker: MockerFixture, resource_path_root: Path) -> None:
|
||||
|
12
tests/ahriman/models/test_packagers.py
Normal file
12
tests/ahriman/models/test_packagers.py
Normal file
@ -0,0 +1,12 @@
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
|
||||
|
||||
def test_for_base(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return username used for base package
|
||||
"""
|
||||
assert Packagers(None, {package_ahriman.base: "packager"}).for_base(package_ahriman.base) == "packager"
|
||||
assert Packagers("default", {package_ahriman.base: "packager"}).for_base("random") == "default"
|
||||
assert Packagers("default").for_base(package_ahriman.base) == "default"
|
||||
assert Packagers().for_base(package_ahriman.base) is None
|
@ -8,7 +8,7 @@ def test_from_option(user: User) -> None:
|
||||
"""
|
||||
must generate user from options
|
||||
"""
|
||||
user = replace(user, access=UserAccess.Read)
|
||||
user = replace(user, access=UserAccess.Read, packager_id=None, key=None)
|
||||
assert User.from_option(user.username, user.password) == user
|
||||
# default is read access
|
||||
user = replace(user, access=UserAccess.Full)
|
||||
|
@ -2,6 +2,7 @@ import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.service.add import AddView
|
||||
@ -21,13 +22,16 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
must call post request correctly
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
|
||||
user_mock = AsyncMock()
|
||||
user_mock.return_value = "username"
|
||||
mocker.patch("ahriman.web.views.base.BaseView.username", side_effect=user_mock)
|
||||
request_schema = pytest.helpers.schema_request(AddView.post)
|
||||
|
||||
payload = {"packages": ["ahriman"]}
|
||||
assert not request_schema.validate(payload)
|
||||
response = await client.post("/api/v1/service/add", json=payload)
|
||||
assert response.ok
|
||||
add_mock.assert_called_once_with(["ahriman"], now=True)
|
||||
add_mock.assert_called_once_with(["ahriman"], "username", now=True)
|
||||
|
||||
|
||||
async def test_post_empty(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -2,6 +2,7 @@ import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.service.rebuild import RebuildView
|
||||
@ -21,13 +22,16 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
must call post request correctly
|
||||
"""
|
||||
rebuild_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_rebuild")
|
||||
user_mock = AsyncMock()
|
||||
user_mock.return_value = "username"
|
||||
mocker.patch("ahriman.web.views.base.BaseView.username", side_effect=user_mock)
|
||||
request_schema = pytest.helpers.schema_request(RebuildView.post)
|
||||
|
||||
payload = {"packages": ["python", "ahriman"]}
|
||||
assert not request_schema.validate(payload)
|
||||
response = await client.post("/api/v1/service/rebuild", json=payload)
|
||||
assert response.ok
|
||||
rebuild_mock.assert_called_once_with("python")
|
||||
rebuild_mock.assert_called_once_with("python", "username")
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -2,6 +2,7 @@ import pytest
|
||||
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.service.request import RequestView
|
||||
@ -21,13 +22,16 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
must call post request correctly
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
|
||||
user_mock = AsyncMock()
|
||||
user_mock.return_value = "username"
|
||||
mocker.patch("ahriman.web.views.base.BaseView.username", side_effect=user_mock)
|
||||
request_schema = pytest.helpers.schema_request(RequestView.post)
|
||||
|
||||
payload = {"packages": ["ahriman"]}
|
||||
assert not request_schema.validate(payload)
|
||||
response = await client.post("/api/v1/service/request", json=payload)
|
||||
assert response.ok
|
||||
add_mock.assert_called_once_with(["ahriman"], now=False)
|
||||
add_mock.assert_called_once_with(["ahriman"], "username", now=False)
|
||||
|
||||
|
||||
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
@ -1,5 +1,6 @@
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
|
||||
async def test_post_update(client: TestClient, mocker: MockerFixture) -> None:
|
||||
@ -7,7 +8,10 @@ async def test_post_update(client: TestClient, mocker: MockerFixture) -> None:
|
||||
must call post request correctly for alias
|
||||
"""
|
||||
update_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_update")
|
||||
user_mock = AsyncMock()
|
||||
user_mock.return_value = "username"
|
||||
mocker.patch("ahriman.web.views.base.BaseView.username", side_effect=user_mock)
|
||||
|
||||
response = await client.post("/api/v1/service/update")
|
||||
assert response.ok
|
||||
update_mock.assert_called_once_with()
|
||||
update_mock.assert_called_once_with("username")
|
||||
|
@ -2,6 +2,8 @@ import pytest
|
||||
|
||||
from multidict import MultiDict
|
||||
from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.views.base import BaseView
|
||||
@ -146,3 +148,22 @@ async def test_head_not_allowed(client: TestClient) -> None:
|
||||
"""
|
||||
response = await client.head("/api/v1/service/add")
|
||||
assert response.status == 405
|
||||
|
||||
|
||||
async def test_username(base: BaseView, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return identity of logged-in user
|
||||
"""
|
||||
policy = AsyncMock()
|
||||
policy.identify.return_value = "identity"
|
||||
mocker.patch("aiohttp.web.Application.get", return_value=policy)
|
||||
|
||||
assert await base.username() == "identity"
|
||||
policy.identify.assert_called_once_with(base.request)
|
||||
|
||||
|
||||
async def test_username_no_auth(base: BaseView) -> None:
|
||||
"""
|
||||
must return None in case if auth is disabled
|
||||
"""
|
||||
assert await base.username() is None
|
||||
|
Reference in New Issue
Block a user