Debian Codegraph @

tests/test_additional_responses_bad.py

raw
1 import pytest
2 from fastapi import FastAPI
3 from fastapi.testclient import TestClient
4
5 app = FastAPI()
6
7
8 @app.get("/a", responses={"hello": {"description": "Not a valid additional response"}})
9 async def a():
10 pass # pragma: no cover
11
12
13 openapi_schema = {
14 "openapi": "3.1.0",
15 "info": {"title": "FastAPI", "version": "0.1.0"},
16 "paths": {
17 "/a": {
18 "get": {
19 "responses": {
20 # this is how one would imagine the openapi schema to be
21 # but since the key is not valid, openapi.utils.get_openapi will raise ValueError
22 "hello": {"description": "Not a valid additional response"},
23 "200": {
24 "description": "Successful Response",
25 "content": {"application/json": {"schema": {}}},
26 },
27 },
28 "summary": "A",
29 "operationId": "a_a_get",
30 }
31 }
32 },
33 }
34
35 client = TestClient(app)
36
37
38 def test_openapi_schema():
39 with pytest.raises(ValueError):
40 client.get("/openapi.json")