From 972d87f2a2b7286f2e6091b2bc8497472e950811 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:30:59 +0100 Subject: [PATCH] new cli --- .../src/simcore_service_catalog/cli.py | 9 ++++-- services/catalog/tests/unit/conftest.py | 1 + services/catalog/tests/unit/test_cli.py | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 services/catalog/tests/unit/test_cli.py diff --git a/services/catalog/src/simcore_service_catalog/cli.py b/services/catalog/src/simcore_service_catalog/cli.py index 5218b369ecc..0d4fbf5107b 100644 --- a/services/catalog/src/simcore_service_catalog/cli.py +++ b/services/catalog/src/simcore_service_catalog/cli.py @@ -5,9 +5,13 @@ from settings_library.http_client_request import ClientRequestSettings from settings_library.postgres import PostgresSettings from settings_library.rabbit import RabbitSettings -from settings_library.utils_cli import create_settings_command, print_as_envfile +from settings_library.utils_cli import ( + create_settings_command, + create_version_callback, + print_as_envfile, +) -from ._meta import PROJECT_NAME +from ._meta import PROJECT_NAME, __version__ from .core.settings import ApplicationSettings, DirectorSettings _logger = logging.getLogger(__name__) @@ -18,6 +22,7 @@ main.command()( create_settings_command(settings_cls=ApplicationSettings, logger=_logger) ) +main.callback()(create_version_callback(__version__)) @main.command() diff --git a/services/catalog/tests/unit/conftest.py b/services/catalog/tests/unit/conftest.py index 865b48be996..278af317091 100644 --- a/services/catalog/tests/unit/conftest.py +++ b/services/catalog/tests/unit/conftest.py @@ -31,6 +31,7 @@ from simcore_service_catalog.core.settings import ApplicationSettings pytest_plugins = [ + "pytest_simcore.cli_runner", "pytest_simcore.docker_compose", "pytest_simcore.docker_registry", "pytest_simcore.docker_swarm", diff --git a/services/catalog/tests/unit/test_cli.py b/services/catalog/tests/unit/test_cli.py new file mode 100644 index 00000000000..9922f9e929a --- /dev/null +++ b/services/catalog/tests/unit/test_cli.py @@ -0,0 +1,30 @@ +# pylint:disable=unused-variable +# pylint:disable=unused-argument +# pylint:disable=redefined-outer-name + +import os + +from simcore_service_catalog._meta import API_VERSION +from simcore_service_catalog.cli import main +from typer.testing import CliRunner + + +def test_cli_help_and_version(cli_runner: CliRunner): + result = cli_runner.invoke(main, "--help") + assert result.exit_code == os.EX_OK, result.output + + result = cli_runner.invoke(main, "--version") + assert result.exit_code == os.EX_OK, result.output + assert result.stdout.strip() == API_VERSION + + +def test_settings(cli_runner: CliRunner): + result = cli_runner.invoke(main, ["settings"]) + assert result.exit_code == 0 + assert "APP_NAME=simcore-service-autoscaling" in result.stdout + + +def test_run(cli_runner: CliRunner): + result = cli_runner.invoke(main, ["run"]) + assert result.exit_code == 0 + assert "disabled" in result.stdout