Coverage for tests / test_tutorial / test_path_operation_configurations / test_tutorial006.py: 100%

14 statements  

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

1import pytest 1abcd

2from fastapi.testclient import TestClient 1abcd

3from inline_snapshot import snapshot 1abcd

4 

5from docs_src.path_operation_configuration.tutorial006_py310 import app 1abcd

6 

7client = TestClient(app) 1abcd

8 

9 

10@pytest.mark.parametrize( 1abcd

11 "path,expected_status,expected_response", 

12 [ 

13 ("/items/", 200, [{"name": "Foo", "price": 42}]), 

14 ("/users/", 200, [{"username": "johndoe"}]), 

15 ("/elements/", 200, [{"item_id": "Foo"}]), 

16 ], 

17) 

18def test_query_params_str_validations(path, expected_status, expected_response): 1abcd

19 response = client.get(path) 1efg

20 assert response.status_code == expected_status 1efg

21 assert response.json() == expected_response 1efg

22 

23 

24def test_openapi_schema(): 1abcd

25 response = client.get("/openapi.json") 1hij

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

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

28 { 

29 "openapi": "3.1.0", 

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

31 "paths": { 

32 "/items/": { 

33 "get": { 

34 "responses": { 

35 "200": { 

36 "description": "Successful Response", 

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

38 } 

39 }, 

40 "tags": ["items"], 

41 "summary": "Read Items", 

42 "operationId": "read_items_items__get", 

43 } 

44 }, 

45 "/users/": { 

46 "get": { 

47 "responses": { 

48 "200": { 

49 "description": "Successful Response", 

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

51 } 

52 }, 

53 "tags": ["users"], 

54 "summary": "Read Users", 

55 "operationId": "read_users_users__get", 

56 } 

57 }, 

58 "/elements/": { 

59 "get": { 

60 "responses": { 

61 "200": { 

62 "description": "Successful Response", 

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

64 } 

65 }, 

66 "tags": ["items"], 

67 "summary": "Read Elements", 

68 "operationId": "read_elements_elements__get", 

69 "deprecated": True, 

70 } 

71 }, 

72 }, 

73 } 

74 )