From b80b5ed1ad6ba92c2b364128cccca903fe855ef9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 15 Dec 2021 19:25:30 +0100 Subject: [PATCH] Improve uri_logging test part of #6069 --- tests/test_misc.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index de3f368e9..21a00f3be 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -184,16 +184,18 @@ def test_render_template_fallback(mocker): assert 'if self.dp' in val -def test_parse_db_uri_for_logging() -> None: - postgresql_conn_uri = "postgresql+psycopg2://scott123:scott123@host/dbname" - mariadb_conn_uri = "mariadb+mariadbconnector://app_user:Password123!@127.0.0.1:3306/company" - mysql_conn_uri = "mysql+pymysql://user:pass@some_mariadb/dbname?charset=utf8mb4" - sqlite_conn_uri = "sqlite:////freqtrade/user_data/tradesv3.sqlite" - censored_pwd = "*****" +@pytest.mark.parametrize('conn_url,expected', [ + ("postgresql+psycopg2://scott123:scott123@host:1245/dbname", + "postgresql+psycopg2://scott123:*****@host:1245/dbname"), + ("postgresql+psycopg2://scott123:scott123@host.name.com/dbname", + "postgresql+psycopg2://scott123:*****@host.name.com/dbname"), + ("mariadb+mariadbconnector://app_user:Password123!@127.0.0.1:3306/company", + "mariadb+mariadbconnector://app_user:*****@127.0.0.1:3306/company"), + ("mysql+pymysql://user:pass@some_mariadb/dbname?charset=utf8mb4", + "mysql+pymysql://user:*****@some_mariadb/dbname?charset=utf8mb4"), + ("sqlite:////freqtrade/user_data/tradesv3.sqlite", + "sqlite:////freqtrade/user_data/tradesv3.sqlite"), +]) +def test_parse_db_uri_for_logging(conn_url, expected) -> None: - def get_pwd(x): return x.split(':')[2].split('@')[0] - - assert get_pwd(parse_db_uri_for_logging(postgresql_conn_uri)) == censored_pwd - assert get_pwd(parse_db_uri_for_logging(mariadb_conn_uri)) == censored_pwd - assert get_pwd(parse_db_uri_for_logging(mysql_conn_uri)) == censored_pwd - assert sqlite_conn_uri == parse_db_uri_for_logging(sqlite_conn_uri) + assert parse_db_uri_for_logging(conn_url) == expected