Coverage for tests/test_additional_responses_bad.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1import pytest 1abcde

2from fastapi import FastAPI 1abcde

3from fastapi.testclient import TestClient 1abcde

4 

5app = FastAPI() 1abcde

6 

7 

8@app.get("/a", responses={"hello": {"description": "Not a valid additional response"}}) 1abcde

9async def a(): 1abcde

10 pass # pragma: no cover 

11 

12 

13openapi_schema = { 1abcde

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 

35client = TestClient(app) 1abcde

36 

37 

38def test_openapi_schema(): 1abcde

39 with pytest.raises(ValueError): 1abcde

40 client.get("/openapi.json") 1abcde