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

17 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.path_params.tutorial004 import app 1abcde

4 

5client = TestClient(app) 1abcde

6 

7 

8def test_file_path(): 1abcde

9 response = client.get("/files/home/johndoe/myfile.txt") 1abcde

10 print(response.content) 1abcde

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

12 assert response.json() == {"file_path": "home/johndoe/myfile.txt"} 1abcde

13 

14 

15def test_root_file_path(): 1abcde

16 response = client.get("/files//home/johndoe/myfile.txt") 1abcde

17 print(response.content) 1abcde

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

19 assert response.json() == {"file_path": "/home/johndoe/myfile.txt"} 1abcde

20 

21 

22def test_openapi_schema(): 1abcde

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

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

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

26 "openapi": "3.1.0", 

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

28 "paths": { 

29 "/files/{file_path}": { 

30 "get": { 

31 "responses": { 

32 "200": { 

33 "description": "Successful Response", 

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

35 }, 

36 "422": { 

37 "description": "Validation Error", 

38 "content": { 

39 "application/json": { 

40 "schema": { 

41 "$ref": "#/components/schemas/HTTPValidationError" 

42 } 

43 } 

44 }, 

45 }, 

46 }, 

47 "summary": "Read File", 

48 "operationId": "read_file_files__file_path__get", 

49 "parameters": [ 

50 { 

51 "required": True, 

52 "schema": {"title": "File Path", "type": "string"}, 

53 "name": "file_path", 

54 "in": "path", 

55 } 

56 ], 

57 } 

58 } 

59 }, 

60 "components": { 

61 "schemas": { 

62 "ValidationError": { 

63 "title": "ValidationError", 

64 "required": ["loc", "msg", "type"], 

65 "type": "object", 

66 "properties": { 

67 "loc": { 

68 "title": "Location", 

69 "type": "array", 

70 "items": { 

71 "anyOf": [{"type": "string"}, {"type": "integer"}] 

72 }, 

73 }, 

74 "msg": {"title": "Message", "type": "string"}, 

75 "type": {"title": "Error Type", "type": "string"}, 

76 }, 

77 }, 

78 "HTTPValidationError": { 

79 "title": "HTTPValidationError", 

80 "type": "object", 

81 "properties": { 

82 "detail": { 

83 "title": "Detail", 

84 "type": "array", 

85 "items": {"$ref": "#/components/schemas/ValidationError"}, 

86 } 

87 }, 

88 }, 

89 } 

90 }, 

91 }