diff --git a/jobrunner/config.py b/jobrunner/config.py index f61b1bee..c3283ead 100644 --- a/jobrunner/config.py +++ b/jobrunner/config.py @@ -86,15 +86,21 @@ def _is_valid_backend_name(name): DOCKER_REGISTRY = os.environ.get("DOCKER_REGISTRY", "ghcr.io/opensafely-core") -db_names = ["full", "default", "include_t1oo"] -DATABASE_URLS = { - db_name: db_url - for db_name, db_url in [ - (db_name, os.environ.get("{db_name.upper()}_DATABASE_URL")) - for db_name in db_names - ] - if db_url -} + +def database_urls_from_env(env): + db_names = ["full", "default", "include_t1oo"] + return { + db_name: db_url + for db_name, db_url in [ + (db_name, env.get(f"{db_name.upper()}_DATABASE_URL")) + for db_name in db_names + ] + if db_url + } + + +DATABASE_URLS = database_urls_from_env(os.environ) + TEMP_DATABASE_NAME = os.environ.get("TEMP_DATABASE_NAME") diff --git a/tests/test_config.py b/tests/test_config.py index ca0ab3df..a25a464b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -5,7 +5,7 @@ import pytest -from jobrunner.config import _is_valid_backend_name +from jobrunner.config import _is_valid_backend_name, database_urls_from_env script = """ @@ -113,3 +113,16 @@ def test_config_presto_paths_not_exist(tmp_path): ) def test_is_valid_backend_name(name, is_valid): assert _is_valid_backend_name(name) == is_valid + + +def test_database_urls_from_env(): + db_urls = database_urls_from_env( + { + "DEFAULT_DATABASE_URL": "mssql://localhost/db1", + "INCLUDE_T1OO_DATABASE_URL": "mssql://localhost/db2", + } + ) + assert db_urls == { + "default": "mssql://localhost/db1", + "include_t1oo": "mssql://localhost/db2", + }