feat(insta-lab): GET /keywords/ranked + POST /slates/{id}/decision
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
42
insta-lab/tests/test_ranked_decision_api.py
Normal file
42
insta-lab/tests/test_ranked_decision_api.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from app import db, config, selection_judge
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(config, "DB_PATH", str(tmp_path / "insta.db"))
|
||||
monkeypatch.setattr(db, "DB_PATH", str(tmp_path / "insta.db"))
|
||||
monkeypatch.setattr(selection_judge, "judge_candidates", lambda c: {})
|
||||
db.init_db()
|
||||
from app.main import app
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_ranked_returns_sorted_eligible(client, monkeypatch):
|
||||
db.add_trending_keyword({"keyword": "금리", "category": "economy", "score": 0.9})
|
||||
r = client.get("/api/insta/keywords/ranked?threshold=0.0&limit=10")
|
||||
assert r.status_code == 200
|
||||
items = r.json()["items"]
|
||||
assert len(items) >= 1
|
||||
assert "final_score" in items[0] and "eligible" in items[0]
|
||||
|
||||
|
||||
def test_decision_approve_publishes(client):
|
||||
sid = db.add_card_slate({"keyword": "금리", "category": "economy"})
|
||||
r = client.post(f"/api/insta/slates/{sid}/decision", json={"decision": "approved"})
|
||||
assert r.status_code == 200
|
||||
assert db.get_card_slate(sid)["status"] == "published"
|
||||
|
||||
|
||||
def test_decision_reject(client):
|
||||
sid = db.add_card_slate({"keyword": "환율", "category": "economy"})
|
||||
r = client.post(f"/api/insta/slates/{sid}/decision", json={"decision": "rejected"})
|
||||
assert r.status_code == 200
|
||||
assert db.get_card_slate(sid)["status"] == "rejected"
|
||||
|
||||
|
||||
def test_decision_invalid_400(client):
|
||||
sid = db.add_card_slate({"keyword": "x", "category": "economy"})
|
||||
r = client.post(f"/api/insta/slates/{sid}/decision", json={"decision": "maybe"})
|
||||
assert r.status_code == 400
|
||||
Reference in New Issue
Block a user