Coverage for tests/test_tutorial/test_extending_openapi/test_tutorial001.py: 100%

15 statements  

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

1from fastapi.testclient import TestClient 1abcde

2 

3from docs_src.extending_openapi.tutorial001 import app 1abcde

4 

5client = TestClient(app) 1abcde

6 

7 

8def test(): 1abcde

9 response = client.get("/items/") 1abcde

10 assert response.status_code == 200, response.text 1abcde

11 assert response.json() == [{"name": "Foo"}] 1abcde

12 

13 

14def test_openapi_schema(): 1abcde

15 response = client.get("/openapi.json") 1abcde

16 assert response.status_code == 200, response.text 1abcde

17 assert response.json() == { 1abcde

18 "openapi": "3.1.0", 

19 "info": { 

20 "title": "Custom title", 

21 "summary": "This is a very custom OpenAPI schema", 

22 "description": "Here's a longer description of the custom **OpenAPI** schema", 

23 "version": "2.5.0", 

24 "x-logo": { 

25 "url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" 

26 }, 

27 }, 

28 "paths": { 

29 "/items/": { 

30 "get": { 

31 "responses": { 

32 "200": { 

33 "description": "Successful Response", 

34 "content": {"application/json": {"schema": {}}}, 

35 } 

36 }, 

37 "summary": "Read Items", 

38 "operationId": "read_items_items__get", 

39 } 

40 } 

41 }, 

42 } 

43 openapi_schema = response.json() 1abcde

44 # Request again to test the custom cache 

45 response = client.get("/openapi.json") 1abcde

46 assert response.status_code == 200, response.text 1abcde

47 assert response.json() == openapi_schema 1abcde