rosdiff / tests /test_webapp.py
Chandra Kiran
Add a web app for testers
d686d47 unverified
Raw History Blame Contribute Delete
2.61 kB
import io
import json
import zipfile
from conftest import complete
from ros_fixtures import INTERFACES, as_file_blocks, python_package
from api.ros_check import load_interfaces
def test_app_page_and_assets_are_served(run_env):
client = run_env[0]
page = client.get("/")
assert page.status_code == 200 and "RosDiff" in page.text and "/static/app/app.js" in page.text
assert client.get("/static/app/app.js").status_code == 200
assert client.get("/static/app/app.css").status_code == 200
def test_history_generation_and_media(run_env):
client, keys_, backend, services, gen_id = run_env
h = {"X-API-Key": keys_["alice"]}
hist = client.get("/me/history", headers=h).json()
assert hist["tester"] == "alice" and hist["items"][0]["id"] == gen_id
assert hist["items"][0]["kind"] == "simulate" and hist["items"][0]["title"].startswith("G1 near a slope")
assert client.get("/me/history", headers={"X-API-Key": keys_["bob"]}).json()["items"] == []
run_id = client.post("/simulate/run", json={"generation_id": gen_id}, headers=h).json()["run_id"]
complete(backend, "job-1", run_id)
job = client.get(f"/jobs/{run_id}", headers=h).json()
assert job["media"]["video"].endswith(f"runs/{run_id}/video.mp4") and "video_webm" in job["media"]
g = client.get(f"/generations/{gen_id}", headers=h).json()
assert g["kind"] == "simulate" and g["valid"] and "<mujoco" in g["output"]
assert [j["id"] for j in g["jobs"]] == [run_id] and "/report/" in g["jobs"][0]["report_url"]
assert client.get(f"/generations/{gen_id}", headers={"X-API-Key": keys_["bob"]}).status_code == 404
def test_code_zip(run_env):
client, keys_, backend, services, _ = run_env
services.settings.data_dir.mkdir(parents=True, exist_ok=True)
services.settings.interfaces_file.write_text(json.dumps(INTERFACES))
load_interfaces.cache_clear()
services.llm_factory().responses[:] = [as_file_blocks(python_package())]
h = {"X-API-Key": keys_["alice"]}
gen = client.post("/code/generate", json={"request": "Stop on a close LaserScan reading"}, headers=h).json()
r = client.get(f"/code/{gen['id']}/zip", headers=h)
assert r.status_code == 200 and r.headers["content-type"] == "application/zip"
names = zipfile.ZipFile(io.BytesIO(r.content)).namelist()
assert "safety_stop/package.xml" in names
assert client.get(f"/code/{gen['id']}/zip", headers={"X-API-Key": keys_["bob"]}).status_code == 404
g = client.get(f"/generations/{gen['id']}", headers=h).json()
assert g["kind"] == "code" and "safety_stop/package.xml" in g["output"]