43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
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
|