STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_error_sentences.py
Go to the documentation of this file.
1"""Every error response is {"detail": "<one plain sentence>"} (docs/investor contract C3).
2
3FastAPI's own request-validation failures used to send `detail` as a list of {loc, msg, type}
4objects, which a page rendered as "[object Object]".
5"""
6
7from fastapi.testclient import TestClient
8
9from backend.main import app, validation_sentence
10
11
13 errs = [{"loc": ("body", "lox_pressure_psi"), "msg": "Input should be a valid number", "type": "x"},
14 {"loc": ("body", "fuel_pressure_psi"), "msg": "Field required", "type": "y"}]
15 # Every problem, by its field -- not the first and a count (a rail with two bad fields used
16 # to say only the first).
17 assert validation_sentence(errs) == (
18 "Lox pressure psi: Input should be a valid number; fuel pressure psi: Field required."
19 )
20 assert validation_sentence([]) == "Some of the values were not accepted."
21
22
24 client = TestClient(app)
25 r = client.post("/api/evaluate", json={"lox_pressure_psi": "not a number"})
26 assert r.status_code == 422
27 detail = r.json()["detail"]
28 assert isinstance(detail, str) and detail.endswith(".")
29
30
32 client = TestClient(app)
33 r = client.post("/api/evaluate", json={"lox_pressure_psi": "not a number"})
34 errors = r.json()["errors"]
35 assert errors and all(isinstance(e["loc"], list) and "msg" in e for e in errors)
test_the_field_paths_ride_along_for_pages_with_their_own_names()