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

13 statements  

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

1import pytest 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4from docs_src.path_operation_configuration.tutorial006 import app 1abcde

5 

6client = TestClient(app) 1abcde

7 

8 

9@pytest.mark.parametrize( 1abcde

10 "path,expected_status,expected_response", 

11 [ 

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

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

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

15 ], 

16) 

17def test_query_params_str_validations(path, expected_status, expected_response): 1abcde

18 response = client.get(path) 1abcde

19 assert response.status_code == expected_status 1abcde

20 assert response.json() == expected_response 1abcde

21 

22 

23def test_openapi_schema(): 1abcde

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

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

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

27 "openapi": "3.1.0", 

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

29 "paths": { 

30 "/items/": { 

31 "get": { 

32 "responses": { 

33 "200": { 

34 "description": "Successful Response", 

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

36 } 

37 }, 

38 "tags": ["items"], 

39 "summary": "Read Items", 

40 "operationId": "read_items_items__get", 

41 } 

42 }, 

43 "/users/": { 

44 "get": { 

45 "responses": { 

46 "200": { 

47 "description": "Successful Response", 

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

49 } 

50 }, 

51 "tags": ["users"], 

52 "summary": "Read Users", 

53 "operationId": "read_users_users__get", 

54 } 

55 }, 

56 "/elements/": { 

57 "get": { 

58 "responses": { 

59 "200": { 

60 "description": "Successful Response", 

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

62 } 

63 }, 

64 "tags": ["items"], 

65 "summary": "Read Elements", 

66 "operationId": "read_elements_elements__get", 

67 "deprecated": True, 

68 } 

69 }, 

70 }, 

71 }