Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PiaSchroeder committed Jan 7, 2024
1 parent ae58504 commit 8d67630
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/pystatis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion src/pystatis/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
18 changes: 13 additions & 5 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/test_helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8d67630

Please sign in to comment.