Coverage for tests / test_tutorial / test_path_params / test_tutorial004.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« 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
4from docs_src.path_params.tutorial004_py310 import app 1abcd
6client = TestClient(app) 1abcd
9def test_file_path(): 1abcd
10 response = client.get("/files/home/johndoe/myfile.txt") 1efg
11 print(response.content) 1efg
12 assert response.status_code == 200, response.text 1efg
13 assert response.json() == {"file_path": "home/johndoe/myfile.txt"} 1efg
16def test_root_file_path(): 1abcd
17 response = client.get("/files//home/johndoe/myfile.txt") 1hij
18 print(response.content) 1hij
19 assert response.status_code == 200, response.text 1hij
20 assert response.json() == {"file_path": "/home/johndoe/myfile.txt"} 1hij
23def test_openapi_schema(): 1abcd
24 response = client.get("/openapi.json") 1klm
25 assert response.status_code == 200, response.text 1klm
26 assert response.json() == snapshot( 1klm
27 {
28 "openapi": "3.1.0",
29 "info": {"title": "FastAPI", "version": "0.1.0"},
30 "paths": {
31 "/files/{file_path}": {
32 "get": {
33 "responses": {
34 "200": {
35 "description": "Successful Response",
36 "content": {"application/json": {"schema": {}}},
37 },
38 "422": {
39 "description": "Validation Error",
40 "content": {
41 "application/json": {
42 "schema": {
43 "$ref": "#/components/schemas/HTTPValidationError"
44 }
45 }
46 },
47 },
48 },
49 "summary": "Read File",
50 "operationId": "read_file_files__file_path__get",
51 "parameters": [
52 {
53 "required": True,
54 "schema": {"title": "File Path", "type": "string"},
55 "name": "file_path",
56 "in": "path",
57 }
58 ],
59 }
60 }
61 },
62 "components": {
63 "schemas": {
64 "ValidationError": {
65 "title": "ValidationError",
66 "required": ["loc", "msg", "type"],
67 "type": "object",
68 "properties": {
69 "loc": {
70 "title": "Location",
71 "type": "array",
72 "items": {
73 "anyOf": [{"type": "string"}, {"type": "integer"}]
74 },
75 },
76 "msg": {"title": "Message", "type": "string"},
77 "type": {"title": "Error Type", "type": "string"},
78 "input": {"title": "Input"},
79 "ctx": {"title": "Context", "type": "object"},
80 },
81 },
82 "HTTPValidationError": {
83 "title": "HTTPValidationError",
84 "type": "object",
85 "properties": {
86 "detail": {
87 "title": "Detail",
88 "type": "array",
89 "items": {
90 "$ref": "#/components/schemas/ValidationError"
91 },
92 }
93 },
94 },
95 }
96 },
97 }
98 )