96 lines
2.3 KiB
Python
96 lines
2.3 KiB
Python
"""FastAPI TestClient-based tests for accurate coverage measurement."""
|
|
from __future__ import annotations
|
|
import io, json, pytest
|
|
from fastapi.testclient import TestClient
|
|
from web.api import app
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_index():
|
|
r = client.get("/")
|
|
assert r.status_code == 200
|
|
assert "verify" in r.text.lower()
|
|
|
|
|
|
def test_verify_422_empty():
|
|
r = client.post("/verify")
|
|
assert r.status_code == 422
|
|
|
|
|
|
def test_verify_202():
|
|
r = client.post("/verify",
|
|
files={
|
|
"copybook": ("t.cpy", b"x", "text/plain"),
|
|
"cobol_src": ("t.cbl", b"x", "text/plain"),
|
|
"java_src": ("t.java", b"x", "text/plain"),
|
|
"mapping": ("t.yaml", b"x", "text/plain"),
|
|
},
|
|
data={"runner": "native"})
|
|
assert r.status_code == 202
|
|
body = r.json()
|
|
assert "task_id" in body
|
|
return body["task_id"]
|
|
|
|
|
|
def test_verify_large_file_413():
|
|
r = client.post("/verify",
|
|
files={
|
|
"copybook": ("t.cpy", b"x", "text/plain"),
|
|
"cobol_src": ("t.cbl", b"x" * (10 * 1024 * 1024 + 1), "application/octet-stream"),
|
|
"java_src": ("t.java", b"x", "text/plain"),
|
|
"mapping": ("t.yaml", b"x", "text/plain"),
|
|
},
|
|
data={"runner": "native"})
|
|
assert r.status_code == 413
|
|
|
|
|
|
def test_status_404():
|
|
r = client.get("/status/nonexistent")
|
|
assert r.status_code == 404
|
|
|
|
|
|
def test_status_ok():
|
|
tid = test_verify_202()
|
|
r = client.get(f"/status/{tid}")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["status"] in ("queued", "running", "done", "error")
|
|
|
|
|
|
def test_fields_404():
|
|
r = client.get("/fields/nonexistent")
|
|
assert r.status_code == 404
|
|
|
|
|
|
def test_fields_ok():
|
|
tid = test_verify_202()
|
|
r = client.get(f"/fields/{tid}")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert "fields" in body
|
|
assert "debug" in body
|
|
assert "build_log" in body
|
|
|
|
|
|
def test_result_404():
|
|
r = client.get("/result/nonexistent")
|
|
assert r.status_code == 404
|
|
|
|
|
|
def test_result_page():
|
|
tid = test_verify_202()
|
|
r = client.get(f"/result/{tid}")
|
|
assert r.status_code == 200
|
|
assert tid in r.text
|
|
|
|
|
|
def test_static_css():
|
|
r = client.get("/static/style.css")
|
|
assert r.status_code == 200
|
|
|
|
|
|
def test_static_js():
|
|
r = client.get("/static/script.js")
|
|
assert r.status_code == 200
|