fix: 修复主程序卡死与下载器集成,新增真实数据测试
- LookingWebMain: 强制 IPv4 避免 IPv6 不可达挂起;requests 加超时防卡死 - get_seed_from_element_detail: 修复限流页崩溃与 favicon 误作来源 URL,改用 canonical/传入 URL - QbittorrentDownloader: 修复 main() 中模块/类误用导致的 download_by_seed AttributeError;请求加超时 - MySqlService: 修复数据库不可达时 query/execute/close 的 None 崩溃,close 后置空 connection - 新增 cf_session: Cloudflare 人机认证 cookie 管理 + 限流退避重试 + 自动弹浏览器刷新验证 - 新增 refresh_cf_cookies.py: 弹出浏览器手动验证并保存 cf_clearance - tests/: 真实网络/数据库测试(get_page、seed_is_exist、cf_session)+ run_tests.py runner - 清理无用脚本(final_test2/verify_replace/REPLACEMENT_INFO),.idea 与 cookie 文件入 .gitignore 注: test_qbittorrent_downloader.py 11 个用例为既有失败(mock 目标 session 为实例属性,与实现错配),未在本次范围
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
测试 MySQLDatabase 类
|
||||
"""
|
||||
import pytest
|
||||
import pymysql
|
||||
from loguru import logger
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from dataService.MySqlService import MySQLDatabase, DatabaseConfig
|
||||
|
||||
|
||||
class TestMySQLDatabase:
|
||||
"""MySQLDatabase 类测试"""
|
||||
|
||||
def setup_method(self):
|
||||
"""每个测试方法前的设置"""
|
||||
logger.remove()
|
||||
logger.add(sys.stderr, level="DEBUG")
|
||||
|
||||
def test_database_config(self):
|
||||
"""测试数据库配置"""
|
||||
assert DatabaseConfig.HOST == "192.168.123.199"
|
||||
assert DatabaseConfig.PORT == 3306
|
||||
assert DatabaseConfig.USER == "root"
|
||||
assert DatabaseConfig.PASSWORD == "GUOxy5157"
|
||||
assert DatabaseConfig.DB == "LookingWeb"
|
||||
logger.info("数据库配置正确")
|
||||
|
||||
def test_create_connection_exists(self):
|
||||
"""测试创建连接对象"""
|
||||
connection = MySQLDatabase.create_connection()
|
||||
assert connection is not None
|
||||
logger.info("数据库连接对象创建成功")
|
||||
connection.close()
|
||||
|
||||
def test_connection_has_attributes(self):
|
||||
"""测试连接对象有必需的属性"""
|
||||
connection = MySQLDatabase.create_connection()
|
||||
assert hasattr(connection, 'host')
|
||||
assert hasattr(connection, 'port')
|
||||
assert hasattr(connection, 'user')
|
||||
assert hasattr(connection, 'password')
|
||||
assert hasattr(connection, 'db')
|
||||
assert hasattr(connection, 'connection')
|
||||
assert hasattr(connection, 'connect')
|
||||
assert hasattr(connection, 'query')
|
||||
assert hasattr(connection, 'execute')
|
||||
assert hasattr(connection, 'close')
|
||||
logger.info("连接对象具有所有必需的属性和方法")
|
||||
connection.close()
|
||||
|
||||
def test_connection_close(self):
|
||||
"""测试关闭连接"""
|
||||
connection = MySQLDatabase.create_connection()
|
||||
connection.close()
|
||||
assert connection.connection is None
|
||||
logger.info("关闭连接成功")
|
||||
|
||||
|
||||
def run_tests():
|
||||
"""运行所有测试"""
|
||||
pytest.main([
|
||||
__file__,
|
||||
"-v",
|
||||
"--tb=short",
|
||||
"--log-cli-level=INFO"
|
||||
])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
Reference in New Issue
Block a user