Skip to content

Commit 890ca3f

Browse files
add new config parameter for ohsomedb connection
1 parent 72107f5 commit 890ca3f

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

config/sample.config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
# Database connection parameters;
3+
ohsomedb_host: localhost
4+
ohsomedb_port: 5432
5+
ohsomedb_db: postgres
6+
ohsomedb_user: postgres
7+
ohsomedb_password: mylocalpassword
38
postgres_host: localhost
49
postgres_port: 5445
510
postgres_db: oqapi

docs/configuration.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ Below is a table listing all possible configuration variables.
88

99
| Configuration Variable Name | Environment Variable Name | Configuration File Name | Default Value | Description |
1010
| --------------------------- | ------------------------------- | ------------------------- | ------------------------------ | --------------------------------------------------------------------------- |
11-
| Postgres Host | `POSTGRES_HOST` | `postgres_host` | `localhost` | Database connection parameter |
11+
| ohsomeDB Host | `OHSOMEDB_HOST` | `ohsomedb_host` | `localhost` | ohsomeDB database connection parameter |
12+
| ohsomeDB Port | `OHSOMEDB_PORT` | `ohsomedb_port` | `5432` | " |
13+
| ohsomeDB Database | `OHSOMEDB_DB` | `ohsomedb_db` | `postgres` | " |
14+
| ohsomeDB User | `OHSOMEDB_USER` | `ohsomedb_user` | `postgres` | " |
15+
| ohsomeDB Password | `OHSOMEDB_PASSWORD` | `ohsomedb_password` | `mylocalpassword` | " |
16+
| Postgres Host | `POSTGRES_HOST` | `postgres_host` | `localhost` | Postgres database connection parameter |
1217
| Postgres Port | `POSTGRES_PORT` | `postgres_port` | `5445` | " |
1318
| Postgres Database | `POSTGRES_DB` | `postgres_db` | `oqapi` | " |
1419
| Postgres User | `POSTGRES_USER` | `postgres_user` | `oqapi` | " |

ohsome_quality_api/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def get_config_path() -> str:
2424

2525
def load_config_default() -> dict:
2626
return {
27+
"ohsomdb_host": "localhost",
28+
"ohsomdb_port": 5432,
29+
"ohsomdb_db": "postgres",
30+
"ohsomdb_user": "postgres",
31+
"ohsomdb_password": "mylocalpassword",
2732
"postgres_host": "localhost",
2833
"postgres_port": 5445,
2934
"postgres_db": "oqapi",
@@ -56,6 +61,11 @@ def load_config_from_file(path: str) -> dict:
5661
def load_config_from_env() -> dict:
5762
"""Load configuration from environment variables."""
5863
cfg = {
64+
"ohsomedb_host": os.getenv("OHSOMEDB_HOST"),
65+
"ohsomedb_port": os.getenv("OHSOMEDB_PORT"),
66+
"ohsomedb_db": os.getenv("OHSOMEDB_DB"),
67+
"ohsomedb_user": os.getenv("OHSOMEDB_USER"),
68+
"ohsomedb_password": os.getenv("OHSOMEDB_PASSWORD"),
5969
"postgres_host": os.getenv("POSTGRES_HOST"),
6070
"postgres_port": os.getenv("POSTGRES_PORT"),
6171
"postgres_db": os.getenv("POSTGRES_DB"),

tests/unittests/fixtures/config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
# Database connection parameters;
3+
ohsomedb_host: localhost
4+
ohsomedb_port: 5432
5+
ohsomedb_db: postgres
6+
ohsomedb_user: postgres
7+
ohsomedb_password: mylocalpassword
38
postgres_host: localhost
49
postgres_port: 5445
510
postgres_db: oqapi

tests/unittests/test_config.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
class TestConfig(unittest.TestCase):
1010
def setUp(self):
1111
self.keys = {
12+
"ohsomedb_host",
13+
"ohsomedb_port",
14+
"ohsomedb_db",
15+
"ohsomedb_user",
16+
"ohsomedb_password",
1217
"postgres_host",
1318
"postgres_port",
1419
"postgres_db",
@@ -46,7 +51,7 @@ def test_get_config_path_set_env(self):
4651
def test_config_default(self):
4752
cfg = config.load_config_default()
4853
self.assertIsInstance(cfg, dict)
49-
self.assertEqual(self.keys, cfg.keys())
54+
self.assertEqual(list(self.keys).sort(), list(cfg.keys()).sort())
5055

5156
@mock.patch.dict(
5257
"os.environ",
@@ -89,7 +94,7 @@ def test_load_config_from_env_set(self):
8994
def test_get_config(self):
9095
cfg = config.get_config()
9196
self.assertIsInstance(cfg, MappingProxyType)
92-
self.assertEqual(self.keys, cfg.keys())
97+
self.assertEqual(list(self.keys).sort(), list(cfg.keys()).sort())
9398

9499
@mock.patch.dict("os.environ", {}, clear=True)
95100
def test_get_config_value(self):
@@ -105,7 +110,7 @@ def test_get_config_value(self):
105110
def test_get_config_env_empty_str(self):
106111
cfg = config.get_config()
107112
self.assertIsInstance(cfg, MappingProxyType)
108-
self.assertEqual(self.keys, cfg.keys())
113+
self.assertEqual(list(self.keys).sort(), list(cfg.keys()).sort())
109114

110115
@mock.patch.dict("os.environ", {}, clear=True)
111116
def test_get_data_dir_unset_env(self):

0 commit comments

Comments
 (0)