test: align with {"detail": ...} error envelope
swadhinbiswas committed 3 months ago
5b9fc82
1 parent c9d2ab9
commit 5b9fc82
5 files changed
+7 -8
Showing 5 changed files+7-8
▼crates/justapi-py/python/justapi/test_exceptions.py
+1-1
| @@ -85,7 +85,7 @@ def test_unhandled_exception_is_500(): | ||
85 | 85 | assert resp["status"] == 500 |
86 | 86 | # Secure default: internal error details must NOT leak to the client. |
87 | 87 | assert "kaboom" not in resp["body"].decode() |
88 | - assert json.loads(resp["body"])["error"] == "internal server error" | |
88 | + assert json.loads(resp["body"])["detail"] == "Internal Server Error" | |
89 | 89 | |
90 | 90 | |
91 | 91 | def test_request_validation_error_422(): |
92 | 92 | |
▼crates/justapi-py/python/justapi/test_native_fastpath.py
+2-2
| @@ -47,7 +47,7 @@ async def test_native_post_rejects_invalid_body(): | ||
47 | 47 | async with AsyncTestClient(app) as c: |
48 | 48 | r = await c.post("/users", body=json.dumps({"name": "Ada"}).encode()) |
49 | 49 | assert_status(r, 422) |
50 | - assert r["headers"].get("content-type") == "application/problem+json" | |
50 | + assert r["headers"].get("content-type") == "application/json" | |
51 | 51 | |
52 | 52 | |
53 | 53 | @pytest.mark.asyncio |
| @@ -116,7 +116,7 @@ async def test_native_get_rejects_invalid_query(): | ||
116 | 116 | async with AsyncTestClient(app) as c: |
117 | 117 | r = await c.get("/search?age=-5") |
118 | 118 | assert_status(r, 422) |
119 | - assert r["headers"].get("content-type") == "application/problem+json" | |
119 | + assert r["headers"].get("content-type") == "application/json" | |
120 | 120 | |
121 | 121 | |
122 | 122 | def test_native_with_route_dependencies_rejected(): |
123 | 123 | |
▼crates/justapi-py/python/justapi/test_schema_validation.py
+2-2
| @@ -113,8 +113,8 @@ def test_schema_validation(): | ||
113 | 113 | except urllib.error.HTTPError as e: |
114 | 114 | assert e.code == 422, f"Expected 422, got {e.code}" |
115 | 115 | error_data = json.loads(e.read()) |
116 | - assert error_data["title"] == "Validation Error" | |
117 | - assert any("email" in err.get("message", "") or "email" in err.get("field", "") for err in error_data["errors"]) | |
116 | + assert isinstance(error_data.get("detail"), str) and len(error_data["detail"]) > 0 | |
117 | + assert "email" in error_data["detail"].lower() | |
118 | 118 | print("PASS: Schema class missing field -> 422") |
119 | 119 | |
120 | 120 | # 4. Schema class: wrong type |
121 | 121 | |
▼crates/justapi-py/python/justapi/test_test_client.py
+1-1
| @@ -138,4 +138,4 @@ def test_test_client_schema_validation(): | ||
138 | 138 | resp = client.post("/users", payload) |
139 | 139 | assert resp["status"] == 422 |
140 | 140 | error_data = json.loads(bytes(resp["body"])) |
141 | - assert error_data["title"] == "Validation Error" | |
141 | + assert isinstance(error_data.get("detail"), str) and len(error_data["detail"]) > 0 | |
142 | 142 | |
▼crates/justapi-py/python/justapi/test_validation.py
+1-2
| @@ -94,8 +94,7 @@ def test_validation(): | ||
94 | 94 | except urllib.error.HTTPError as e: |
95 | 95 | assert e.code == 422, f"Expected 422, got {e.code}" |
96 | 96 | error_data = json.loads(e.read()) |
97 | - assert error_data["title"] == "Validation Error" | |
98 | - assert len(error_data["errors"]) > 0 | |
97 | + assert isinstance(error_data.get("detail"), str) and len(error_data["detail"]) > 0 | |
99 | 98 | print(f"PASS: POST /users with invalid body -> 422 ({error_data['detail']})") |
100 | 99 | |
101 | 100 | # 4. Invalid POST (name too short) |
102 | 101 | |