Skip to content

Commit

Permalink
cli and models
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Nov 4, 2024
1 parent e1221aa commit 0f8556f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
Empty file.
3 changes: 2 additions & 1 deletion services/director/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
28 changes: 28 additions & 0 deletions services/director/tests/test__model_examples.py
Original file line number Diff line number Diff line change
@@ -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}"
)
34 changes: 34 additions & 0 deletions services/director/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0f8556f

Please sign in to comment.