from zbt.core.config import Settings
from zbt.infrastructure.mysql.sessions import DatabaseName, build_mysql_url


def test_mysql_urls_target_each_whitelisted_database_and_escape_credentials() -> None:
    settings = Settings(
        mysql_user="zbt_s2",
        mysql_password="p@ss/word",
        mysql_core_database="insurance_s2_test_core",
        mysql_agent_database="insurance_s2_test_agent",
        mysql_analytics_database="insurance_s2_test_analytics",
        redis_prefix="ins:s2:test:db-contract:",
    )

    assert build_mysql_url(settings, DatabaseName.CORE).render_as_string(hide_password=False) == (
        "mysql+pymysql://zbt_s2:p%40ss%2Fword@127.0.0.1:3306/insurance_s2_test_core?charset=utf8mb4"
    )
    assert build_mysql_url(settings, DatabaseName.AGENT).database == ("insurance_s2_test_agent")
    assert build_mysql_url(settings, DatabaseName.ANALYTICS).database == (
        "insurance_s2_test_analytics"
    )
