3
from fastapi import FastAPI, Response
4
from fastapi.testclient import TestClient
14
async def delete_deployment(
18
response.status_code = 400
19
return {"msg": "Status overwritten", "id": id}
22
client = TestClient(app)
25
def test_dependency_set_status_code():
26
response = client.delete("/1")
27
assert response.status_code == 400 and response.content
28
assert response.json() == {"msg": "Status overwritten", "id": 1}
31
def test_openapi_schema():
32
response = client.get("/openapi.json")
33
assert response.status_code == 200, response.text
34
assert response.json() == {
36
"info": {"title": "FastAPI", "version": "0.1.0"},
40
"summary": "Delete Deployment",
41
"operationId": "delete_deployment__id__delete",
45
"schema": {"title": "Id", "type": "integer"},
51
"204": {"description": "Successful Response"},
53
"description": "Validation Error",
57
"$ref": "#/components/schemas/HTTPValidationError"
68
"HTTPValidationError": {
69
"title": "HTTPValidationError",
75
"items": {"$ref": "#/components/schemas/ValidationError"},
80
"title": "ValidationError",
81
"required": ["loc", "msg", "type"],
88
"anyOf": [{"type": "string"}, {"type": "integer"}]
91
"msg": {"title": "Message", "type": "string"},
92
"type": {"title": "Error Type", "type": "string"},