Skip to content

Commit 87babd6

Browse files
author
Andrei Neagu
committed
fixed cli
1 parent 11b923c commit 87babd6

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import typer
55
from settings_library.docker_api_proxy import DockerApiProxysettings
6+
from settings_library.postgres import PostgresSettings
67
from settings_library.rabbit import RabbitSettings
78
from settings_library.utils_cli import (
89
create_settings_command,
@@ -49,14 +50,29 @@ def echo_dotenv(ctx: typer.Context, *, minimal: bool = True):
4950
RABBIT_SECURE=os.environ.get("RABBIT_SECURE", "0"),
5051
RABBIT_USER=os.environ.get("RABBIT_USER", "replace-with-rabbit-user"),
5152
RABBIT_PASSWORD=os.environ.get(
52-
"RABBIT_PASSWORD", "replace-with-rabbit-user"
53+
"RABBIT_PASSWORD", "replace-with-rabbit-password"
5354
),
5455
),
5556
),
5657
DYNAMIC_SCHEDULER_UI_STORAGE_SECRET=os.environ.get(
5758
"DYNAMIC_SCHEDULER_UI_STORAGE_SECRET",
5859
"replace-with-ui-storage-secret",
5960
),
61+
DYNAMIC_SCHEDULER_POSTGRES=os.environ.get(
62+
"DYNAMIC_SCHEDULER_POSTGRES",
63+
PostgresSettings.create_from_envs(
64+
POSTGRES_HOST=os.environ.get(
65+
"POSTGRES_HOST", "replace-with-postgres-host"
66+
),
67+
POSTGRES_USER=os.environ.get(
68+
"POSTGRES_USER", "replace-with-postgres-user"
69+
),
70+
POSTGRES_PASSWORD=os.environ.get(
71+
"POSTGRES_PASSWORD", "replace-with-postgres-password"
72+
),
73+
POSTGRES_DB=os.environ.get("POSTGRES_DB", "replace-with-postgres-db"),
74+
),
75+
),
6076
DYNAMIC_SCHEDULER_DOCKER_API_PROXY=os.environ.get(
6177
"DYNAMIC_SCHEDULER_DOCKER_API_PROXY",
6278
DockerApiProxysettings.create_from_envs(

services/dynamic-scheduler/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"pytest_simcore.environment_configs",
2828
"pytest_simcore.faker_projects_data",
2929
"pytest_simcore.faker_users_data",
30+
"pytest_simcore.postgres_service",
3031
"pytest_simcore.rabbit_service",
3132
"pytest_simcore.redis_service",
3233
"pytest_simcore.repository_paths",

services/dynamic-scheduler/tests/unit/test_cli.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint:disable=redefined-outer-name
12
# pylint:disable=unused-argument
23

34
import os
@@ -29,7 +30,9 @@ def test_cli_help_and_version(cli_runner: CliRunner):
2930
assert result.stdout.strip() == API_VERSION
3031

3132

32-
def test_echo_dotenv(cli_runner: CliRunner, monkeypatch: pytest.MonkeyPatch):
33+
def test_echo_dotenv(
34+
app_environment: EnvVarsDict, cli_runner: CliRunner, monkeypatch: pytest.MonkeyPatch
35+
):
3336
# simcore-service-dynamic-scheduler echo-dotenv
3437
result = cli_runner.invoke(cli_main, "echo-dotenv")
3538
assert result.exit_code == os.EX_OK, _format_cli_error(result)
@@ -38,35 +41,29 @@ def test_echo_dotenv(cli_runner: CliRunner, monkeypatch: pytest.MonkeyPatch):
3841

3942
with monkeypatch.context() as patch:
4043
setenvs_from_dict(patch, environs)
41-
assert ApplicationSettings.create_from_envs()
44+
ApplicationSettings.create_from_envs()
45+
46+
47+
def _get_default_environs(cli_runner: CliRunner) -> EnvVarsDict:
48+
result = cli_runner.invoke(cli_main, "echo-dotenv")
49+
assert result.exit_code == os.EX_OK, _format_cli_error(result)
50+
return load_dotenv(result.stdout)
4251

4352

4453
def test_list_settings(
4554
cli_runner: CliRunner, app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
4655
):
4756
with monkeypatch.context() as patch:
48-
setenvs_from_dict(
49-
patch,
50-
{
51-
**app_environment,
52-
"DYNAMIC_SCHEDULER_TRACING": "{}",
53-
"TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT": "http://replace-with-opentelemetry-collector",
54-
"TRACING_OPENTELEMETRY_COLLECTOR_PORT": "4318",
55-
},
56-
)
57+
setenvs_from_dict(patch, _get_default_environs(cli_runner))
5758

5859
# simcore-service-dynamic-scheduler settings --show-secrets --as-json
5960
result = cli_runner.invoke(
6061
cli_main, ["settings", "--show-secrets", "--as-json"]
6162
)
6263
assert result.exit_code == os.EX_OK, _format_cli_error(result)
6364

64-
print(result.output)
65-
settings = ApplicationSettings(result.output)
66-
assert settings.model_dump() == ApplicationSettings.create_from_envs().model_dump()
67-
68-
69-
def test_main(app_environment: EnvVarsDict):
70-
from simcore_service_dynamic_scheduler.main import the_app
71-
72-
assert the_app
65+
print(result.output)
66+
settings = ApplicationSettings(result.output)
67+
assert (
68+
settings.model_dump() == ApplicationSettings.create_from_envs().model_dump()
69+
)

0 commit comments

Comments
 (0)