feat: AI 余额监控服务(平台/账号 CRUD、并发轮询、Telegram 阈值提醒)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_db(tmp_path, monkeypatch):
|
||||
"""把数据库指向临时目录,避免污染真实 data/monitor.db。"""
|
||||
from app import db
|
||||
|
||||
monkeypatch.setattr(db, "DB_PATH", tmp_path / "test.db")
|
||||
monkeypatch.setattr(db, "DATA_DIR", tmp_path)
|
||||
db.init_db()
|
||||
return db
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_platform(test_db):
|
||||
"""插入一个示例平台,返回 dict。"""
|
||||
from app import db
|
||||
|
||||
with db.get_conn() as conn:
|
||||
cur = conn.execute(
|
||||
"""INSERT INTO platforms (name, currency, icon, method, url, headers, body,
|
||||
balance_path, interval_seconds, retry_count, timeout_seconds, enabled, note)
|
||||
VALUES ('OpenAI', 'USD', 'OpenAI', 'GET', 'https://x.test/api?key={{apiKey}}',
|
||||
'{"Authorization": "Bearer {{apiKey}}"}', '', 'data.balance', 60, 2, 10, 1, '')"""
|
||||
)
|
||||
pid = cur.lastrowid
|
||||
return dict((test_db.get_conn().execute("SELECT * FROM platforms WHERE id=?", (pid,)).fetchone()))
|
||||
Reference in New Issue
Block a user