- Auth/roles (no self-reg), admin user provision, JWT - Analyze: sales kit + initial pain-fit from form/upload - Persona generator: 15 personas (5/tier) w/ pain variety, negotiation, init mode, channel, latent/revealable, wrong_text special - Chat simulator: per-mode initiation, one-shot, hidden signals, judge-LLM debrief+coaching - Trainee loop: win/lose board, weak-areas, user-generated personas - Admin analytics; EN+TH Vue SPA served by Flask - Deploy: Dockerfile, docker-compose, README, eng-log + HANDOFF - Tests (mock LLM): m0/m1/routes/e2e all pass
80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
"""Verify the whole backend imports without errors (no LLM calls)."""
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import warnings
|
|
from pathlib import Path
|
|
|
|
warnings.filterwarnings("ignore", message="The HMAC key is")
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
|
|
|
tempdir = tempfile.mkdtemp(prefix="st_import_")
|
|
os.environ["DATA_DIR"] = tempdir
|
|
os.environ["JWT_SECRET"] = "test-secret-key-0123456789abcdef"
|
|
|
|
from app.factory import create_app # noqa: E402
|
|
from app.config import Config # noqa: E402
|
|
|
|
Config.DATA_DIR = Path(tempdir)
|
|
# Force no LLM for import/structural test (analyze path tested separately)
|
|
Config.LLM_API_KEY = ""
|
|
Config.LLM_BASE_URL = ""
|
|
|
|
|
|
def main():
|
|
app = create_app()
|
|
# LLM should be None (no API key in test env)
|
|
assert app.extensions["llm"] is None, "expect no LLM in test env"
|
|
client = app.test_client()
|
|
|
|
# login as super-admin
|
|
r = client.post("/api/auth/login", json={
|
|
"email": "admin@salestrainer.local", "password": "admin123"})
|
|
assert r.status_code == 200, r.get_json()
|
|
token = r.get_json()["token"]
|
|
H = {"Authorization": f"Bearer {token}"}
|
|
|
|
# create a group via JSON form (no files)
|
|
r = client.post("/api/groups", json={
|
|
"product": "Cloud POS system for small restaurants",
|
|
"segment": "SME restaurants",
|
|
"description": "Target Bangkok SME restaurants, 1-3 branches",
|
|
"channel": "line",
|
|
"language": "th",
|
|
}, headers=H)
|
|
assert r.status_code == 201, r.get_json()
|
|
gid = r.get_json()["group"]["id"]
|
|
assert r.get_json()["group"]["status"] == "draft"
|
|
print("[ok] group created (draft)")
|
|
|
|
# analyze should fail cleanly (LLM None)
|
|
r = client.post(f"/api/groups/{gid}/analyze", headers=H)
|
|
assert r.status_code == 500, r.get_json()
|
|
print("[ok] analyze fails cleanly when LLM unset (500)")
|
|
|
|
# list groups as admin
|
|
r = client.get("/api/groups", headers=H)
|
|
assert r.status_code == 200 and len(r.get_json()["groups"]) == 1
|
|
print("[ok] admin lists 1 group")
|
|
|
|
# personas empty until analyze
|
|
r = client.get(f"/api/groups/{gid}", headers=H)
|
|
assert r.get_json()["group"]["personas"] == []
|
|
print("[ok] group has no personas before analyze")
|
|
|
|
# trainee created; can list groups but only 'ready' ones (this one is 'failed' -> hidden)
|
|
client.post("/api/admin/users", json={
|
|
"name": "Trainee", "email": "t@x.com", "password": "pass123", "role": "user"}, headers=H)
|
|
r = client.post("/api/auth/login", json={"email": "t@x.com", "password": "pass123"})
|
|
ut = r.get_json()["token"]
|
|
UH = {"Authorization": f"Bearer {ut}"}
|
|
r = client.get("/api/groups", headers=UH)
|
|
assert r.get_json()["groups"] == [], "trainee should not see non-ready groups"
|
|
print("[ok] trainee cannot see non-ready groups")
|
|
|
|
print("\nALL M1/M2-IMPORT TESTS PASSED")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|