Skip to content

Commit c3371b5

Browse files
committed
moves environs
1 parent cf3eaa0 commit c3371b5

File tree

2 files changed

+142
-144
lines changed

2 files changed

+142
-144
lines changed

services/web/server/tests/unit/isolated/conftest.py

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from faker import Faker
88
from pytest_mock import MockerFixture
99
from pytest_simcore.helpers.dict_tools import ConfigDict
10-
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
10+
from pytest_simcore.helpers.monkeypatch_envs import (
11+
setenvs_from_dict,
12+
setenvs_from_envfile,
13+
)
1114
from pytest_simcore.helpers.typing_env import EnvVarsDict
1215

1316

@@ -89,6 +92,144 @@ def mock_env_deployer_pipeline(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict:
8992
)
9093

9194

95+
@pytest.fixture
96+
def mock_env_devel_environment(
97+
mock_env_devel_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
98+
) -> EnvVarsDict:
99+
# Overrides to ensure dev-features are enabled testings
100+
return mock_env_devel_environment | setenvs_from_dict(
101+
monkeypatch,
102+
envs={
103+
"WEBSERVER_DEV_FEATURES_ENABLED": "1",
104+
},
105+
)
106+
107+
108+
@pytest.fixture
109+
def mock_env_makefile(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict:
110+
"""envvars produced @Makefile (export)"""
111+
# TODO: add Makefile recipe 'make dump-envs' to produce the file we load here
112+
return setenvs_from_dict(
113+
monkeypatch,
114+
{
115+
"API_SERVER_API_VERSION": "0.3.0",
116+
"BUILD_DATE": "2022-01-14T21:28:15Z",
117+
"CATALOG_API_VERSION": "0.3.2",
118+
"CLIENT_WEB_OUTPUT": "/home/crespo/devp/osparc-simcore/services/static-webserver/client/source-output",
119+
"DATCORE_ADAPTER_API_VERSION": "0.1.0-alpha",
120+
"DIRECTOR_API_VERSION": "0.1.0",
121+
"DIRECTOR_V2_API_VERSION": "2.0.0",
122+
"DOCKER_IMAGE_TAG": "production",
123+
"DOCKER_REGISTRY": "local",
124+
"S3_ENDPOINT": "http://127.0.0.1:9001",
125+
"STORAGE_API_VERSION": "0.2.1",
126+
"SWARM_HOSTS": "",
127+
"SWARM_STACK_NAME": "master-simcore",
128+
"SWARM_STACK_NAME_NO_HYPHEN": "master_simcore",
129+
"VCS_REF_CLIENT": "99b8022d2",
130+
"VCS_STATUS_CLIENT": "'modified/untracked'",
131+
"VCS_URL": "[email protected]:pcrespov/osparc-simcore.git",
132+
"WEBSERVER_API_VERSION": "0.7.0",
133+
},
134+
)
135+
136+
137+
@pytest.fixture
138+
def mock_env_dockerfile_build(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict:
139+
#
140+
# docker run -it --hostname "{{.Node.Hostname}}-{{.Service.Name}}-{{.Task.Slot}}" local/webserver:production printenv
141+
#
142+
return setenvs_from_envfile(
143+
monkeypatch,
144+
"""\
145+
GPG_KEY=123456789123456789
146+
HOME=/home/scu
147+
HOSTNAME=osparc-master-55-master-simcore_master_webserver-1
148+
IS_CONTAINER_CONTEXT=Yes
149+
LANG=C.UTF-8
150+
PATH=/home/scu/.venv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
151+
PWD=/home/scu
152+
PYTHON_GET_PIP_SHA256=6123659241292b2147b58922b9ffe11dda66b39d52d8a6f3aa310bc1d60ea6f7
153+
PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/a1675ab6c2bd898ed82b1f58c486097f763c74a9/public/get-pip.py
154+
PYTHON_PIP_VERSION=21.1.3
155+
PYTHON_VERSION=3.11.9
156+
PYTHONDONTWRITEBYTECODE=1
157+
PYTHONOPTIMIZE=TRUE
158+
SC_BOOT_MODE=production
159+
SC_BUILD_DATE=2022-01-09T12:26:29Z
160+
SC_BUILD_TARGET=production
161+
SC_HEALTHCHECK_INTERVAL=30
162+
SC_HEALTHCHECK_RETRY=3
163+
SC_USER_ID=8004
164+
SC_USER_NAME=scu
165+
SC_VCS_REF=dd536f998
166+
[email protected]:ITISFoundation/osparc-simcore.git
167+
TERM=xterm
168+
VIRTUAL_ENV=/home/scu/.venv
169+
""",
170+
)
171+
172+
173+
@pytest.fixture
174+
def mock_webserver_service_environment(
175+
monkeypatch: pytest.MonkeyPatch,
176+
mock_env_makefile: EnvVarsDict,
177+
mock_env_devel_environment: EnvVarsDict,
178+
mock_env_dockerfile_build: EnvVarsDict,
179+
mock_env_deployer_pipeline: EnvVarsDict,
180+
) -> EnvVarsDict:
181+
"""
182+
Mocks environment produce in the docker compose config with a .env (.env-devel)
183+
and launched with a makefile
184+
"""
185+
# @docker compose config (overrides)
186+
# TODO: get from docker compose config
187+
# r'- ([A-Z2_]+)=\$\{\1:-([\w-]+)\}'
188+
189+
# - .env-devel + docker-compose service environs
190+
# hostname: "{{.Node.Hostname}}-{{.Service.Name}}-{{.Task.Slot}}"
191+
192+
# environment:
193+
# - CATALOG_HOST=${CATALOG_HOST:-catalog}
194+
# - CATALOG_PORT=${CATALOG_PORT:-8000}
195+
# - DIAGNOSTICS_MAX_AVG_LATENCY=10
196+
# - DIAGNOSTICS_MAX_TASK_DELAY=30
197+
# - DIRECTOR_PORT=${DIRECTOR_PORT:-8080}
198+
# - DIRECTOR_V2_HOST=${DIRECTOR_V2_HOST:-director-v2}
199+
# - DIRECTOR_V2_PORT=${DIRECTOR_V2_PORT:-8000}
200+
# - STORAGE_HOST=${STORAGE_HOST:-storage}
201+
# - STORAGE_PORT=${STORAGE_PORT:-8080}
202+
# - SWARM_STACK_NAME=${SWARM_STACK_NAME:-simcore}
203+
# - WEBSERVER_LOGLEVEL=${LOG_LEVEL:-WARNING}
204+
# env_file:
205+
# - ../.env
206+
mock_envs_docker_compose_environment = setenvs_from_dict(
207+
monkeypatch,
208+
{
209+
# Emulates MYVAR=${MYVAR:-default}
210+
"CATALOG_HOST": os.environ.get("CATALOG_HOST", "catalog"),
211+
"CATALOG_PORT": os.environ.get("CATALOG_PORT", "8000"),
212+
"DIAGNOSTICS_MAX_AVG_LATENCY": "30",
213+
"DIRECTOR_PORT": os.environ.get("DIRECTOR_PORT", "8080"),
214+
"DIRECTOR_V2_HOST": os.environ.get("DIRECTOR_V2_HOST", "director-v2"),
215+
"DIRECTOR_V2_PORT": os.environ.get("DIRECTOR_V2_PORT", "8000"),
216+
"STORAGE_HOST": os.environ.get("STORAGE_HOST", "storage"),
217+
"STORAGE_PORT": os.environ.get("STORAGE_PORT", "8080"),
218+
"SWARM_STACK_NAME": os.environ.get("SWARM_STACK_NAME", "simcore"),
219+
"WEBSERVER_LOGLEVEL": os.environ.get("LOG_LEVEL", "WARNING"),
220+
"SESSION_COOKIE_MAX_AGE": str(7 * 24 * 60 * 60),
221+
},
222+
)
223+
224+
return (
225+
mock_env_makefile
226+
| mock_env_devel_environment
227+
| mock_env_dockerfile_build
228+
| mock_env_deployer_pipeline
229+
| mock_envs_docker_compose_environment
230+
)
231+
232+
92233
@pytest.fixture
93234
def mocked_login_required(mocker: MockerFixture):
94235

services/web/server/tests/unit/isolated/test_application_settings.py

Lines changed: 0 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
# pylint:disable=no-name-in-module
44

55
import json
6-
import os
76

87
import pytest
98
from aiohttp import web
109
from models_library.utils.json_serialization import json_dumps
1110
from pydantic import HttpUrl, parse_obj_as
12-
from pytest_simcore.helpers.monkeypatch_envs import (
13-
setenvs_from_dict,
14-
setenvs_from_envfile,
15-
)
1611
from pytest_simcore.helpers.typing_env import EnvVarsDict
1712
from simcore_service_webserver.application_settings import (
1813
APP_SETTINGS_KEY,
@@ -21,144 +16,6 @@
2116
)
2217

2318

24-
@pytest.fixture
25-
def mock_env_devel_environment(
26-
mock_env_devel_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatch
27-
) -> EnvVarsDict:
28-
# Overrides to ensure dev-features are enabled testings
29-
return mock_env_devel_environment | setenvs_from_dict(
30-
monkeypatch,
31-
envs={
32-
"WEBSERVER_DEV_FEATURES_ENABLED": "1",
33-
},
34-
)
35-
36-
37-
@pytest.fixture
38-
def mock_env_makefile(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict:
39-
"""envvars produced @Makefile (export)"""
40-
# TODO: add Makefile recipe 'make dump-envs' to produce the file we load here
41-
return setenvs_from_dict(
42-
monkeypatch,
43-
{
44-
"API_SERVER_API_VERSION": "0.3.0",
45-
"BUILD_DATE": "2022-01-14T21:28:15Z",
46-
"CATALOG_API_VERSION": "0.3.2",
47-
"CLIENT_WEB_OUTPUT": "/home/crespo/devp/osparc-simcore/services/static-webserver/client/source-output",
48-
"DATCORE_ADAPTER_API_VERSION": "0.1.0-alpha",
49-
"DIRECTOR_API_VERSION": "0.1.0",
50-
"DIRECTOR_V2_API_VERSION": "2.0.0",
51-
"DOCKER_IMAGE_TAG": "production",
52-
"DOCKER_REGISTRY": "local",
53-
"S3_ENDPOINT": "http://127.0.0.1:9001",
54-
"STORAGE_API_VERSION": "0.2.1",
55-
"SWARM_HOSTS": "",
56-
"SWARM_STACK_NAME": "master-simcore",
57-
"SWARM_STACK_NAME_NO_HYPHEN": "master_simcore",
58-
"VCS_REF_CLIENT": "99b8022d2",
59-
"VCS_STATUS_CLIENT": "'modified/untracked'",
60-
"VCS_URL": "[email protected]:pcrespov/osparc-simcore.git",
61-
"WEBSERVER_API_VERSION": "0.7.0",
62-
},
63-
)
64-
65-
66-
@pytest.fixture
67-
def mock_env_dockerfile_build(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict:
68-
#
69-
# docker run -it --hostname "{{.Node.Hostname}}-{{.Service.Name}}-{{.Task.Slot}}" local/webserver:production printenv
70-
#
71-
return setenvs_from_envfile(
72-
monkeypatch,
73-
"""\
74-
GPG_KEY=123456789123456789
75-
HOME=/home/scu
76-
HOSTNAME=osparc-master-55-master-simcore_master_webserver-1
77-
IS_CONTAINER_CONTEXT=Yes
78-
LANG=C.UTF-8
79-
PATH=/home/scu/.venv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
80-
PWD=/home/scu
81-
PYTHON_GET_PIP_SHA256=6123659241292b2147b58922b9ffe11dda66b39d52d8a6f3aa310bc1d60ea6f7
82-
PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/a1675ab6c2bd898ed82b1f58c486097f763c74a9/public/get-pip.py
83-
PYTHON_PIP_VERSION=21.1.3
84-
PYTHON_VERSION=3.11.9
85-
PYTHONDONTWRITEBYTECODE=1
86-
PYTHONOPTIMIZE=TRUE
87-
SC_BOOT_MODE=production
88-
SC_BUILD_DATE=2022-01-09T12:26:29Z
89-
SC_BUILD_TARGET=production
90-
SC_HEALTHCHECK_INTERVAL=30
91-
SC_HEALTHCHECK_RETRY=3
92-
SC_USER_ID=8004
93-
SC_USER_NAME=scu
94-
SC_VCS_REF=dd536f998
95-
[email protected]:ITISFoundation/osparc-simcore.git
96-
TERM=xterm
97-
VIRTUAL_ENV=/home/scu/.venv
98-
""",
99-
)
100-
101-
102-
@pytest.fixture
103-
def mock_webserver_service_environment(
104-
monkeypatch: pytest.MonkeyPatch,
105-
mock_env_makefile: EnvVarsDict,
106-
mock_env_devel_environment: EnvVarsDict,
107-
mock_env_dockerfile_build: EnvVarsDict,
108-
mock_env_deployer_pipeline: EnvVarsDict,
109-
) -> EnvVarsDict:
110-
"""
111-
Mocks environment produce in the docker compose config with a .env (.env-devel)
112-
and launched with a makefile
113-
"""
114-
# @docker compose config (overrides)
115-
# TODO: get from docker compose config
116-
# r'- ([A-Z2_]+)=\$\{\1:-([\w-]+)\}'
117-
118-
# - .env-devel + docker-compose service environs
119-
# hostname: "{{.Node.Hostname}}-{{.Service.Name}}-{{.Task.Slot}}"
120-
121-
# environment:
122-
# - CATALOG_HOST=${CATALOG_HOST:-catalog}
123-
# - CATALOG_PORT=${CATALOG_PORT:-8000}
124-
# - DIAGNOSTICS_MAX_AVG_LATENCY=10
125-
# - DIAGNOSTICS_MAX_TASK_DELAY=30
126-
# - DIRECTOR_PORT=${DIRECTOR_PORT:-8080}
127-
# - DIRECTOR_V2_HOST=${DIRECTOR_V2_HOST:-director-v2}
128-
# - DIRECTOR_V2_PORT=${DIRECTOR_V2_PORT:-8000}
129-
# - STORAGE_HOST=${STORAGE_HOST:-storage}
130-
# - STORAGE_PORT=${STORAGE_PORT:-8080}
131-
# - SWARM_STACK_NAME=${SWARM_STACK_NAME:-simcore}
132-
# - WEBSERVER_LOGLEVEL=${LOG_LEVEL:-WARNING}
133-
# env_file:
134-
# - ../.env
135-
mock_envs_docker_compose_environment = setenvs_from_dict(
136-
monkeypatch,
137-
{
138-
# Emulates MYVAR=${MYVAR:-default}
139-
"CATALOG_HOST": os.environ.get("CATALOG_HOST", "catalog"),
140-
"CATALOG_PORT": os.environ.get("CATALOG_PORT", "8000"),
141-
"DIAGNOSTICS_MAX_AVG_LATENCY": "30",
142-
"DIRECTOR_PORT": os.environ.get("DIRECTOR_PORT", "8080"),
143-
"DIRECTOR_V2_HOST": os.environ.get("DIRECTOR_V2_HOST", "director-v2"),
144-
"DIRECTOR_V2_PORT": os.environ.get("DIRECTOR_V2_PORT", "8000"),
145-
"STORAGE_HOST": os.environ.get("STORAGE_HOST", "storage"),
146-
"STORAGE_PORT": os.environ.get("STORAGE_PORT", "8080"),
147-
"SWARM_STACK_NAME": os.environ.get("SWARM_STACK_NAME", "simcore"),
148-
"WEBSERVER_LOGLEVEL": os.environ.get("LOG_LEVEL", "WARNING"),
149-
"SESSION_COOKIE_MAX_AGE": str(7 * 24 * 60 * 60),
150-
},
151-
)
152-
153-
return (
154-
mock_env_makefile
155-
| mock_env_devel_environment
156-
| mock_env_dockerfile_build
157-
| mock_env_deployer_pipeline
158-
| mock_envs_docker_compose_environment
159-
)
160-
161-
16219
@pytest.fixture
16320
def app_settings(
16421
mock_webserver_service_environment: EnvVarsDict,

0 commit comments

Comments
 (0)