From 8d676308af3cce1cbbec3433bec51b0581e8ea9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pia=20Schr=C3=B6der?= Date: Sun, 7 Jan 2024 12:50:43 +0100 Subject: [PATCH] fixed tests --- src/pystatis/config.py | 6 +++--- src/pystatis/db.py | 2 +- tests/test_db.py | 18 +++++++++++++----- tests/test_helloworld.py | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/pystatis/config.py b/src/pystatis/config.py index dca3964..582e299 100644 --- a/src/pystatis/config.py +++ b/src/pystatis/config.py @@ -28,9 +28,9 @@ DEFAULT_CONFIG_DIR = str(Path().home() / f".{PKG_NAME}") SUPPORTED_DB = ["genesis", "zensus", "regio"] REGEX_DB = { - "genesis": re.compile("^((\d{5}-\d{4})|([0-9A-Z]{10}))$"), - "zensus": re.compile("^\d{4}[A-Z]-\d{4}$"), - "regio": re.compile("^((\d{5}-.{1,2}($|-.*$))|(A.*$)|([0-9A-Z]{10}$))"), + "genesis": re.compile(r"^((\d{5}-\d{4})|([0-9A-Z]{10}))$"), + "zensus": re.compile(r"^\d{4}[A-Z]-\d{4}$"), + "regio": re.compile(r"^((\d{5}-.{1,2}($|-.*$))|(A.*$)|([0-9A-Z]{10}$))"), } logger = logging.getLogger(__name__) diff --git a/src/pystatis/db.py b/src/pystatis/db.py index 2de72a1..74d6f23 100644 --- a/src/pystatis/db.py +++ b/src/pystatis/db.py @@ -14,7 +14,7 @@ def identify_db(name: str) -> str: name (str): Query parameter 'name' corresponding to the item code. Returns: - db_name (str): Name of matching database. + db_match (list[str]): List of matching databases. """ regex_db = config.get_db_identifiers() diff --git a/tests/test_db.py b/tests/test_db.py index 228ae12..6840704 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -37,17 +37,25 @@ def test_set_db_pw(config_): ("21111-01-03-4-B", "regio"), ], ) -def test_match_db(config_, name, expected_db): - assert db.match_db(name) == expected_db +def test_identify_db(config_, name, expected_db): + assert db.identify_db(name)[0] == expected_db -def test_match_db_with_multiple_matches(config_): +def test_identify_db_with_multiple_matches(config_): config_.set("genesis", "username", "test") config_.set("genesis", "password", "test") - assert db.match_db("1234567890") == "genesis" + db_match = db.identify_db("1234567890") + for db_name in db_match: + if db.check_db_credentials(db_name): + break + assert db_name == "genesis" config_.set("genesis", "username", "") config_.set("genesis", "password", "") config_.set("regio", "username", "test") config_.set("regio", "password", "test") - assert db.match_db("1234567890") == "regio" + db_match = db.identify_db("1234567890") + for db_name in db_match: + if db.check_db_credentials(db_name): + break + assert db_name == "regio" diff --git a/tests/test_helloworld.py b/tests/test_helloworld.py index b3caaf6..fd2c5a3 100644 --- a/tests/test_helloworld.py +++ b/tests/test_helloworld.py @@ -9,7 +9,7 @@ def test_whoami(mocker): ) mocker.patch("pystatis.db.get_db_host", return_value="genesis") - response = whoami() + response = whoami("genesis") assert response == str(_generic_request_status().text)