Spaces:
Sleeping
Sleeping
Download test/services/test_api_validation_message.py from fitzpatrick9/jade-meadow-5791: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/fitzpatrick9/jade-meadow-5791/resolve/main/test/services/test_api_validation_message.py
- Command line
-
hf download hf://spaces/fitzpatrick9/jade-meadow-5791/test/services/test_api_validation_message.py
-
curl -L -o test_api_validation_message.py https://huggingface.co/spaces/fitzpatrick9/jade-meadow-5791/resolve/main/test/services/test_api_validation_message.py
1.62 kB
| from unittest.mock import patch | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| from app import asgi | |
| from app.config import config | |
| def _post(path, content): | |
| with ( | |
| patch.dict(config.app, {"api_key": ""}), | |
| patch("app.controllers.v1.video.task_manager.add_task") as schedule, | |
| patch("app.controllers.v1.llm.llm.generate_script") as generate, | |
| TestClient(asgi.get_application(), raise_server_exceptions=False) as client, | |
| ): | |
| response = client.post( | |
| path, content=content, headers={"content-type": "application/json"} | |
| ) | |
| schedule.assert_not_called() | |
| generate.assert_not_called() | |
| return response | |
| def test_validation_message_describes_the_rejected_field(content, expected): | |
| # Out-of-range values and malformed JSON used to be reported as | |
| # "field required", pointing clients at a field that was present. | |
| response = _post("/api/v1/scripts", content) | |
| assert response.status_code == 400 | |
| body = response.json() | |
| assert body["message"] == expected | |
| assert body["data"][0]["msg"] in expected | |
| def test_missing_field_message_still_says_field_required(): | |
| response = _post("/api/v1/videos", "{}") | |
| assert response.status_code == 400 | |
| assert response.json()["message"] == "body.video_subject: Field required" | |