#!/usr/bin/env python3 """GeneCup end-to-end smoke test (anonymous flow, GRIA1 x function).""" import http.cookiejar, re, sys, urllib.parse, urllib.request import os BASE = os.environ.get("BASE", "http://127.0.0.1:4201") opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor( http.cookiejar.CookieJar())) opener.addheaders = [("User-Agent", "genecup-smoke/1.0")] def get(path, timeout=60): return opener.open(BASE + path, timeout=timeout).read().decode(errors="replace") results = [] def check(name, ok, detail=""): results.append((name, ok, detail)) print(("PASS " if ok else "FAIL ") + name + (" -- " + detail if detail else "")) b = get("/") check("front page", "GeneCup" in b) b = get("/about") check("about page with version", bool(re.search(r"1\.9", b))) b = get("/progress?query=GRIA1&type=function") m = re.search(r'cytoscape/\?rnd=([^"&]+)&genequery=([^"&]+)', b) check("search kickoff (progress page)", bool(m)) if not m: sys.exit(1) rnd, genequery = m.group(1), m.group(2) # the SSE stream: read until the SERVER ends it (the generator writes # nodes.json/edges.json only after the final yield -- closing early # kills it mid-flight) progress = [] r = opener.open(BASE + "/search", timeout=420) for raw in r: line = raw.decode().strip() if line.startswith("data:"): progress.append(line[5:].strip()) check("search stream completed", bool(progress) and progress[-1] == "100", "progress=" + ",".join(progress)) b = get(f"/cytoscape/?rnd={rnd}&genequery={genequery}") check("cytoscape graph page", "var cy = cytoscape(" in b and "nodecolor" in b, f"{len(b)} bytes") b = get(f"/tableview/?rnd={rnd}&genequery={genequery}") check("table view has data", ("GRIA1" in b or "gria1" in b.lower()), f"{len(b)} bytes") m2 = re.search(r"sentences\?edgeID=([^\"']+)", b) if not m2: # the table renders client-side; pull an edgeID from the cytoscape page m2 = re.search(r"sentences\?edgeID=([^\"']+)", get(f"/cytoscape/?rnd={rnd}&genequery={genequery}")) check("edgeID available", bool(m2)) if m2: edge = urllib.parse.quote(m2.group(1), safe="") b = get("/sentences?edgeID=" + edge) ok = b.count("PMID") > 0 # the template has no closing </html> check("sentences page", ok, f"{len(b)} bytes" + ("" if ok else " -- " + re.sub(r"\s+"," ",re.sub(r"<[^>]*>"," ",b))[:250])) for a in ("bootstrap.min.css", "cytoscape.min.js", "jquery.slim.min.js"): b = get("/static/" + a) check("static " + a, len(b) > 1000, f"{len(b)} bytes") print() failed = [r for r in results if not r[1]] print(f"== {len(results)-len(failed)} passed, {len(failed)} failed ==") sys.exit(1 if failed else 0)