54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
"""P4.0: категория жалобы, source, старые NULL видны в attention."""
|
|
import importlib
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
if ROOT not in sys.path:
|
|
sys.path.insert(0, ROOT)
|
|
|
|
|
|
@pytest.fixture()
|
|
def env(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("DB_PATH", str(tmp_path / "t.db"))
|
|
monkeypatch.setenv("SESSION_SECRET", "test-secret")
|
|
monkeypatch.setenv("AI_BACKEND", "claude")
|
|
monkeypatch.chdir(ROOT)
|
|
import auth
|
|
import db
|
|
import main
|
|
import attention
|
|
for m in (db, auth, main, attention):
|
|
importlib.reload(m)
|
|
db.init_db()
|
|
db.create_user("joe@x", auth.hash_password("Passw0rd!ok"))
|
|
db.admin_verify_user("joe@x")
|
|
from fastapi.testclient import TestClient
|
|
client = TestClient(main.app)
|
|
h = {"Authorization": "Bearer " + auth._make_token("joe@x", "user")}
|
|
return db, client, h, attention
|
|
|
|
|
|
def test_category_and_source_are_stored(env):
|
|
db, client, h, attention = env
|
|
r = client.post("/api/feedback", json={"comment": "не то", "answer": "a",
|
|
"category": "off_topic", "source": "chat"}, headers=h)
|
|
assert r.status_code == 200, r.text
|
|
row = db.get_feedback(1)[0]
|
|
assert row["category"] == "off_topic" and row["source"] == "chat"
|
|
assert db.count_feedback_new() == 1
|
|
keys = {i["key"] for i in attention.collect({}, {"accounts_total_rub": 0})["items"]}
|
|
assert "feedback:new" in keys
|
|
assert client.post("/api/feedback", json={"comment": "x", "category": "nope"},
|
|
headers=h).status_code == 400
|
|
|
|
|
|
def test_old_null_category_still_counts(env):
|
|
db, client, h, attention = env
|
|
db.save_feedback("joe@x", "t1", "старая жалоба", "a")
|
|
row = db.get_feedback(1)[0]
|
|
assert row["category"] is None and row["status"] == "new"
|
|
assert db.count_feedback_new() == 1
|