|
7 | 7 | from faker import Faker |
8 | 8 | from pytest_mock import MockerFixture |
9 | 9 | 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 | +) |
11 | 14 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
12 | 15 |
|
13 | 16 |
|
@@ -89,6 +92,144 @@ def mock_env_deployer_pipeline(monkeypatch: pytest.MonkeyPatch) -> EnvVarsDict: |
89 | 92 | ) |
90 | 93 |
|
91 | 94 |
|
| 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 | + |
92 | 233 | @pytest.fixture |
93 | 234 | def mocked_login_required(mocker: MockerFixture): |
94 | 235 |
|
|
0 commit comments