mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-11-04 07:43:42 +00:00 
			
		
		
		
	Setup command (#9)
* block issues without templates * add setup subcommand * handle devtools config correctly
This commit is contained in:
		@ -6,12 +6,17 @@ from ahriman.application.handlers import Add
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.without_dependencies = False
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.without_dependencies = False
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.add")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,15 +6,20 @@ from ahriman.application.handlers import Clean
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.no_build = False
 | 
			
		||||
    args.no_cache = False
 | 
			
		||||
    args.no_chroot = False
 | 
			
		||||
    args.no_manual = False
 | 
			
		||||
    args.no_packages = False
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.clean")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,11 +6,16 @@ from ahriman.application.handlers import Remove
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.package = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.remove")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,11 +6,16 @@ from ahriman.application.handlers import Report
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.target = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args.target = []
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.report")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										145
									
								
								tests/ahriman/application/handlers/test_handler_setup.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								tests/ahriman/application/handlers/test_handler_setup.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,145 @@
 | 
			
		||||
import argparse
 | 
			
		||||
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from pytest_mock import MockerFixture
 | 
			
		||||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
from ahriman.application.handlers import Setup
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
from ahriman.models.repository_paths import RepositoryPaths
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.build_command = "ahriman"
 | 
			
		||||
    args.from_config = "/usr/share/devtools/pacman-extra.conf"
 | 
			
		||||
    args.no_multilib = False
 | 
			
		||||
    args.packager = "John Doe <john@doe.com>"
 | 
			
		||||
    args.repository = "aur-clone"
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    ahriman_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_ahriman_configuration")
 | 
			
		||||
    devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_devtools_configuration")
 | 
			
		||||
    makepkg_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_makepkg_configuration")
 | 
			
		||||
    sudo_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_sudo_configuration")
 | 
			
		||||
    executable_mock = mocker.patch("ahriman.application.handlers.setup.Setup.create_executable")
 | 
			
		||||
 | 
			
		||||
    Setup.run(args, "x86_64", configuration)
 | 
			
		||||
    ahriman_configuration_mock.assert_called_once()
 | 
			
		||||
    devtools_configuration_mock.assert_called_once()
 | 
			
		||||
    makepkg_configuration_mock.assert_called_once()
 | 
			
		||||
    sudo_configuration_mock.assert_called_once()
 | 
			
		||||
    executable_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_build_command(args: argparse.Namespace) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must generate correct build command name
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    assert Setup.build_command(args.build_command, "x86_64").name == f"{args.build_command}-x86_64-build"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_ahriman_configuration(args: argparse.Namespace, configuration: Configuration,
 | 
			
		||||
                                      mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must create configuration for the service
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.open")
 | 
			
		||||
    add_section_mock = mocker.patch("configparser.RawConfigParser.add_section")
 | 
			
		||||
    set_mock = mocker.patch("configparser.RawConfigParser.set")
 | 
			
		||||
    write_mock = mocker.patch("configparser.RawConfigParser.write")
 | 
			
		||||
 | 
			
		||||
    command = Setup.build_command(args.build_command, "x86_64")
 | 
			
		||||
    Setup.create_ahriman_configuration(args.build_command, "x86_64", args.repository, configuration.include)
 | 
			
		||||
    add_section_mock.assert_has_calls([
 | 
			
		||||
        mock.call("build"),
 | 
			
		||||
        mock.call("repository"),
 | 
			
		||||
    ])
 | 
			
		||||
    set_mock.assert_has_calls([
 | 
			
		||||
        mock.call("build", "build_command", str(command)),
 | 
			
		||||
        mock.call("repository", "name", args.repository),
 | 
			
		||||
    ])
 | 
			
		||||
    write_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_devtools_configuration(args: argparse.Namespace, repository_paths: RepositoryPaths,
 | 
			
		||||
                                       mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must create configuration for the devtools
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.open")
 | 
			
		||||
    mocker.patch("configparser.RawConfigParser.set")
 | 
			
		||||
    add_section_mock = mocker.patch("configparser.RawConfigParser.add_section")
 | 
			
		||||
    write_mock = mocker.patch("configparser.RawConfigParser.write")
 | 
			
		||||
 | 
			
		||||
    Setup.create_devtools_configuration(args.build_command, "x86_64", Path(args.from_config), args.no_multilib,
 | 
			
		||||
                                        args.repository, repository_paths)
 | 
			
		||||
    add_section_mock.assert_has_calls([
 | 
			
		||||
        mock.call("multilib"),
 | 
			
		||||
        mock.call(args.repository)
 | 
			
		||||
    ])
 | 
			
		||||
    write_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_devtools_configuration_no_multilib(args: argparse.Namespace, repository_paths: RepositoryPaths,
 | 
			
		||||
                                                   mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must create configuration for the devtools without multilib
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.open")
 | 
			
		||||
    mocker.patch("configparser.RawConfigParser.set")
 | 
			
		||||
    add_section_mock = mocker.patch("configparser.RawConfigParser.add_section")
 | 
			
		||||
    write_mock = mocker.patch("configparser.RawConfigParser.write")
 | 
			
		||||
 | 
			
		||||
    Setup.create_devtools_configuration(args.build_command, "x86_64", Path(args.from_config), True,
 | 
			
		||||
                                        args.repository, repository_paths)
 | 
			
		||||
    add_section_mock.assert_called_once()
 | 
			
		||||
    write_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_makepkg_configuration(args: argparse.Namespace, repository_paths: RepositoryPaths,
 | 
			
		||||
                                      mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must create makepkg configuration
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    write_text_mock = mocker.patch("pathlib.Path.write_text")
 | 
			
		||||
 | 
			
		||||
    Setup.create_makepkg_configuration(args.packager, repository_paths)
 | 
			
		||||
    write_text_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_sudo_configuration(args: argparse.Namespace, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must create sudo configuration
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    chmod_text_mock = mocker.patch("pathlib.Path.chmod")
 | 
			
		||||
    write_text_mock = mocker.patch("pathlib.Path.write_text")
 | 
			
		||||
 | 
			
		||||
    Setup.create_sudo_configuration(args.build_command, "x86_64")
 | 
			
		||||
    chmod_text_mock.assert_called_with(0o400)
 | 
			
		||||
    write_text_mock.assert_called_once()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_create_executable(args: argparse.Namespace, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must create executable
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    symlink_text_mock = mocker.patch("pathlib.Path.symlink_to")
 | 
			
		||||
    unlink_text_mock = mocker.patch("pathlib.Path.unlink")
 | 
			
		||||
 | 
			
		||||
    Setup.create_executable(args.build_command, "x86_64")
 | 
			
		||||
    symlink_text_mock.assert_called_once()
 | 
			
		||||
    unlink_text_mock.assert_called_once()
 | 
			
		||||
@ -6,11 +6,16 @@ from ahriman.application.handlers import Sign
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.package = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.sign")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,13 +6,17 @@ from ahriman.application.handlers import Status
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.ahriman = True
 | 
			
		||||
    args.package = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args.ahriman = True
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.without_dependencies = False
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.core.status.client.Client.get_self")
 | 
			
		||||
    packages_mock = mocker.patch("ahriman.core.status.client.Client.get")
 | 
			
		||||
 | 
			
		||||
@ -6,11 +6,16 @@ from ahriman.application.handlers import Sync
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.target = []
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args.target = []
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.sync")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,15 +6,20 @@ from ahriman.application.handlers import Update
 | 
			
		||||
from ahriman.core.configuration import Configuration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args.dry_run = False
 | 
			
		||||
    args.no_aur = False
 | 
			
		||||
    args.no_manual = False
 | 
			
		||||
    args.no_vcs = False
 | 
			
		||||
    return args
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must run command
 | 
			
		||||
    """
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    application_mock = mocker.patch("ahriman.application.application.Application.update")
 | 
			
		||||
    updates_mock = mocker.patch("ahriman.application.application.Application.get_updates")
 | 
			
		||||
@ -28,11 +33,8 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, moc
 | 
			
		||||
    """
 | 
			
		||||
    must run simplified command
 | 
			
		||||
    """
 | 
			
		||||
    args.package = []
 | 
			
		||||
    args = _default_args(args)
 | 
			
		||||
    args.dry_run = True
 | 
			
		||||
    args.no_aur = False
 | 
			
		||||
    args.no_manual = False
 | 
			
		||||
    args.no_vcs = False
 | 
			
		||||
    mocker.patch("pathlib.Path.mkdir")
 | 
			
		||||
    updates_mock = mocker.patch("ahriman.application.application.Application.get_updates")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -26,6 +26,14 @@ def test_subparsers_check(parser: argparse.ArgumentParser) -> None:
 | 
			
		||||
    assert args.dry_run
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_subparsers_clean(parser: argparse.ArgumentParser) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    clean command must imply unsafe
 | 
			
		||||
    """
 | 
			
		||||
    args = parser.parse_args(["-a", "x86_64", "clean"])
 | 
			
		||||
    assert args.unsafe
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_subparsers_config(parser: argparse.ArgumentParser) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    config command must imply lock, no_report and unsafe
 | 
			
		||||
@ -36,6 +44,16 @@ def test_subparsers_config(parser: argparse.ArgumentParser) -> None:
 | 
			
		||||
    assert args.unsafe
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_subparsers_setup(parser: argparse.ArgumentParser) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    setup command must imply lock, no_report and unsafe
 | 
			
		||||
    """
 | 
			
		||||
    args = parser.parse_args(["-a", "x86_64", "setup", "--packager", "John Doe <john@doe.com>"])
 | 
			
		||||
    assert args.lock is None
 | 
			
		||||
    assert args.no_report
 | 
			
		||||
    assert args.unsafe
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_subparsers_status(parser: argparse.ArgumentParser) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    status command must imply lock, no_report and unsafe
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user