From 0f8556fdfcd385ca6df6c53464a287e2c3b1a88e Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:25:17 +0100 Subject: [PATCH] cli and models --- .../models/__init__.py | 0 services/director/tests/conftest.py | 3 +- .../director/tests/test__model_examples.py | 28 +++++++++++++++ services/director/tests/test_cli.py | 34 +++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 services/director/src/simcore_service_director/models/__init__.py create mode 100644 services/director/tests/test__model_examples.py create mode 100644 services/director/tests/test_cli.py diff --git a/services/director/src/simcore_service_director/models/__init__.py b/services/director/src/simcore_service_director/models/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/services/director/tests/conftest.py b/services/director/tests/conftest.py index 925c6c26d03..d09e4623d40 100644 --- a/services/director/tests/conftest.py +++ b/services/director/tests/conftest.py @@ -4,8 +4,8 @@ # pylint: disable=too-many-arguments import os +from collections.abc import AsyncIterator from pathlib import Path -from typing import AsyncIterator import pytest import simcore_service_director @@ -19,6 +19,7 @@ pytest_plugins = [ "fixtures.fake_services", + "pytest_simcore.cli_runner", "pytest_simcore.docker_compose", "pytest_simcore.docker_registry", "pytest_simcore.docker_swarm", diff --git a/services/director/tests/test__model_examples.py b/services/director/tests/test__model_examples.py new file mode 100644 index 00000000000..d9604d738d6 --- /dev/null +++ b/services/director/tests/test__model_examples.py @@ -0,0 +1,28 @@ +# pylint: disable=protected-access +# pylint: disable=redefined-outer-name +# pylint: disable=too-many-arguments +# pylint: disable=unused-argument +# pylint: disable=unused-variable + +import json +from typing import Any + +import pytest +import simcore_service_director.models +from pydantic import BaseModel, ValidationError +from pytest_simcore.pydantic_models import walk_model_examples_in_package + + +@pytest.mark.parametrize( + "model_cls, example_name, example_data", + walk_model_examples_in_package(simcore_service_director.models), +) +def test_director_service_model_examples( + model_cls: type[BaseModel], example_name: int, example_data: Any +): + try: + assert model_cls.parse_obj(example_data) is not None + except ValidationError as err: + pytest.fail( + f"\n{example_name}: {json.dumps(example_data, indent=1)}\nError: {err}" + ) diff --git a/services/director/tests/test_cli.py b/services/director/tests/test_cli.py new file mode 100644 index 00000000000..3b42989bcff --- /dev/null +++ b/services/director/tests/test_cli.py @@ -0,0 +1,34 @@ +# pylint: disable=redefined-outer-name +# pylint: disable=unused-argument +# pylint: disable=unused-variable +# pylint: disable=too-many-arguments +import os + +from pytest_simcore.helpers.typing_env import EnvVarsDict +from simcore_service_director._meta import API_VERSION +from simcore_service_director.cli import main +from simcore_service_director.core.settings import ApplicationSettings +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, app_environment: EnvVarsDict): + result = cli_runner.invoke(main, ["settings", "--show-secrets", "--as-json"]) + assert result.exit_code == os.EX_OK + + settings = ApplicationSettings.parse_raw(result.output) + assert settings.dict() == ApplicationSettings.create_from_envs().dict() + + +def test_run(cli_runner: CliRunner): + result = cli_runner.invoke(main, ["run"]) + assert result.exit_code == 0 + assert "disabled" in result.stdout