Skip to content

Commit

Permalink
Merge pull request #656 from opensafely-core/evansd/fix-db-config
Browse files Browse the repository at this point in the history
Fix missing f-string
  • Loading branch information
evansd authored Sep 13, 2023
2 parents 89b2f61 + 622ea81 commit 5766795
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
24 changes: 15 additions & 9 deletions jobrunner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
15 changes: 14 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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",
}

0 comments on commit 5766795

Please sign in to comment.