Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing f-string #656

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
}