improve setup command by --makeflags-jobs argument and fix repository sign on creation

This commit is contained in:
2022-11-29 16:06:41 +02:00
parent 0161617e36
commit 01eda513cf
8 changed files with 54 additions and 26 deletions

View File

@ -1,16 +0,0 @@
import pytest
from unittest.mock import MagicMock
@pytest.fixture
def passwd() -> MagicMock:
"""
get passwd structure for the user
Returns:
MagicMock: passwd structure test instance
"""
passwd = MagicMock()
passwd.pw_dir = "home"
return passwd

View File

@ -25,6 +25,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
args.build_as_user = "ahriman"
args.build_command = "ahriman"
args.from_configuration = Path("/usr/share/devtools/pacman-extra.conf")
args.makeflags_jobs = True
args.multilib = True
args.packager = "John Doe <john@doe.com>"
args.repository = "aur-clone"
@ -54,10 +55,10 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository_
args, "x86_64", args.repository, configuration.include, repository_paths)
devtools_configuration_mock.assert_called_once_with(
args.build_command, "x86_64", args.from_configuration, args.multilib, args.repository, repository_paths)
makepkg_configuration_mock.assert_called_once_with(args.packager, repository_paths)
makepkg_configuration_mock.assert_called_once_with(args.packager, args.makeflags_jobs, repository_paths)
sudo_configuration_mock.assert_called_once_with(repository_paths, args.build_command, "x86_64")
executable_mock.assert_called_once_with(repository_paths, args.build_command, "x86_64")
init_mock.assert_called_once()
init_mock.assert_called_once_with()
def test_build_command(args: argparse.Namespace) -> None:
@ -138,7 +139,7 @@ def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths
mocker.patch("ahriman.application.handlers.setup.getpwuid", return_value=passwd)
write_text_mock = mocker.patch("pathlib.Path.write_text", autospec=True)
Setup.configuration_create_makepkg(args.packager, repository_paths)
Setup.configuration_create_makepkg(args.packager, args.makeflags_jobs, repository_paths)
write_text_mock.assert_called_once_with(
Path("home") / ".makepkg.conf", pytest.helpers.anyvar(str, True), encoding="utf8")

View File

@ -363,6 +363,19 @@ def pacman(configuration: Configuration) -> Pacman:
return Pacman("x86_64", configuration, refresh_database=0)
@pytest.fixture
def passwd() -> MagicMock:
"""
get passwd structure for the user
Returns:
MagicMock: passwd structure test instance
"""
passwd = MagicMock()
passwd.pw_dir = "home"
return passwd
@pytest.fixture
def remote_source() -> RemoteSource:
"""

View File

@ -1,11 +1,13 @@
import datetime
import logging
import os
import pytest
import requests
import subprocess
from pathlib import Path
from pytest_mock import MockerFixture
from typing import Any
from unittest.mock import MagicMock
from ahriman.core.exceptions import BuildError, OptionError, UnsafeRunError
@ -75,6 +77,19 @@ def test_check_output_multiple_with_stdin_newline() -> None:
input_data="multiple\nlines\n") == "multiple\nlines"
def test_check_output_with_user(passwd: Any, mocker: MockerFixture) -> None:
"""
must run command as specified user and set its homedir
"""
assert check_output("python", "-c", "import os; print(os.getenv('HOME'))") != passwd.pw_dir
getpwuid_mock = mocker.patch("ahriman.core.util.getpwuid", return_value=passwd)
user = os.getuid()
assert check_output("python", "-c", "import os; print(os.getenv('HOME'))", user=user) == passwd.pw_dir
getpwuid_mock.assert_called_once_with(user)
def test_check_output_failure(mocker: MockerFixture) -> None:
"""
must process exception correctly