Skip to content

Commit

Permalink
Tests for reading db config and defaults
Browse files Browse the repository at this point in the history
Added
test_db_config
test_db2_config
test_db_passwd_config
#7
  • Loading branch information
VaeterchenFrost committed Jul 11, 2020
1 parent b81ba9b commit ea7e985
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
3 changes: 1 addition & 2 deletions test/database.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[postgresql]
host=localhost
port=5432
database=logicsem
port=123
user=postgres
password=XXX
application_name=dpdb-admin
Expand Down
6 changes: 6 additions & 0 deletions test/db_password.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[postgresql]

password=XXX

[extra]
data=something
39 changes: 34 additions & 5 deletions test/test_construct_dpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,45 @@
"""

from pathlib import Path
from tdvisu.construct_dpdb_visu import read_cfg, db_config
from tdvisu.construct_dpdb_visu import read_cfg, db_config, DEFAULT_DBCONFIG

DIR = Path(__file__).parent
SECTION = 'postgresql'


def test_db_config():
result = read_cfg(DIR / 'database.ini', 'postgresql', True)
"""Test reading the database configuration from the test file."""
result = read_cfg(DIR / 'database.ini', SECTION, True)
assert result == {'application_name': 'dpdb-admin',
'database': 'logicsem',
'host': 'localhost',
'password': 'XXX',
'port': '5432',
'user': 'postgres'}
'port': '123',
'user': 'postgres'
}, "should be able to read from ini file"

result = db_config(DIR / 'database.ini', SECTION)
assert result == {'application_name': 'dpdb-admin',
'database': DEFAULT_DBCONFIG['database'],
'host': 'localhost',
'password': 'XXX',
'port': '123',
'user': 'postgres'
}, "should complete 'database' with default."


def test_db2_config():
"""Test should use defaults when file not found."""
fixed_defaults = db_config(DIR / 'database2.ini', SECTION)
assert fixed_defaults == DEFAULT_DBCONFIG


def test_db_passwd_config():
"""Test should add password from file to defaults."""
insert_passwd = db_config(DIR / 'db_password.ini', SECTION)
assert insert_passwd == {'application_name': 'dpdb-admin',
'database': 'logicsem',
'host': 'localhost',
'password': 'XXX',
'port': 5432,
'user': 'postgres'
}

0 comments on commit ea7e985

Please sign in to comment.