feat: fpw plugins, validation/crawl perf, WS stats, test DB isolation
- Add Free_Proxy_Website-style fpw_* plugins and register them - Per-plugin crawl timeout (crawl_timeout_seconds=120); remove global crawl_timeout setting - Validator: fix connect vs total timeout on save; SOCKS session LRU cache; drop redundant semaphore - Validation handler uses single DB connection; batch upsert after crawl; WorkerPool put_nowait - Remove unused max_retries from settings API/UI; settings maintenance SQL + init_db cleanup of deprecated keys - WebSocket dashboard stats; ProxyList pool_filter and API alignment - POST /api/proxies/delete-one for IPv6-safe deletes; task poll stops on 404 - pytest uses PROXYPOOL_DB_PATH=db/proxies.test.sqlite so tests do not wipe production DB - .gitignore: explicit proxies.test.sqlite patterns; fix plugin_service ValidationException import Made-with: Cursor
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
"""调度器 API 集成测试 - 测试 /api/scheduler/* 所有接口"""
|
||||
import pytest
|
||||
|
||||
from app.api.deps import get_settings_repo
|
||||
from app.repositories.settings_repo import SettingsRepository
|
||||
|
||||
|
||||
class FailingSettingsRepository(SettingsRepository):
|
||||
"""save 恒为 False,用于覆盖「设置保存失败」分支,非 MagicMock。"""
|
||||
|
||||
@staticmethod
|
||||
async def save(db, settings):
|
||||
return False
|
||||
|
||||
|
||||
class TestSchedulerAPI:
|
||||
"""测试调度器相关 API"""
|
||||
@@ -93,18 +104,17 @@ class TestSchedulerAPI:
|
||||
assert job is not None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_scheduler_db_save_failure(self, client, monkeypatch):
|
||||
async def test_start_scheduler_db_save_failure(self, client, app):
|
||||
"""测试启动调度器时数据库保存失败应返回 running=False"""
|
||||
from app.repositories.settings_repo import SettingsRepository
|
||||
|
||||
# lifespan 启动时调度器可能已自动启动,先停止它
|
||||
await client.post("/api/scheduler/stop")
|
||||
|
||||
async def mock_save(*args, **kwargs):
|
||||
return False
|
||||
app.dependency_overrides[get_settings_repo] = lambda: FailingSettingsRepository()
|
||||
try:
|
||||
response = await client.post("/api/scheduler/start")
|
||||
finally:
|
||||
app.dependency_overrides.pop(get_settings_repo, None)
|
||||
|
||||
monkeypatch.setattr(SettingsRepository, "save", mock_save)
|
||||
response = await client.post("/api/scheduler/start")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["code"] == 200
|
||||
|
||||
Reference in New Issue
Block a user