You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
942 B
24 lines
942 B
|
2 weeks ago
|
"""
|
||
|
|
数据缓冲平台 - MySQL 数据库连接测试
|
||
|
|
"""
|
||
|
|
from unittest.mock import MagicMock, patch
|
||
|
|
|
||
|
|
from app.mysql_database import init_mysql
|
||
|
|
|
||
|
|
|
||
|
|
def test_init_mysql_url_encodes_password():
|
||
|
|
"""MySQL 密码应使用 urllib.parse.quote_plus 进行 URL 编码。"""
|
||
|
|
with patch("app.mysql_database.create_engine") as mock_create_engine:
|
||
|
|
mock_engine = MagicMock()
|
||
|
|
mock_create_engine.return_value = mock_engine
|
||
|
|
with patch("app.mysql_database.MYSQL_PASSWORD", "p@ss/w+ord"):
|
||
|
|
with patch("app.mysql_database.MYSQL_USER", "user"):
|
||
|
|
with patch("app.mysql_database.MYSQL_HOST", "host"):
|
||
|
|
with patch("app.mysql_database.MYSQL_PORT", "3306"):
|
||
|
|
with patch("app.mysql_database.MYSQL_DATABASE", "buffer"):
|
||
|
|
init_mysql()
|
||
|
|
|
||
|
|
url = mock_create_engine.call_args[0][0]
|
||
|
|
assert "p%40ss%2Fw%2Bord" in url
|
||
|
|
assert "p@ss" not in url
|