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,8 @@
|
||||
"""插件 API 集成测试 - 测试 /api/plugins/* 所有接口"""
|
||||
import pytest
|
||||
|
||||
from tests.task_utils import poll_task_until_terminal
|
||||
|
||||
|
||||
class TestPluginsAPI:
|
||||
"""测试插件相关 API"""
|
||||
@@ -116,10 +118,11 @@ class TestPluginsAPI:
|
||||
data = response.json()
|
||||
assert data["code"] == 200
|
||||
|
||||
@pytest.mark.network
|
||||
@pytest.mark.slow
|
||||
@pytest.mark.asyncio
|
||||
async def test_crawl_plugin(self, client):
|
||||
"""测试 POST /api/plugins/{id}/crawl - 异步任务模式"""
|
||||
import asyncio
|
||||
response = await client.get("/api/plugins")
|
||||
plugins = response.json()["data"]["plugins"]
|
||||
if not plugins:
|
||||
@@ -133,18 +136,11 @@ class TestPluginsAPI:
|
||||
assert "task_id" in data["data"]
|
||||
|
||||
task_id = data["data"]["task_id"]
|
||||
# 轮询任务状态
|
||||
task_data = None
|
||||
for _ in range(10):
|
||||
await asyncio.sleep(0.3)
|
||||
res = await client.get(f"/api/tasks/{task_id}")
|
||||
assert res.status_code == 200
|
||||
task_data = res.json()["data"]
|
||||
if task_data["status"] in ("completed", "failed", "cancelled"):
|
||||
break
|
||||
|
||||
task_data = await poll_task_until_terminal(
|
||||
client, task_id, max_rounds=140, interval=0.5
|
||||
)
|
||||
assert task_data is not None
|
||||
assert task_data["status"] in ("completed", "cancelled")
|
||||
assert task_data["status"] in ("completed", "failed", "cancelled")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_crawl_nonexistent_plugin(self, client):
|
||||
@@ -152,10 +148,11 @@ class TestPluginsAPI:
|
||||
response = await client.post("/api/plugins/nonexistent_plugin/crawl")
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.network
|
||||
@pytest.mark.slow
|
||||
@pytest.mark.asyncio
|
||||
async def test_crawl_all_plugins(self, client):
|
||||
"""测试 POST /api/plugins/crawl-all - 异步任务模式"""
|
||||
import asyncio
|
||||
response = await client.post("/api/plugins/crawl-all")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -163,15 +160,8 @@ class TestPluginsAPI:
|
||||
assert "task_id" in data["data"]
|
||||
|
||||
task_id = data["data"]["task_id"]
|
||||
# 轮询任务状态
|
||||
task_data = None
|
||||
for _ in range(10):
|
||||
await asyncio.sleep(0.3)
|
||||
res = await client.get(f"/api/tasks/{task_id}")
|
||||
assert res.status_code == 200
|
||||
task_data = res.json()["data"]
|
||||
if task_data["status"] in ("completed", "failed", "cancelled"):
|
||||
break
|
||||
|
||||
task_data = await poll_task_until_terminal(
|
||||
client, task_id, max_rounds=400, interval=0.5
|
||||
)
|
||||
assert task_data is not None
|
||||
assert task_data["status"] in ("completed", "cancelled")
|
||||
assert task_data["status"] in ("completed", "failed", "cancelled")
|
||||
|
||||
Reference in New Issue
Block a user