diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json index dc3fd1cd481..ea3d423bcb8 100644 --- a/.vscode/launch.template.json +++ b/.vscode/launch.template.json @@ -44,6 +44,28 @@ "justMyCode": false }, { + // This test adds --external-envfile and expects a file named ".secrets" in the workspace root. + "name": "Python: Test w/ repo.config", + "type": "debugpy", + "request": "launch", + "module": "pytest", + "args": [ + "--ff", + "--log-cli-level=INFO", + "--external-envfile=${workspaceFolder}/.secrets", + "--pdb", + "--setup-show", + "--durations=5", + "-s", + "-vv", + "${file}" + ], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "justMyCode": false + }, + { + // This tests enables the httpx spy and dumps captures in a json. Mainly for api-server "name": "Python: Test-Httpx-Spy", "type": "debugpy", "request": "launch", diff --git a/packages/pytest-simcore/src/pytest_simcore/environment_configs.py b/packages/pytest-simcore/src/pytest_simcore/environment_configs.py index 6495f1f7cc1..d953465d96a 100644 --- a/packages/pytest-simcore/src/pytest_simcore/environment_configs.py +++ b/packages/pytest-simcore/src/pytest_simcore/environment_configs.py @@ -3,6 +3,7 @@ # pylint: disable=unused-variable +import logging import re from pathlib import Path from typing import Any @@ -12,6 +13,8 @@ from .helpers.monkeypatch_envs import load_dotenv, setenvs_from_dict from .helpers.typing_env import EnvVarsDict +_logger = logging.getLogger(__name__) + def pytest_addoption(parser: pytest.Parser): simcore_group = parser.getgroup("simcore") @@ -20,12 +23,17 @@ def pytest_addoption(parser: pytest.Parser): action="store", type=Path, default=None, - help="Path to an env file. Consider passing a link to repo configs, i.e. `ln -s /path/to/osparc-ops-config/repo.config`", + help="Path to an env file. Replaces .env-devel in the tests by an external envfile." + "e.g. consider " + " `ln -s /path/to/osparc-ops-config/repo.config .secrets` and then " + " `pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py`", ) @pytest.fixture(scope="session") -def external_envfile_dict(request: pytest.FixtureRequest) -> EnvVarsDict: +def external_envfile_dict( + request: pytest.FixtureRequest, osparc_simcore_root_dir: Path +) -> EnvVarsDict: """ If a file under test folder prefixed with `.env-secret` is present, then this fixture captures it. @@ -35,19 +43,43 @@ def external_envfile_dict(request: pytest.FixtureRequest) -> EnvVarsDict: """ envs = {} if envfile := request.config.getoption("--external-envfile"): - print("🚨 EXTERNAL `envfile` option detected. Loading", envfile, "...") + _logger.warning( + "🚨 EXTERNAL `envfile` option detected. Loading '%s' ...", envfile + ) assert isinstance(envfile, Path) assert envfile.exists() assert envfile.is_file() + envfile = envfile.resolve() + osparc_simcore_root_dir = osparc_simcore_root_dir.resolve() + + if osparc_simcore_root_dir in envfile.parents and not any( + term in envfile.name.lower() for term in ("ignore", "secret") + ): + _logger.warning( + "🚨 CAUTION: The external envfile '%s' may contain sensitive data and could be accidentally versioned. " + "To prevent this, include the words 'secret' or 'ignore' in the filename.", + envfile.name, + ) + envs = load_dotenv(envfile) + if envs: + response = input( + f"🚨 CAUTION: You are about to run tests using environment variables loaded from '{envfile}'.\n" + "This may cause tests to interact with or modify real external systems (e.g., production or staging environments).\n" + "Proceeding could result in data loss or unintended side effects.\n" + "Are you sure you want to continue? [y/N]: " + ) + if response.strip().lower() not in ("y", "yes"): + pytest.exit("Aborted by user due to external envfile usage.") + return envs @pytest.fixture(scope="session") -def skip_if_external_envfile_dict(external_envfile_dict: EnvVarsDict) -> None: +def skip_if_no_external_envfile(external_envfile_dict: EnvVarsDict) -> None: if not external_envfile_dict: pytest.skip(reason="Skipping test since external-envfile is not set") diff --git a/services/agent/tests/unit/test_core_settings.py b/services/agent/tests/unit/test_core_settings.py new file mode 100644 index 00000000000..7e3fb5b5d2d --- /dev/null +++ b/services/agent/tests/unit/test_core_settings.py @@ -0,0 +1,18 @@ +# pylint: disable=unused-variable +# pylint: disable=unused-argument +# pylint: disable=redefined-outer-name + + +from pytest_simcore.helpers.monkeypatch_envs import ( + EnvVarsDict, +) +from simcore_service_agent.core.settings import ApplicationSettings + + +def test_valid_application_settings(mock_environment: EnvVarsDict): + assert mock_environment + + settings = ApplicationSettings() # type: ignore + assert settings + + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/api-server/src/simcore_service_api_server/api/dependencies/models_schemas_jobs_filters.py b/services/api-server/src/simcore_service_api_server/api/dependencies/models_schemas_jobs_filters.py index c4683f653d1..f18198cbba1 100644 --- a/services/api-server/src/simcore_service_api_server/api/dependencies/models_schemas_jobs_filters.py +++ b/services/api-server/src/simcore_service_api_server/api/dependencies/models_schemas_jobs_filters.py @@ -18,7 +18,9 @@ def get_job_metadata_filter( *Format*: `key:pattern` where pattern can contain glob wildcards """ ), - example=["key1:val*", "key2:exactval"], + examples=[ + ["key1:val*", "key2:exactval"], + ], ), ] = None, ) -> JobMetadataFilter | None: diff --git a/services/api-server/tests/unit/test_core_settings.py b/services/api-server/tests/unit/test_core_settings.py index feb5052ab0f..a2301b4951d 100644 --- a/services/api-server/tests/unit/test_core_settings.py +++ b/services/api-server/tests/unit/test_core_settings.py @@ -3,38 +3,16 @@ # pylint: disable=redefined-outer-name -import pytest from pytest_simcore.helpers.monkeypatch_envs import ( EnvVarsDict, - delenvs_from_dict, - setenvs_from_dict, ) from simcore_service_api_server.core.settings import ApplicationSettings -@pytest.fixture -def app_environment( - monkeypatch: pytest.MonkeyPatch, - app_environment: EnvVarsDict, - external_envfile_dict: EnvVarsDict, -) -> EnvVarsDict: - """ - NOTE: To run against repo.config in osparc-config repo - - ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets - pytest --external-envfile=.secrets tests/unit/test_core_settings.py - - """ - if external_envfile_dict: - delenvs_from_dict(monkeypatch, app_environment, raising=False) - return setenvs_from_dict( - monkeypatch, - {**external_envfile_dict}, - ) - return app_environment +def test_valid_application_settings(app_environment: EnvVarsDict): + assert app_environment + settings = ApplicationSettings() # type: ignore + assert settings -def test_unit_app_environment(app_environment: EnvVarsDict): - assert app_environment - settings = ApplicationSettings.create_from_envs() - print("captured settings: \n", settings.model_dump_json(indent=2)) + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/autoscaling/tests/unit/test_core_settings.py b/services/autoscaling/tests/unit/test_core_settings.py index bc63be64cff..a7d3b70fe27 100644 --- a/services/autoscaling/tests/unit/test_core_settings.py +++ b/services/autoscaling/tests/unit/test_core_settings.py @@ -2,7 +2,13 @@ # pylint: disable=redefined-outer-name # pylint: disable=unused-argument # pylint: disable=unused-variable +""" +We can validate actual .env files (also refered as `repo.config` files) by passing them via the CLI +$ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets +$ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py + +""" import datetime import json import logging diff --git a/services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py b/services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py index a46a75c8006..19bb4c69c89 100644 --- a/services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py +++ b/services/autoscaling/tests/unit/test_modules_auto_scaling_dynamic.py @@ -1069,7 +1069,7 @@ async def test_cluster_scaling_up_and_down( ], ) async def test_cluster_scaling_up_and_down_against_aws( - skip_if_external_envfile_dict: None, + skip_if_no_external_envfile: None, external_ec2_instances_allowed_types: None | dict[str, EC2InstanceBootSpecific], with_labelize_drain_nodes: EnvVarsDict, app_with_docker_join_drained: EnvVarsDict, diff --git a/services/autoscaling/tests/unit/test_modules_buffer_machine_core.py b/services/autoscaling/tests/unit/test_modules_buffer_machine_core.py index 99939ede125..32d38c0eea9 100644 --- a/services/autoscaling/tests/unit/test_modules_buffer_machine_core.py +++ b/services/autoscaling/tests/unit/test_modules_buffer_machine_core.py @@ -532,7 +532,7 @@ def pre_pull_images( async def test_monitor_buffer_machines_against_aws( - skip_if_external_envfile_dict: None, + skip_if_no_external_envfile: None, disable_buffers_pool_background_task: None, disable_autoscaling_background_task: None, disabled_rabbitmq: None, diff --git a/services/catalog/tests/unit/conftest.py b/services/catalog/tests/unit/conftest.py index 296cc47bd19..4233d7b3c7a 100644 --- a/services/catalog/tests/unit/conftest.py +++ b/services/catalog/tests/unit/conftest.py @@ -15,10 +15,7 @@ import pytest import respx import simcore_service_catalog -import simcore_service_catalog.core.application import simcore_service_catalog.core.events -import simcore_service_catalog.repository -import simcore_service_catalog.repository.events import yaml from asgi_lifespan import LifespanManager from faker import Faker diff --git a/services/catalog/tests/unit/test_core_settings.py b/services/catalog/tests/unit/test_core_settings.py index 9f94c6c3588..15476b4a37c 100644 --- a/services/catalog/tests/unit/test_core_settings.py +++ b/services/catalog/tests/unit/test_core_settings.py @@ -3,19 +3,13 @@ # pylint: disable=unused-variable # pylint: disable=too-many-arguments - from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_service_catalog.core.settings import ApplicationSettings -def test_valid_web_application_settings(app_environment: EnvVarsDict): - """ - We can validate actual .env files (also refered as `repo.config` files) by passing them via the CLI - - $ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets - $ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py +def test_valid_application_settings(app_environment: EnvVarsDict): + assert app_environment - """ settings = ApplicationSettings() # type: ignore assert settings diff --git a/services/clusters-keeper/tests/unit/test_core_settings.py b/services/clusters-keeper/tests/unit/test_core_settings.py index 021d7f4f107..bbd7073d77f 100644 --- a/services/clusters-keeper/tests/unit/test_core_settings.py +++ b/services/clusters-keeper/tests/unit/test_core_settings.py @@ -9,7 +9,10 @@ import pytest from aws_library.ec2 import EC2InstanceBootSpecific from pydantic import ValidationError -from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict +from pytest_simcore.helpers.monkeypatch_envs import ( + EnvVarsDict, + setenvs_from_dict, +) from simcore_service_clusters_keeper.core.settings import ApplicationSettings from types_aiobotocore_ec2.literals import InstanceTypeType @@ -110,3 +113,17 @@ def test_valid_primary_custom_tags( {"PRIMARY_EC2_INSTANCES_CUSTOM_TAGS": json.dumps(valid_tag)}, ) ApplicationSettings.create_from_envs() + + +def test_valid_application_settings( + monkeypatch: pytest.MonkeyPatch, + app_environment: EnvVarsDict, +): + # Mock + assert app_environment + + # Test + settings = ApplicationSettings() # type: ignore + assert settings + + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/datcore-adapter/tests/unit/test_core_settings.py b/services/datcore-adapter/tests/unit/test_core_settings.py index 6ab82562ad2..31496dee4eb 100644 --- a/services/datcore-adapter/tests/unit/test_core_settings.py +++ b/services/datcore-adapter/tests/unit/test_core_settings.py @@ -2,41 +2,17 @@ # pylint: disable=unused-argument # pylint: disable=redefined-outer-name - -import pytest from pytest_simcore.helpers.monkeypatch_envs import ( EnvVarsDict, - delenvs_from_dict, - setenvs_from_dict, ) from simcore_service_datcore_adapter.core.settings import ApplicationSettings -@pytest.fixture -def app_environment( - monkeypatch: pytest.MonkeyPatch, - app_environment: EnvVarsDict, - external_envfile_dict: EnvVarsDict, -) -> EnvVarsDict: - """ - NOTE: To run against repo.config in osparc-config repo - - ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets - pytest --external-envfile=.secrets tests/unit/test_core_settings.py - - """ - if external_envfile_dict: - delenvs_from_dict(monkeypatch, app_environment, raising=False) - return setenvs_from_dict( - monkeypatch, - {**external_envfile_dict}, - ) - return app_environment - - -def test_unit_app_environment(app_environment: EnvVarsDict): +def test_valid_application_settings(app_environment: EnvVarsDict): assert app_environment - settings = ApplicationSettings.create_from_envs() - print("captured settings: \n", settings.model_dump_json(indent=2)) + + settings = ApplicationSettings() # type: ignore + assert settings + assert settings == ApplicationSettings.create_from_envs() assert settings.PENNSIEVE diff --git a/services/director-v2/tests/unit/test_core_settings.py b/services/director-v2/tests/unit/test_core_settings.py index 2151d64cfa5..6da0d9772a5 100644 --- a/services/director-v2/tests/unit/test_core_settings.py +++ b/services/director-v2/tests/unit/test_core_settings.py @@ -27,7 +27,7 @@ def _get_backend_type_options() -> set[str]: def test_supported_backends_did_not_change() -> None: _EXPECTED = {"AWS", "CEPH", "MINIO"} - assert _EXPECTED == _get_backend_type_options(), ( + assert _get_backend_type_options() == _EXPECTED, ( "Backend configuration change, please code support for " "it in volumes_resolver -> _get_s3_volume_driver_config. " "When done, adjust above list." diff --git a/services/director/tests/unit/test_core_settings.py b/services/director/tests/unit/test_core_settings.py index 5e8b42c1268..122d6baea9a 100644 --- a/services/director/tests/unit/test_core_settings.py +++ b/services/director/tests/unit/test_core_settings.py @@ -3,7 +3,6 @@ # pylint: disable=unused-variable # pylint: disable=too-many-arguments - import datetime import pytest @@ -16,14 +15,7 @@ from simcore_service_director.core.settings import ApplicationSettings -def test_valid_web_application_settings(app_environment: EnvVarsDict): - """ - We validate actual envfiles (e.g. repo.config files) by passing them via the CLI - - $ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets - $ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py - - """ +def test_valid_application_settings(app_environment: EnvVarsDict): settings = ApplicationSettings() # type: ignore assert settings diff --git a/services/director/tests/unit/test_registry_proxy.py b/services/director/tests/unit/test_registry_proxy.py index c15ccd7df7f..d4cb4d63c97 100644 --- a/services/director/tests/unit/test_registry_proxy.py +++ b/services/director/tests/unit/test_registry_proxy.py @@ -278,7 +278,7 @@ def configure_number_concurrency_calls( def test_list_services_performance( - skip_if_external_envfile_dict: None, + skip_if_no_external_envfile: None, configure_external_registry_access: EnvVarsDict, configure_number_concurrency_calls: EnvVarsDict, registry_settings: RegistrySettings, diff --git a/services/dynamic-scheduler/tests/unit/test_core_settings.py b/services/dynamic-scheduler/tests/unit/test_core_settings.py new file mode 100644 index 00000000000..d874f5a15b9 --- /dev/null +++ b/services/dynamic-scheduler/tests/unit/test_core_settings.py @@ -0,0 +1,17 @@ +# pylint: disable=unused-variable +# pylint: disable=unused-argument +# pylint: disable=redefined-outer-name + + +from pytest_simcore.helpers.monkeypatch_envs import ( + EnvVarsDict, +) +from simcore_service_dynamic_scheduler.core.settings import ApplicationSettings + + +def test_valid_application_settings(app_environment: EnvVarsDict): + assert app_environment + + settings = ApplicationSettings() # type: ignore + assert settings + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/efs-guardian/tests/unit/test_core_settings.py b/services/efs-guardian/tests/unit/test_core_settings.py index 0d72653a8e4..ba1d011d68b 100644 --- a/services/efs-guardian/tests/unit/test_core_settings.py +++ b/services/efs-guardian/tests/unit/test_core_settings.py @@ -1,20 +1,21 @@ # pylint: disable=redefined-outer-name # pylint: disable=unused-argument # pylint: disable=unused-variable +""" +We can validate actual .env files (also refered as `repo.config` files) by passing them via the CLI +$ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets +$ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py + +""" from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict from simcore_service_efs_guardian.core.settings import ApplicationSettings -def test_settings(app_environment: EnvVarsDict): - """ - We validate actual envfiles (e.g. repo.config files) by passing them via the CLI - - $ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets - $ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py +def test_valid_application_settings(app_environment: EnvVarsDict): + assert app_environment - """ settings = ApplicationSettings() # type: ignore assert settings diff --git a/services/invitations/tests/unit/test_core_settings.py b/services/invitations/tests/unit/test_core_settings.py index 7c68e809eda..f639cc0b0f3 100644 --- a/services/invitations/tests/unit/test_core_settings.py +++ b/services/invitations/tests/unit/test_core_settings.py @@ -2,7 +2,13 @@ # pylint: disable=unused-argument # pylint: disable=unused-variable # pylint: disable=too-many-arguments +""" +We can validate actual .env files (also refered as `repo.config` files) by passing them via the CLI +$ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets +$ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py + +""" import pytest from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict @@ -29,6 +35,10 @@ def test_valid_cli_application_settings( assert settings -def test_valid_web_application_settings(app_environment: EnvVarsDict): - settings = ApplicationSettings.create_from_envs() +def test_valid_application_settings(app_environment: EnvVarsDict): + assert app_environment + + settings = ApplicationSettings() # type: ignore assert settings + + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/notifications/tests/conftest.py b/services/notifications/tests/conftest.py index a310c11b5d5..ba95f08d2e1 100644 --- a/services/notifications/tests/conftest.py +++ b/services/notifications/tests/conftest.py @@ -2,6 +2,8 @@ # pylint: disable=unused-argument +from pathlib import Path + import pytest from models_library.basic_types import BootModeEnum from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict @@ -9,17 +11,31 @@ pytest_plugins = [ "pytest_simcore.docker_compose", "pytest_simcore.docker_swarm", + "pytest_simcore.environment_configs", "pytest_simcore.postgres_service", "pytest_simcore.rabbit_service", "pytest_simcore.repository_paths", ] +@pytest.fixture(scope="session") +def project_slug_dir(osparc_simcore_root_dir: Path) -> Path: + # fixtures in pytest_simcore.environs + service_folder = osparc_simcore_root_dir / "services" / "notifications" + assert service_folder.exists() + assert any(service_folder.glob("src/simcore_service_notifications")) + return service_folder + + @pytest.fixture -def mock_environment(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict: +def mock_environment( + monkeypatch: pytest.MonkeyPatch, + docker_compose_service_environment_dict: EnvVarsDict, +) -> EnvVarsDict: return setenvs_from_dict( monkeypatch, { + **docker_compose_service_environment_dict, "LOGLEVEL": "DEBUG", "SC_BOOT_MODE": BootModeEnum.DEBUG, }, diff --git a/services/notifications/tests/unit/conftest.py b/services/notifications/tests/unit/conftest.py index e1f57c7c5c7..5f785451f12 100644 --- a/services/notifications/tests/unit/conftest.py +++ b/services/notifications/tests/unit/conftest.py @@ -14,11 +14,11 @@ @pytest.fixture -def service_env( +def app_environment( monkeypatch: pytest.MonkeyPatch, mock_environment: EnvVarsDict, rabbit_service: RabbitSettings, - postgres_db: sa.engine.Engine, + postgres_db: sa.engine.Engine, # waiting for postgres service to start postgres_env_vars_dict: EnvVarsDict, ) -> EnvVarsDict: return setenvs_from_dict( @@ -36,7 +36,7 @@ def service_env( @pytest.fixture -async def initialized_app(service_env: EnvVarsDict) -> AsyncIterator[FastAPI]: +async def initialized_app(app_environment: EnvVarsDict) -> AsyncIterator[FastAPI]: app: FastAPI = create_app() async with LifespanManager(app, startup_timeout=30, shutdown_timeout=30): diff --git a/services/notifications/tests/unit/test_cli.py b/services/notifications/tests/unit/test_cli.py index bcfc7925b61..6caedb8dded 100644 --- a/services/notifications/tests/unit/test_cli.py +++ b/services/notifications/tests/unit/test_cli.py @@ -21,7 +21,7 @@ @pytest.fixture -def cli_runner(service_env: EnvVarsDict) -> CliRunner: +def cli_runner(app_environment: EnvVarsDict) -> CliRunner: return CliRunner() diff --git a/services/notifications/tests/unit/test_core_settings.py b/services/notifications/tests/unit/test_core_settings.py new file mode 100644 index 00000000000..92ac7f3dc9d --- /dev/null +++ b/services/notifications/tests/unit/test_core_settings.py @@ -0,0 +1,18 @@ +# pylint: disable=unused-variable +# pylint: disable=unused-argument +# pylint: disable=redefined-outer-name + + +from pytest_simcore.helpers.monkeypatch_envs import ( + EnvVarsDict, +) +from simcore_service_notifications.core.settings import ApplicationSettings + + +def test_valid_application_settings(mock_environment: EnvVarsDict): + assert mock_environment + + settings = ApplicationSettings() # type: ignore + assert settings + + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/payments/tests/unit/test_core_settings.py b/services/payments/tests/unit/test_core_settings.py index a1d84644d62..343a4507871 100644 --- a/services/payments/tests/unit/test_core_settings.py +++ b/services/payments/tests/unit/test_core_settings.py @@ -3,19 +3,11 @@ # pylint: disable=unused-variable # pylint: disable=too-many-arguments - from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_service_payments.core.settings import ApplicationSettings -def test_valid_web_application_settings(app_environment: EnvVarsDict): - """ - We validate actual envfiles (e.g. repo.config files) by passing them via the CLI - - $ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets - $ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py - - """ +def test_valid_application_settings(app_environment: EnvVarsDict): settings = ApplicationSettings() # type: ignore assert settings diff --git a/services/resource-usage-tracker/tests/unit/test_core_settings.py b/services/resource-usage-tracker/tests/unit/test_core_settings.py index d338859a550..f99239cc06b 100644 --- a/services/resource-usage-tracker/tests/unit/test_core_settings.py +++ b/services/resource-usage-tracker/tests/unit/test_core_settings.py @@ -2,7 +2,13 @@ # pylint: disable=unused-argument # pylint: disable=unused-variable # pylint: disable=too-many-arguments +""" +We can validate actual .env files (also refered as `repo.config` files) by passing them via the CLI +$ ln -s /path/to/osparc-config/deployments/mydeploy.com/repo.config .secrets +$ pytest --external-envfile=.secrets --pdb tests/unit/test_core_settings.py + +""" from pytest_simcore.helpers.typing_env import EnvVarsDict from simcore_service_resource_usage_tracker.core.settings import ( diff --git a/services/storage/tests/unit/test_core_settings.py b/services/storage/tests/unit/test_core_settings.py new file mode 100644 index 00000000000..56b9da04cf4 --- /dev/null +++ b/services/storage/tests/unit/test_core_settings.py @@ -0,0 +1,18 @@ +# pylint: disable=unused-variable +# pylint: disable=unused-argument +# pylint: disable=redefined-outer-name + + +from pytest_simcore.helpers.monkeypatch_envs import ( + EnvVarsDict, +) +from simcore_service_storage.core.settings import ApplicationSettings + + +def test_valid_application_settings(app_environment: EnvVarsDict): + assert app_environment + + settings = ApplicationSettings() # type: ignore + assert settings + + assert settings == ApplicationSettings.create_from_envs() diff --git a/services/web/server/tests/unit/isolated/test_application_settings.py b/services/web/server/tests/unit/isolated/test_application_settings.py index 02394063061..c8c12355922 100644 --- a/services/web/server/tests/unit/isolated/test_application_settings.py +++ b/services/web/server/tests/unit/isolated/test_application_settings.py @@ -193,3 +193,12 @@ def test_backwards_compatibility_with_bool_env_vars_turned_into_objects( settings = ApplicationSettings.create_from_envs() assert settings.WEBSERVER_LICENSES is None + + +def test_valid_application_settings(mock_webserver_service_environment: EnvVarsDict): + assert mock_webserver_service_environment + + settings = ApplicationSettings() # type: ignore + assert settings + + assert settings == ApplicationSettings.create_from_envs()