diff --git a/src/ahriman/application/handlers/setup.py b/src/ahriman/application/handlers/setup.py index 565afaee..940a3892 100644 --- a/src/ahriman/application/handlers/setup.py +++ b/src/ahriman/application/handlers/setup.py @@ -20,6 +20,7 @@ import argparse from pathlib import Path +from pwd import getpwuid from typing import Type from ahriman.application.application import Application @@ -173,7 +174,9 @@ class Setup(Handler): packager(str): packager identifier (e.g. name, email) paths(RepositoryPaths): repository paths instance """ - (paths.root / ".makepkg.conf").write_text(f"PACKAGER='{packager}'\n", encoding="utf8") + uid, _ = paths.root_owner + home_dir = Path(getpwuid(uid).pw_dir) + (home_dir / ".makepkg.conf").write_text(f"PACKAGER='{packager}'\n", encoding="utf8") @staticmethod def configuration_create_sudo(paths: RepositoryPaths, prefix: str, architecture: str) -> None: diff --git a/tests/ahriman/application/handlers/conftest.py b/tests/ahriman/application/handlers/conftest.py new file mode 100644 index 00000000..e49f6179 --- /dev/null +++ b/tests/ahriman/application/handlers/conftest.py @@ -0,0 +1,17 @@ +import pytest + +from collections import namedtuple + + +_passwd = namedtuple("passwd", ["pw_dir"]) + + +@pytest.fixture +def passwd() -> _passwd: + """ + get passwd structure for the user + + Returns: + _passwd: passwd structure test instance + """ + return _passwd("home") diff --git a/tests/ahriman/application/handlers/test_handler_setup.py b/tests/ahriman/application/handlers/test_handler_setup.py index 7bf661ee..428ae34a 100644 --- a/tests/ahriman/application/handlers/test_handler_setup.py +++ b/tests/ahriman/application/handlers/test_handler_setup.py @@ -3,6 +3,7 @@ import pytest from pathlib import Path from pytest_mock import MockerFixture +from typing import Any from unittest import mock from ahriman.application.handlers import Setup @@ -130,15 +131,17 @@ def test_configuration_create_devtools_no_multilib(args: argparse.Namespace, rep def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths: RepositoryPaths, - mocker: MockerFixture) -> None: + passwd: Any, mocker: MockerFixture) -> None: """ must create makepkg configuration """ args = _default_args(args) - write_text_mock = mocker.patch("pathlib.Path.write_text") + 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) - write_text_mock.assert_called_once_with(pytest.helpers.anyvar(str, True), encoding="utf8") + write_text_mock.assert_called_once_with( + Path("home") / ".makepkg.conf", pytest.helpers.anyvar(str, True), encoding="utf8") def test_configuration_create_sudo(args: argparse.Namespace, repository_paths: RepositoryPaths,