Coverage for tests/test_tutorial/test_custom_response/test_tutorial004.py: 100%

12 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.custom_response.tutorial004 import app 1abcde

4 

5client = TestClient(app) 1abcde

6 

7 

8html_contents = """ 1abcde

9 <html> 

10 <head> 

11 <title>Some HTML in here</title> 

12 </head> 

13 <body> 

14 <h1>Look ma! HTML!</h1> 

15 </body> 

16 </html> 

17 """ 

18 

19 

20def test_get_custom_response(): 1abcde

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

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

23 assert response.text == html_contents 1abcde

24 

25 

26def test_openapi_schema(): 1abcde

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

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

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

30 "openapi": "3.1.0", 

31 "info": {"title": "FastAPI", "version": "0.1.0"}, 

32 "paths": { 

33 "/items/": { 

34 "get": { 

35 "responses": { 

36 "200": { 

37 "description": "Successful Response", 

38 "content": {"text/html": {"schema": {"type": "string"}}}, 

39 } 

40 }, 

41 "summary": "Read Items", 

42 "operationId": "read_items_items__get", 

43 } 

44 } 

45 }, 

46 }