From 10806e78ae68efa1629545501a3caa10b277527a Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Thu, 20 May 2021 00:52:10 +0300 Subject: [PATCH] add init subcommand --- src/ahriman/application/ahriman.py | 14 +++++++ src/ahriman/application/handlers/__init__.py | 1 + src/ahriman/application/handlers/init.py | 42 +++++++++++++++++++ .../application/handlers/test_handler_init.py | 16 +++++++ tests/ahriman/application/test_ahriman.py | 8 ++++ tests/ahriman/web/views/test_view_status.py | 2 +- 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/ahriman/application/handlers/init.py create mode 100644 tests/ahriman/application/handlers/test_handler_init.py diff --git a/src/ahriman/application/ahriman.py b/src/ahriman/application/ahriman.py index 0bf27659..5edcd4ad 100644 --- a/src/ahriman/application/ahriman.py +++ b/src/ahriman/application/ahriman.py @@ -56,6 +56,7 @@ def _parser() -> argparse.ArgumentParser: _set_check_parser(subparsers) _set_clean_parser(subparsers) _set_config_parser(subparsers) + _set_init_parser(subparsers) _set_key_import_parser(subparsers) _set_rebuild_parser(subparsers) _set_remove_parser(subparsers) @@ -132,6 +133,19 @@ def _set_config_parser(root: SubParserAction) -> argparse.ArgumentParser: return parser +def _set_init_parser(root: SubParserAction) -> argparse.ArgumentParser: + """ + add parser for init subcommand + :param root: subparsers for the commands + :return: created argument parser + """ + parser = root.add_parser("init", help="create repository tree", + description="create empty repository tree. Optional command for auto architecture support", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.set_defaults(handler=handlers.Init, no_report=True) + return parser + + def _set_key_import_parser(root: SubParserAction) -> argparse.ArgumentParser: """ add parser for key import subcommand diff --git a/src/ahriman/application/handlers/__init__.py b/src/ahriman/application/handlers/__init__.py index 21043f45..1a9fdb9d 100644 --- a/src/ahriman/application/handlers/__init__.py +++ b/src/ahriman/application/handlers/__init__.py @@ -22,6 +22,7 @@ from ahriman.application.handlers.handler import Handler from ahriman.application.handlers.add import Add from ahriman.application.handlers.clean import Clean from ahriman.application.handlers.dump import Dump +from ahriman.application.handlers.init import Init from ahriman.application.handlers.key_import import KeyImport from ahriman.application.handlers.rebuild import Rebuild from ahriman.application.handlers.remove import Remove diff --git a/src/ahriman/application/handlers/init.py b/src/ahriman/application/handlers/init.py new file mode 100644 index 00000000..acdaa9c3 --- /dev/null +++ b/src/ahriman/application/handlers/init.py @@ -0,0 +1,42 @@ +# +# Copyright (c) 2021 ahriman team. +# +# This file is part of ahriman +# (see https://github.com/arcan1s/ahriman). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import argparse + +from typing import Type + +from ahriman.application.application import Application +from ahriman.application.handlers.handler import Handler +from ahriman.core.configuration import Configuration + + +class Init(Handler): + """ + repository init handler + """ + + @classmethod + def run(cls: Type[Handler], args: argparse.Namespace, architecture: str, configuration: Configuration) -> None: + """ + callback for command line + :param args: command line args + :param architecture: repository architecture + :param configuration: configuration instance + """ + Application(architecture, configuration) diff --git a/tests/ahriman/application/handlers/test_handler_init.py b/tests/ahriman/application/handlers/test_handler_init.py new file mode 100644 index 00000000..195365b2 --- /dev/null +++ b/tests/ahriman/application/handlers/test_handler_init.py @@ -0,0 +1,16 @@ +import argparse + +from pytest_mock import MockerFixture + +from ahriman.application.handlers import Init +from ahriman.core.configuration import Configuration + + +def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None: + """ + must run command + """ + create_tree_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.create_tree") + + Init.run(args, "x86_64", configuration) + create_tree_mock.assert_called_once() diff --git a/tests/ahriman/application/test_ahriman.py b/tests/ahriman/application/test_ahriman.py index 80359c86..a92ffe18 100644 --- a/tests/ahriman/application/test_ahriman.py +++ b/tests/ahriman/application/test_ahriman.py @@ -73,6 +73,14 @@ def test_subparsers_config(parser: argparse.ArgumentParser) -> None: assert args.unsafe +def test_subparsers_init(parser: argparse.ArgumentParser) -> None: + """ + init command must imply no_report + """ + args = parser.parse_args(["-a", "x86_64", "init"]) + assert args.no_report + + def test_subparsers_key_import(parser: argparse.ArgumentParser) -> None: """ key-import command must imply lock and no_report diff --git a/tests/ahriman/web/views/test_view_status.py b/tests/ahriman/web/views/test_view_status.py index 5078870b..e5be2666 100644 --- a/tests/ahriman/web/views/test_view_status.py +++ b/tests/ahriman/web/views/test_view_status.py @@ -8,7 +8,7 @@ from ahriman.models.package import Package async def test_get(client: TestClient, package_ahriman: Package) -> None: """ - must generate web service status correctly) + must generate web service status correctly """ await client.post(f"/api/v1/packages/{package_ahriman.base}", json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})