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

15 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi.testclient import TestClient 1abcd

2from inline_snapshot import snapshot 1abcd

3 

4from docs_src.metadata.tutorial002_py310 import app 1abcd

5 

6client = TestClient(app) 1abcd

7 

8 

9def test_items(): 1abcd

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

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

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

13 

14 

15def test_get_openapi_json_default_url(): 1abcd

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

17 assert response.status_code == 404, response.text 1klm

18 

19 

20def test_openapi_schema(): 1abcd

21 response = client.get("/api/v1/openapi.json") 1hij

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

23 assert response.json() == snapshot( 1hij

24 { 

25 "openapi": "3.1.0", 

26 "info": { 

27 "title": "FastAPI", 

28 "version": "0.1.0", 

29 }, 

30 "paths": { 

31 "/items/": { 

32 "get": { 

33 "summary": "Read Items", 

34 "operationId": "read_items_items__get", 

35 "responses": { 

36 "200": { 

37 "description": "Successful Response", 

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

39 } 

40 }, 

41 } 

42 } 

43 }, 

44 } 

45 )