mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-29 05:39:56 +00:00
strict test checks
This commit is contained in:
@ -20,7 +20,7 @@ def test_repo_add(repo: Repo, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
|
||||
|
||||
repo.add(Path("path"))
|
||||
check_output_mock.assert_called_once()
|
||||
check_output_mock.assert_called_once() # it will be checked later
|
||||
assert check_output_mock.call_args[0][0] == "repo-add"
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ def test_repo_init(repo: Repo, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
|
||||
|
||||
repo.init()
|
||||
check_output_mock.assert_called_once()
|
||||
check_output_mock.assert_called_once() # it will be checked later
|
||||
assert check_output_mock.call_args[0][0] == "repo-add"
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ def test_repo_remove(repo: Repo, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.alpm.repo.Repo._check_output")
|
||||
|
||||
repo.remove("package", Path("package.pkg.tar.xz"))
|
||||
check_output_mock.assert_called_once()
|
||||
check_output_mock.assert_called_once() # it will be checked later
|
||||
assert check_output_mock.call_args[0][0] == "repo-remove"
|
||||
|
||||
|
||||
|
@ -39,7 +39,7 @@ async def test_authorized_userid_library(mocker: MockerFixture) -> None:
|
||||
mocker.patch.object(helpers, "_has_aiohttp_security", True)
|
||||
authorized_userid_mock = mocker.patch("aiohttp_security.authorized_userid")
|
||||
await helpers.authorized_userid()
|
||||
authorized_userid_mock.assert_called_once()
|
||||
authorized_userid_mock.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_check_authorized_dummy(mocker: MockerFixture) -> None:
|
||||
@ -59,7 +59,7 @@ async def test_check_authorized_library(mocker: MockerFixture) -> None:
|
||||
mocker.patch.object(helpers, "_has_aiohttp_security", True)
|
||||
check_authorized_mock = mocker.patch("aiohttp_security.check_authorized")
|
||||
await helpers.check_authorized()
|
||||
check_authorized_mock.assert_called_once()
|
||||
check_authorized_mock.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_forget_dummy(mocker: MockerFixture) -> None:
|
||||
@ -79,7 +79,7 @@ async def test_forget_library(mocker: MockerFixture) -> None:
|
||||
mocker.patch.object(helpers, "_has_aiohttp_security", True)
|
||||
forget_mock = mocker.patch("aiohttp_security.forget")
|
||||
await helpers.forget()
|
||||
forget_mock.assert_called_once()
|
||||
forget_mock.assert_called_once_with()
|
||||
|
||||
|
||||
async def test_remember_dummy(mocker: MockerFixture) -> None:
|
||||
@ -99,4 +99,4 @@ async def test_remember_library(mocker: MockerFixture) -> None:
|
||||
mocker.patch.object(helpers, "_has_aiohttp_security", True)
|
||||
remember_mock = mocker.patch("aiohttp_security.remember")
|
||||
await helpers.remember()
|
||||
remember_mock.assert_called_once()
|
||||
remember_mock.assert_called_once_with()
|
||||
|
@ -71,7 +71,7 @@ async def test_get_oauth_username(oauth: OAuth, mocker: MockerFixture) -> None:
|
||||
|
||||
email = await oauth.get_oauth_username("code")
|
||||
access_token_mock.assert_called_once_with("code", redirect_uri=oauth.redirect_uri)
|
||||
user_info_mock.assert_called_once()
|
||||
user_info_mock.assert_called_once_with()
|
||||
assert email == "email"
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ def test_diff(mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
Sources.diff(local, Path("patch"))
|
||||
write_mock.assert_called_once()
|
||||
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
check_output_mock.assert_called_once_with("git", "diff",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
@ -157,7 +157,7 @@ def test_patch_apply(mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
Sources.patch_apply(local, Path("patches"))
|
||||
glob_mock.assert_called_once()
|
||||
glob_mock.assert_called_once_with("*.patch")
|
||||
check_output_mock.assert_has_calls([
|
||||
mock.call("git", "apply", "--ignore-space-change", "--ignore-whitespace", "01.patch",
|
||||
exception=None, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
|
@ -21,4 +21,4 @@ def test_init_with_cache(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
copytree_mock = mocker.patch("shutil.copytree")
|
||||
|
||||
task_ahriman.init(None)
|
||||
copytree_mock.assert_called_once()
|
||||
copytree_mock.assert_called_once() # we do not check full command here, sorry
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
@ -15,8 +17,8 @@ def test_send(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.starttls.assert_not_called()
|
||||
smtp_mock.return_value.login.assert_not_called()
|
||||
smtp_mock.return_value.sendmail.assert_called_once()
|
||||
smtp_mock.return_value.quit.assert_called_once()
|
||||
smtp_mock.return_value.sendmail.assert_called_once_with(report.sender, report.receivers, pytest.helpers.anyvar(int))
|
||||
smtp_mock.return_value.quit.assert_called_once_with()
|
||||
|
||||
|
||||
def test_send_auth(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -29,7 +31,7 @@ def test_send_auth(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.login.assert_called_once()
|
||||
smtp_mock.return_value.login.assert_called_once_with(report.user, report.password)
|
||||
|
||||
|
||||
def test_send_auth_no_password(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -67,8 +69,8 @@ def test_send_ssl_tls(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.starttls.assert_not_called()
|
||||
smtp_mock.return_value.login.assert_not_called()
|
||||
smtp_mock.return_value.sendmail.assert_called_once()
|
||||
smtp_mock.return_value.quit.assert_called_once()
|
||||
smtp_mock.return_value.sendmail.assert_called_once_with(report.sender, report.receivers, pytest.helpers.anyvar(int))
|
||||
smtp_mock.return_value.quit.assert_called_once_with()
|
||||
|
||||
|
||||
def test_send_starttls(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -80,7 +82,7 @@ def test_send_starttls(configuration: Configuration, mocker: MockerFixture) -> N
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.starttls.assert_called_once()
|
||||
smtp_mock.return_value.starttls.assert_called_once_with()
|
||||
|
||||
|
||||
def test_generate(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -91,7 +93,7 @@ def test_generate(configuration: Configuration, package_ahriman: Package, mocker
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [])
|
||||
send_mock.assert_called_once()
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
|
||||
|
||||
|
||||
def test_generate_with_built(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -102,7 +104,7 @@ def test_generate_with_built(configuration: Configuration, package_ahriman: Pack
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
send_mock.assert_called_once()
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
|
||||
|
||||
|
||||
def test_generate_with_built_and_full_path(
|
||||
@ -117,7 +119,7 @@ def test_generate_with_built_and_full_path(
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.full_template_path = report.template_path
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
send_mock.assert_called_once()
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_generate_no_empty(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -142,4 +144,4 @@ def test_generate_no_empty_with_built(configuration: Configuration, package_ahri
|
||||
|
||||
report = Email("x86_64", configuration, "email")
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
send_mock.assert_called_once()
|
||||
send_mock.assert_called_once_with(pytest.helpers.anyvar(int), {})
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
@ -13,4 +15,4 @@ def test_generate(configuration: Configuration, package_ahriman: Package, mocker
|
||||
|
||||
report = HTML("x86_64", configuration, "html")
|
||||
report.generate([package_ahriman], [])
|
||||
write_mock.assert_called_once()
|
||||
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
@ -24,7 +24,7 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
mocker.patch("ahriman.models.report_settings.ReportSettings.from_option", return_value=ReportSettings.Disabled)
|
||||
report_mock = mocker.patch("ahriman.core.report.report.Report.generate")
|
||||
Report.load("x86_64", configuration, "disabled").run([], [])
|
||||
report_mock.assert_called_once()
|
||||
report_mock.assert_called_once_with([], [])
|
||||
|
||||
|
||||
def test_report_email(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -33,7 +33,7 @@ def test_report_email(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.email.Email.generate")
|
||||
Report.load("x86_64", configuration, "email").run([], [])
|
||||
report_mock.assert_called_once()
|
||||
report_mock.assert_called_once_with([], [])
|
||||
|
||||
|
||||
def test_report_html(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -42,4 +42,4 @@ def test_report_html(configuration: Configuration, mocker: MockerFixture) -> Non
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.html.HTML.generate")
|
||||
Report.load("x86_64", configuration, "html").run([], [])
|
||||
report_mock.assert_called_once()
|
||||
report_mock.assert_called_once_with([], [])
|
||||
|
@ -39,14 +39,14 @@ def test_process_build(executor: Executor, package_ahriman: Package, mocker: Moc
|
||||
|
||||
executor.process_build([package_ahriman])
|
||||
# must move files (once)
|
||||
move_mock.assert_called_once()
|
||||
move_mock.assert_called_once_with(Path(package_ahriman.base), executor.paths.packages / package_ahriman.base)
|
||||
# must update status
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
# must clear directory
|
||||
from ahriman.core.repository.cleaner import Cleaner
|
||||
Cleaner.clear_build.assert_called_once()
|
||||
Cleaner.clear_build.assert_called_once_with()
|
||||
# must return build packages after all
|
||||
built_packages_mock.assert_called_once()
|
||||
built_packages_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_process_build_failure(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -60,7 +60,7 @@ def test_process_build_failure(executor: Executor, package_ahriman: Package, moc
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_failed")
|
||||
|
||||
executor.process_build([package_ahriman])
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_process_remove_base(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -74,10 +74,11 @@ def test_process_remove_base(executor: Executor, package_ahriman: Package, mocke
|
||||
|
||||
executor.process_remove([package_ahriman.base])
|
||||
# must remove via alpm wrapper
|
||||
repo_remove_mock.assert_called_once()
|
||||
repo_remove_mock.assert_called_once_with(
|
||||
package_ahriman.base, package_ahriman.packages[package_ahriman.base].filepath)
|
||||
# must update status and remove package files
|
||||
tree_clear_mock.assert_called_once_with(package_ahriman.base)
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_process_remove_base_multiple(executor: Executor, package_python_schedule: Package,
|
||||
@ -96,7 +97,7 @@ def test_process_remove_base_multiple(executor: Executor, package_python_schedul
|
||||
for package, props in package_python_schedule.packages.items()
|
||||
], any_order=True)
|
||||
# must update status
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_python_schedule.base)
|
||||
|
||||
|
||||
def test_process_remove_base_single(executor: Executor, package_python_schedule: Package,
|
||||
@ -110,7 +111,8 @@ def test_process_remove_base_single(executor: Executor, package_python_schedule:
|
||||
|
||||
executor.process_remove(["python2-schedule"])
|
||||
# must remove via alpm wrapper
|
||||
repo_remove_mock.assert_called_once()
|
||||
repo_remove_mock.assert_called_once_with(
|
||||
"python2-schedule", package_python_schedule.packages["python2-schedule"].filepath)
|
||||
# must not update status
|
||||
status_client_mock.assert_not_called()
|
||||
|
||||
@ -154,7 +156,7 @@ def test_process_report(executor: Executor, package_ahriman: Package, mocker: Mo
|
||||
report_mock = mocker.patch("ahriman.core.report.report.Report.run")
|
||||
|
||||
executor.process_report(["dummy"], [])
|
||||
report_mock.assert_called_once()
|
||||
report_mock.assert_called_once_with([package_ahriman], [])
|
||||
|
||||
|
||||
def test_process_report_auto(executor: Executor) -> None:
|
||||
@ -163,18 +165,18 @@ def test_process_report_auto(executor: Executor) -> None:
|
||||
"""
|
||||
configuration_mock = executor.configuration = MagicMock()
|
||||
executor.process_report(None, [])
|
||||
configuration_mock.getlist.assert_called_once()
|
||||
configuration_mock.getlist.assert_called_once_with("report", "target")
|
||||
|
||||
|
||||
def test_process_upload(executor: Executor, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must process sync in auto mode if no targets supplied
|
||||
must process sync
|
||||
"""
|
||||
mocker.patch("ahriman.core.upload.upload.Upload.load", return_value=Upload("x86_64", executor.configuration))
|
||||
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.run")
|
||||
|
||||
executor.process_sync(["dummy"], [])
|
||||
upload_mock.assert_called_once()
|
||||
upload_mock.assert_called_once_with(executor.paths.repository, [])
|
||||
|
||||
|
||||
def test_process_upload_auto(executor: Executor) -> None:
|
||||
@ -183,7 +185,7 @@ def test_process_upload_auto(executor: Executor) -> None:
|
||||
"""
|
||||
configuration_mock = executor.configuration = MagicMock()
|
||||
executor.process_sync(None, [])
|
||||
configuration_mock.getlist.assert_called_once()
|
||||
configuration_mock.getlist.assert_called_once_with("upload", "target")
|
||||
|
||||
|
||||
def test_process_update(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -197,20 +199,21 @@ 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")
|
||||
filepath = next(package.filepath for package in package_ahriman.packages.values())
|
||||
|
||||
# must return complete
|
||||
assert executor.process_update([package.filepath for package in package_ahriman.packages.values()])
|
||||
assert executor.process_update([filepath])
|
||||
# must move files (once)
|
||||
move_mock.assert_called_once()
|
||||
move_mock.assert_called_once_with(executor.paths.packages / filepath, executor.paths.repository / filepath)
|
||||
# must sign package
|
||||
sign_package_mock.assert_called_once()
|
||||
sign_package_mock.assert_called_once_with(executor.paths.packages / filepath, package_ahriman.base)
|
||||
# must add package
|
||||
repo_add_mock.assert_called_once()
|
||||
repo_add_mock.assert_called_once_with(executor.paths.repository / filepath)
|
||||
# must update status
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman)
|
||||
# must clear directory
|
||||
from ahriman.core.repository.cleaner import Cleaner
|
||||
Cleaner.clear_packages.assert_called_once()
|
||||
Cleaner.clear_packages.assert_called_once_with()
|
||||
# clear removed packages
|
||||
remove_mock.assert_called_once_with([])
|
||||
|
||||
@ -256,7 +259,7 @@ def test_process_update_failed(executor: Executor, package_ahriman: Package, moc
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_failed")
|
||||
|
||||
executor.process_update([package.filepath for package in package_ahriman.packages.values()])
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_process_update_removed_package(executor: Executor, package_python_schedule: Package,
|
||||
|
@ -14,7 +14,7 @@ def test_create_tree_on_load(configuration: Configuration, mocker: MockerFixture
|
||||
tree_create_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.tree_create")
|
||||
Properties("x86_64", configuration, True)
|
||||
|
||||
tree_create_mock.assert_called_once()
|
||||
tree_create_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_create_tree_on_load_unsafe(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -48,4 +48,4 @@ def test_create_full_report_client(configuration: Configuration, mocker: MockerF
|
||||
load_mock = mocker.patch("ahriman.core.status.client.Client.load")
|
||||
Properties("x86_64", configuration, False)
|
||||
|
||||
load_mock.assert_called_once()
|
||||
load_mock.assert_called_once_with(configuration)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
@ -71,7 +73,8 @@ def test_packages(repository: Repository, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
load_mock = mocker.patch("ahriman.core.repository.repository.Repository.load_archives")
|
||||
repository.packages()
|
||||
load_mock.assert_called_once() # it uses filter object so we cannot verity argument list =/
|
||||
# it uses filter object, so we cannot verify argument list =/
|
||||
load_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_packages_built(repository: Repository, mocker: MockerFixture) -> None:
|
||||
|
@ -4,6 +4,7 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.repository.update_handler import UpdateHandler
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
|
||||
|
||||
def test_packages(update_handler: UpdateHandler) -> None:
|
||||
@ -25,13 +26,13 @@ def test_updates_aur(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_pending")
|
||||
|
||||
assert update_handler.updates_aur([], False) == [package_ahriman]
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_updates_aur_success(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must provide updates with status updates
|
||||
must provide updates with status updates with success
|
||||
"""
|
||||
mocker.patch("ahriman.core.repository.update_handler.UpdateHandler.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.models.package.Package.is_outdated", return_value=False)
|
||||
@ -52,7 +53,7 @@ def test_updates_aur_failed(update_handler: UpdateHandler, package_ahriman: Pack
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_failed")
|
||||
|
||||
update_handler.updates_aur([], False)
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_updates_aur_filter(update_handler: UpdateHandler, package_ahriman: Package, package_python_schedule: Package,
|
||||
@ -66,7 +67,8 @@ def test_updates_aur_filter(update_handler: UpdateHandler, package_ahriman: Pack
|
||||
package_load_mock = mocker.patch("ahriman.models.package.Package.load", return_value=package_ahriman)
|
||||
|
||||
assert update_handler.updates_aur([package_ahriman.base], False) == [package_ahriman]
|
||||
package_load_mock.assert_called_once()
|
||||
package_load_mock.assert_called_once_with(package_ahriman.base, PackageSource.AUR,
|
||||
update_handler.pacman, update_handler.aur_url)
|
||||
|
||||
|
||||
def test_updates_aur_ignore(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
@ -108,8 +110,9 @@ def test_updates_local(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
|
||||
assert update_handler.updates_local() == [package_ahriman]
|
||||
fetch_mock.assert_called_once_with(package_ahriman.base, remote=None)
|
||||
package_load_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once()
|
||||
package_load_mock.assert_called_once_with(
|
||||
package_ahriman.base, PackageSource.Local, update_handler.pacman, update_handler.aur_url)
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_updates_local_unknown(update_handler: UpdateHandler, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -124,7 +127,7 @@ def test_updates_local_unknown(update_handler: UpdateHandler, package_ahriman: P
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_unknown")
|
||||
|
||||
assert update_handler.updates_local() == [package_ahriman]
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman)
|
||||
|
||||
|
||||
def test_updates_local_with_failures(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
@ -165,7 +168,7 @@ def test_updates_manual_clear(update_handler: UpdateHandler, mocker: MockerFixtu
|
||||
update_handler.updates_manual()
|
||||
|
||||
from ahriman.core.repository.cleaner import Cleaner
|
||||
Cleaner.clear_manual.assert_called_once()
|
||||
Cleaner.clear_manual.assert_called_once_with()
|
||||
|
||||
|
||||
def test_updates_manual_status_known(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
@ -179,7 +182,7 @@ def test_updates_manual_status_known(update_handler: UpdateHandler, package_ahri
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_pending")
|
||||
|
||||
update_handler.updates_manual()
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_updates_manual_status_unknown(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
@ -193,7 +196,7 @@ def test_updates_manual_status_unknown(update_handler: UpdateHandler, package_ah
|
||||
status_client_mock = mocker.patch("ahriman.core.status.client.Client.set_unknown")
|
||||
|
||||
update_handler.updates_manual()
|
||||
status_client_mock.assert_called_once()
|
||||
status_client_mock.assert_called_once_with(package_ahriman)
|
||||
|
||||
|
||||
def test_updates_manual_with_failures(update_handler: UpdateHandler, package_ahriman: Package,
|
||||
|
@ -70,7 +70,8 @@ def test_key_download(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
requests_mock = mocker.patch("requests.get")
|
||||
gpg.key_download("pgp.mit.edu", "0xE989490C")
|
||||
requests_mock.assert_called_once()
|
||||
requests_mock.assert_called_once_with(
|
||||
"http://pgp.mit.edu/pks/lookup", params={"op": "get", "options": "mr", "search": "0xE989490C"})
|
||||
|
||||
|
||||
def test_key_download_failure(gpg: GPG, mocker: MockerFixture) -> None:
|
||||
@ -116,19 +117,19 @@ 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()
|
||||
process_mock.assert_called_once_with(Path("a"), "key")
|
||||
|
||||
|
||||
def test_process_sign_package_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must sign package
|
||||
must sign package if there are multiple targets
|
||||
"""
|
||||
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, SignSettings.Repository}
|
||||
assert gpg_with_key.process_sign_package(Path("a"), "a") == result
|
||||
process_mock.assert_called_once()
|
||||
process_mock.assert_called_once_with(Path("a"), "key")
|
||||
|
||||
|
||||
def test_process_sign_package_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
@ -180,19 +181,19 @@ def test_process_sign_repository_1(gpg_with_key: GPG, mocker: MockerFixture) ->
|
||||
|
||||
gpg_with_key.targets = {SignSettings.Repository}
|
||||
assert gpg_with_key.process_sign_repository(Path("a")) == result
|
||||
process_mock.assert_called_once()
|
||||
process_mock.assert_called_once_with(Path("a"), "key")
|
||||
|
||||
|
||||
def test_process_sign_repository_2(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must sign repository
|
||||
must sign repository if there are multiple targets
|
||||
"""
|
||||
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, SignSettings.Repository}
|
||||
assert gpg_with_key.process_sign_repository(Path("a")) == result
|
||||
process_mock.assert_called_once()
|
||||
process_mock.assert_called_once_with(Path("a"), "key")
|
||||
|
||||
|
||||
def test_process_sign_repository_skip_1(gpg_with_key: GPG, mocker: MockerFixture) -> None:
|
||||
|
@ -105,7 +105,7 @@ def test_cache_save(watcher: Watcher, package_ahriman: Package, mocker: MockerFi
|
||||
|
||||
watcher.known = {package_ahriman.base: (package_ahriman, BuildStatus())}
|
||||
watcher._cache_save()
|
||||
json_mock.assert_called_once()
|
||||
json_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_cache_save_failed(watcher: Watcher, mocker: MockerFixture) -> None:
|
||||
@ -163,7 +163,7 @@ def test_load(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture)
|
||||
cache_mock = mocker.patch("ahriman.core.status.watcher.Watcher._cache_load")
|
||||
|
||||
watcher.load()
|
||||
cache_mock.assert_called_once()
|
||||
cache_mock.assert_called_once_with()
|
||||
package, status = watcher.known[package_ahriman.base]
|
||||
assert package == package_ahriman
|
||||
assert status.status == BuildStatusEnum.Unknown
|
||||
@ -191,7 +191,7 @@ def test_remove(watcher: Watcher, package_ahriman: Package, mocker: MockerFixtur
|
||||
|
||||
watcher.remove(package_ahriman.base)
|
||||
assert not watcher.known
|
||||
cache_mock.assert_called_once()
|
||||
cache_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_remove_unknown(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -201,7 +201,7 @@ def test_remove_unknown(watcher: Watcher, package_ahriman: Package, mocker: Mock
|
||||
cache_mock = mocker.patch("ahriman.core.status.watcher.Watcher._cache_save")
|
||||
|
||||
watcher.remove(package_ahriman.base)
|
||||
cache_mock.assert_called_once()
|
||||
cache_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@ -211,7 +211,7 @@ def test_update(watcher: Watcher, package_ahriman: Package, mocker: MockerFixtur
|
||||
cache_mock = mocker.patch("ahriman.core.status.watcher.Watcher._cache_save")
|
||||
|
||||
watcher.update(package_ahriman.base, BuildStatusEnum.Unknown, package_ahriman)
|
||||
cache_mock.assert_called_once()
|
||||
cache_mock.assert_called_once_with()
|
||||
package, status = watcher.known[package_ahriman.base]
|
||||
assert package == package_ahriman
|
||||
assert status.status == BuildStatusEnum.Unknown
|
||||
@ -225,7 +225,7 @@ def test_update_ping(watcher: Watcher, package_ahriman: Package, mocker: MockerF
|
||||
watcher.known = {package_ahriman.base: (package_ahriman, BuildStatus())}
|
||||
|
||||
watcher.update(package_ahriman.base, BuildStatusEnum.Success, None)
|
||||
cache_mock.assert_called_once()
|
||||
cache_mock.assert_called_once_with()
|
||||
package, status = watcher.known[package_ahriman.base]
|
||||
assert package == package_ahriman
|
||||
assert status.status == BuildStatusEnum.Success
|
||||
@ -239,7 +239,7 @@ def test_update_unknown(watcher: Watcher, package_ahriman: Package, mocker: Mock
|
||||
|
||||
with pytest.raises(UnknownPackage):
|
||||
watcher.update(package_ahriman.base, BuildStatusEnum.Unknown, None)
|
||||
cache_mock.assert_called_once()
|
||||
cache_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_update_self(watcher: Watcher) -> None:
|
||||
|
@ -130,7 +130,7 @@ def test_get_all(web_client: WebClient, package_ahriman: Package, mocker: Mocker
|
||||
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
|
||||
|
||||
result = web_client.get(None)
|
||||
requests_mock.assert_called_once()
|
||||
requests_mock.assert_called_once_with(web_client._package_url())
|
||||
assert len(result) == len(response)
|
||||
assert (package_ahriman, BuildStatusEnum.Unknown) in [(package, status.status) for package, status in result]
|
||||
|
||||
@ -163,7 +163,7 @@ def test_get_single(web_client: WebClient, package_ahriman: Package, mocker: Moc
|
||||
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
|
||||
|
||||
result = web_client.get(package_ahriman.base)
|
||||
requests_mock.assert_called_once()
|
||||
requests_mock.assert_called_once_with(web_client._package_url(package_ahriman.base))
|
||||
assert len(result) == len(response)
|
||||
assert (package_ahriman, BuildStatusEnum.Unknown) in [(package, status.status) for package, status in result]
|
||||
|
||||
@ -179,7 +179,7 @@ def test_get_internal(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
|
||||
|
||||
result = web_client.get_internal()
|
||||
requests_mock.assert_called_once()
|
||||
requests_mock.assert_called_once_with(web_client._status_url)
|
||||
assert result.architecture == "x86_64"
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ def test_get_self(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||
requests_mock = mocker.patch("requests.Session.get", return_value=response_obj)
|
||||
|
||||
result = web_client.get_self()
|
||||
requests_mock.assert_called_once()
|
||||
requests_mock.assert_called_once_with(web_client._ahriman_url)
|
||||
assert result.status == BuildStatusEnum.Unknown
|
||||
|
||||
|
||||
|
@ -22,8 +22,8 @@ def test_from_path(mocker: MockerFixture) -> None:
|
||||
configuration = Configuration.from_path(path, "x86_64", True)
|
||||
assert configuration.path == path
|
||||
read_mock.assert_called_once_with(path)
|
||||
load_includes_mock.assert_called_once()
|
||||
load_logging_mock.assert_called_once()
|
||||
load_includes_mock.assert_called_once_with()
|
||||
load_logging_mock.assert_called_once_with(True)
|
||||
|
||||
|
||||
def test_dump(configuration: Configuration) -> None:
|
||||
@ -251,8 +251,8 @@ def test_reload(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
merge_mock = mocker.patch("ahriman.core.configuration.Configuration.merge_sections")
|
||||
|
||||
configuration.reload()
|
||||
load_mock.assert_called_once()
|
||||
merge_mock.assert_called_once()
|
||||
load_mock.assert_called_once_with(configuration.path)
|
||||
merge_mock.assert_called_once_with(configuration.architecture)
|
||||
|
||||
|
||||
def test_reload_clear(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
|
@ -70,7 +70,7 @@ def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:
|
||||
start_mock = mocker.patch("multiprocessing.Process.start")
|
||||
|
||||
spawner.spawn_process("add", "ahriman", now="", maybe="?")
|
||||
start_mock.assert_called_once()
|
||||
start_mock.assert_called_once_with()
|
||||
spawner.args_parser.parse_args.assert_called_once_with([
|
||||
"--architecture", spawner.architecture, "--configuration", str(spawner.configuration.path),
|
||||
"add", "ahriman", "--now", "--maybe", "?"
|
||||
@ -104,8 +104,8 @@ def test_run_pop(spawner: Spawn) -> None:
|
||||
|
||||
spawner.run()
|
||||
|
||||
first.terminate.assert_called_once()
|
||||
first.join.assert_called_once()
|
||||
second.terminate.assert_called_once()
|
||||
second.join.assert_called_once()
|
||||
first.terminate.assert_called_once_with()
|
||||
first.join.assert_called_once_with()
|
||||
second.terminate.assert_called_once_with()
|
||||
second.join.assert_called_once_with()
|
||||
assert not spawner.active
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
@ -47,10 +49,11 @@ def test_leaf_load(package_ahriman: Package, repository_paths: RepositoryPaths,
|
||||
leaf = Leaf.load(package_ahriman, repository_paths)
|
||||
assert leaf.package == package_ahriman
|
||||
assert leaf.dependencies == {"ahriman-dependency"}
|
||||
tempdir_mock.assert_called_once()
|
||||
load_mock.assert_called_once()
|
||||
dependencies_mock.assert_called_once()
|
||||
rmtree_mock.assert_called_once()
|
||||
tempdir_mock.assert_called_once_with()
|
||||
load_mock.assert_called_once_with(
|
||||
pytest.helpers.anyvar(int), package_ahriman.git_url, repository_paths.patches_for(package_ahriman.base))
|
||||
dependencies_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||
rmtree_mock.assert_called_once_with(pytest.helpers.anyvar(int), ignore_errors=True)
|
||||
|
||||
|
||||
def test_tree_levels(leaf_ahriman: Leaf, leaf_python_schedule: Leaf) -> None:
|
||||
|
@ -21,7 +21,7 @@ def test_check_output(mocker: MockerFixture) -> None:
|
||||
logger_mock.assert_not_called()
|
||||
|
||||
assert check_output("echo", "hello", exception=None, logger=logging.getLogger("")) == "hello"
|
||||
logger_mock.assert_called_once()
|
||||
logger_mock.assert_called_once_with("hello")
|
||||
|
||||
|
||||
def test_check_output_failure(mocker: MockerFixture) -> None:
|
||||
@ -49,7 +49,7 @@ def test_check_output_failure_log(mocker: MockerFixture) -> None:
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
check_output("echo", "hello", exception=None, logger=logging.getLogger(""))
|
||||
logger_mock.assert_called_once()
|
||||
logger_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_check_user(mocker: MockerFixture) -> None:
|
||||
|
@ -180,20 +180,20 @@ def test_release_sync(github: Github, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run sync command
|
||||
"""
|
||||
release_get_mock = mocker.patch("ahriman.core.upload.github.Github.release_get")
|
||||
get_hashes_mock = mocker.patch("ahriman.core.upload.github.Github.get_hashes")
|
||||
get_local_files_mock = mocker.patch("ahriman.core.upload.github.Github.get_local_files")
|
||||
release_get_mock = mocker.patch("ahriman.core.upload.github.Github.release_get", return_value={})
|
||||
get_hashes_mock = mocker.patch("ahriman.core.upload.github.Github.get_hashes", return_value={})
|
||||
get_local_files_mock = mocker.patch("ahriman.core.upload.github.Github.get_local_files", return_value={})
|
||||
files_upload_mock = mocker.patch("ahriman.core.upload.github.Github.files_upload")
|
||||
files_remove_mock = mocker.patch("ahriman.core.upload.github.Github.files_remove")
|
||||
release_update_mock = mocker.patch("ahriman.core.upload.github.Github.release_update")
|
||||
|
||||
github.sync(Path("local"), [])
|
||||
release_get_mock.assert_called_once()
|
||||
get_hashes_mock.assert_called_once()
|
||||
get_local_files_mock.assert_called_once()
|
||||
files_upload_mock.assert_called_once()
|
||||
files_remove_mock.assert_called_once()
|
||||
release_update_mock.assert_called_once()
|
||||
release_get_mock.assert_called_once_with()
|
||||
get_hashes_mock.assert_called_once_with("")
|
||||
get_local_files_mock.assert_called_once_with(Path("local"))
|
||||
files_upload_mock.assert_called_once_with({}, {}, {})
|
||||
files_remove_mock.assert_called_once_with({}, {}, {})
|
||||
release_update_mock.assert_called_once_with({}, pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_release_sync_create_release(github: Github, mocker: MockerFixture) -> None:
|
||||
@ -209,4 +209,4 @@ def test_release_sync_create_release(github: Github, mocker: MockerFixture) -> N
|
||||
release_create_mock = mocker.patch("ahriman.core.upload.github.Github.release_create")
|
||||
|
||||
github.sync(Path("local"), [])
|
||||
release_create_mock.assert_called_once()
|
||||
release_create_mock.assert_called_once_with()
|
||||
|
@ -51,7 +51,7 @@ def test_request(github: Github, mocker: MockerFixture) -> None:
|
||||
|
||||
github._request("GET", "url", arg="arg")
|
||||
request_mock.assert_called_once_with("GET", "url", auth=github.auth, arg="arg")
|
||||
response_mock.raise_for_status.assert_called_once()
|
||||
response_mock.raise_for_status.assert_called_once_with()
|
||||
|
||||
|
||||
def test_request_exception(github: Github, mocker: MockerFixture) -> None:
|
||||
|
@ -10,4 +10,4 @@ def test_sync(rsync: Rsync, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.upload.rsync.Rsync._check_output")
|
||||
rsync.sync(Path("path"), [])
|
||||
check_output_mock.assert_called_once()
|
||||
check_output_mock.assert_called_once_with(*rsync.command, "path", rsync.remote, exception=None, logger=rsync.logger)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from typing import Any, List, Optional, Tuple
|
||||
@ -44,7 +46,7 @@ def test_files_remove(s3_remote_objects: List[Any]) -> None:
|
||||
remote_objects = {Path(item.key): item for item in s3_remote_objects}
|
||||
|
||||
S3.files_remove(local_files, remote_objects)
|
||||
remote_objects[Path("x86_64/a")].delete.assert_called_once()
|
||||
remote_objects[Path("x86_64/a")].delete.assert_called_once_with()
|
||||
|
||||
|
||||
def test_files_upload(s3: S3, s3_remote_objects: List[Any], mocker: MockerFixture) -> None:
|
||||
@ -104,13 +106,13 @@ def test_sync(s3: S3, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run sync command
|
||||
"""
|
||||
local_files_mock = mocker.patch("ahriman.core.upload.s3.S3.get_local_files")
|
||||
remote_objects_mock = mocker.patch("ahriman.core.upload.s3.S3.get_remote_objects")
|
||||
local_files_mock = mocker.patch("ahriman.core.upload.s3.S3.get_local_files", return_value=["a"])
|
||||
remote_objects_mock = mocker.patch("ahriman.core.upload.s3.S3.get_remote_objects", return_value=["b"])
|
||||
remove_files_mock = mocker.patch("ahriman.core.upload.s3.S3.files_remove")
|
||||
upload_files_mock = mocker.patch("ahriman.core.upload.s3.S3.files_upload")
|
||||
|
||||
s3.sync(Path("root"), [])
|
||||
local_files_mock.assert_called_once()
|
||||
remote_objects_mock.assert_called_once()
|
||||
remove_files_mock.assert_called_once()
|
||||
upload_files_mock.assert_called_once()
|
||||
remote_objects_mock.assert_called_once_with()
|
||||
local_files_mock.assert_called_once_with(Path("root"))
|
||||
upload_files_mock.assert_called_once_with(Path("root"), ["a"], ["b"])
|
||||
remove_files_mock.assert_called_once_with(["a"], ["b"])
|
||||
|
@ -25,7 +25,7 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
mocker.patch("ahriman.models.upload_settings.UploadSettings.from_option", return_value=UploadSettings.Disabled)
|
||||
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.sync")
|
||||
Upload.load("x86_64", configuration, "disabled").run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
upload_mock.assert_called_once_with(Path("path"), [])
|
||||
|
||||
|
||||
def test_upload_rsync(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -34,7 +34,7 @@ def test_upload_rsync(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.rsync.Rsync.sync")
|
||||
Upload.load("x86_64", configuration, "rsync").run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
upload_mock.assert_called_once_with(Path("path"), [])
|
||||
|
||||
|
||||
def test_upload_s3(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -43,7 +43,7 @@ def test_upload_s3(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.s3.S3.sync")
|
||||
Upload.load("x86_64", configuration, "customs3").run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
upload_mock.assert_called_once_with(Path("path"), [])
|
||||
|
||||
|
||||
def test_upload_github(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -52,4 +52,4 @@ def test_upload_github(configuration: Configuration, mocker: MockerFixture) -> N
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.github.Github.sync")
|
||||
Upload.load("x86_64", configuration, "github").run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
upload_mock.assert_called_once_with(Path("path"), [])
|
||||
|
Reference in New Issue
Block a user