feat: add POST /api/accounts/test endpoint
This commit is contained in:
parent
f64be8bbe0
commit
965362f5e3
2 changed files with 36 additions and 0 deletions
11
app/api.py
11
app/api.py
|
|
@ -273,6 +273,17 @@ def download_stats():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AccountTestRequest(BaseModel):
|
||||||
|
account: dict
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/accounts/test")
|
||||||
|
def test_account(req: AccountTestRequest):
|
||||||
|
from app.imap_fetch import test_connection
|
||||||
|
ok, message, count = test_connection(req.account)
|
||||||
|
return {"ok": ok, "message": message, "count": count}
|
||||||
|
|
||||||
|
|
||||||
# Static SPA — MUST be last (catches all unmatched paths)
|
# Static SPA — MUST be last (catches all unmatched paths)
|
||||||
_DIST = _ROOT / "web" / "dist"
|
_DIST = _ROOT / "web" / "dist"
|
||||||
if _DIST.exists():
|
if _DIST.exists():
|
||||||
|
|
|
||||||
|
|
@ -251,3 +251,28 @@ def test_stats_download_returns_file(client, score_with_labels):
|
||||||
def test_stats_download_404_when_no_file(client, data_dir):
|
def test_stats_download_404_when_no_file(client, data_dir):
|
||||||
r = client.get("/api/stats/download")
|
r = client.get("/api/stats/download")
|
||||||
assert r.status_code == 404
|
assert r.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
# ── /api/accounts/test ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
def test_account_test_missing_fields(client):
|
||||||
|
r = client.post("/api/accounts/test", json={"account": {"host": "", "username": "", "password": ""}})
|
||||||
|
assert r.status_code == 200
|
||||||
|
data = r.json()
|
||||||
|
assert data["ok"] is False
|
||||||
|
assert "required" in data["message"].lower()
|
||||||
|
|
||||||
|
|
||||||
|
def test_account_test_success(client):
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
mock_conn = MagicMock()
|
||||||
|
mock_conn.select.return_value = ("OK", [b"99"])
|
||||||
|
with patch("app.imap_fetch.imaplib.IMAP4_SSL", return_value=mock_conn):
|
||||||
|
r = client.post("/api/accounts/test", json={"account": {
|
||||||
|
"host": "imap.example.com", "port": 993, "use_ssl": True,
|
||||||
|
"username": "u@example.com", "password": "pw", "folder": "INBOX",
|
||||||
|
}})
|
||||||
|
assert r.status_code == 200
|
||||||
|
data = r.json()
|
||||||
|
assert data["ok"] is True
|
||||||
|
assert data["count"] == 99
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue