File size: 1,203 Bytes
57d7008 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | """Import local_agent's Flask app and exercise the new routes with the Flask
test client - no real server socket is opened, so this exits on its own.
Run: python tools\\_webapp_check.py
"""
import os
import sys
BUILD = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(BUILD, "LocalAgent"))
import local_agent as la # noqa: E402
app = la.build_web_app()
client = app.test_client()
def show(name, resp):
body = resp.get_data(as_text=True)
print("%-28s %s %s" % (name, resp.status_code, body[:220].replace("\n", " ")))
show("GET /", client.get("/"))
show("GET /api/health", client.get("/api/health"))
show("GET /api/search/status", client.get("/api/search/status"))
show("GET /api/speech/capabilities", client.get("/api/speech/capabilities"))
show("POST /api/search/test", client.post("/api/search/test", json={"q": "python", "limit": 3}))
show("POST /api/tts (should fail, no text)", client.post("/api/tts", json={}))
resp = client.post("/api/tts", json={"text": "Hello from local agent."})
print("%-28s %s %s bytes, content-type=%s" % (
"POST /api/tts (real)", resp.status_code, len(resp.get_data()), resp.content_type))
print("done")
|