Coverage for tests / test_tutorial / test_metadata / test_tutorial003.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from fastapi.testclient import TestClient 1abcd

2from inline_snapshot import snapshot 1abcd

3 

4from docs_src.metadata.tutorial003_py310 import app 1abcd

5 

6client = TestClient(app) 1abcd

7 

8 

9def test_items(): 1abcd

10 response = client.get("/items/") 1efgh

11 assert response.status_code == 200, response.text 1efgh

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

13 

14 

15def test_openapi_schema(): 1abcd

16 response = client.get("/openapi.json") 1ijkl

17 assert response.status_code == 200, response.text 1ijkl

18 assert response.json() == snapshot( 1ijkl

19 { 

20 "openapi": "3.1.0", 

21 "info": { 

22 "title": "FastAPI", 

23 "version": "0.1.0", 

24 }, 

25 "paths": { 

26 "/items/": { 

27 "get": { 

28 "summary": "Read Items", 

29 "operationId": "read_items_items__get", 

30 "responses": { 

31 "200": { 

32 "description": "Successful Response", 

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

34 } 

35 }, 

36 } 

37 } 

38 }, 

39 } 

40 ) 

41 

42 

43def test_swagger_ui_default_url(): 1abcd

44 response = client.get("/docs") 1qrst

45 assert response.status_code == 404, response.text 1qrst

46 

47 

48def test_swagger_ui_custom_url(): 1abcd

49 response = client.get("/documentation") 1mnop

50 assert response.status_code == 200, response.text 1mnop

51 assert "<title>FastAPI - Swagger UI</title>" in response.text 1mnop

52 

53 

54def test_redoc_ui_default_url(): 1abcd

55 response = client.get("/redoc") 1uvwx

56 assert response.status_code == 404, response.text 1uvwx