Debian Codegraph @

tests/test_tutorial/test_path_params/test_tutorial004.py

raw
1 from fastapi.testclient import TestClient
2 from inline_snapshot import snapshot
3
4 from docs_src.path_params.tutorial004_py310 import app
5
6 client = TestClient(app)
7
8
9 def test_file_path():
10 response = client.get("/files/home/johndoe/myfile.txt")
11 print(response.content)
12 assert response.status_code == 200, response.text
13 assert response.json() == {"file_path": "home/johndoe/myfile.txt"}
14
15
16 def test_root_file_path():
17 response = client.get("/files//home/johndoe/myfile.txt")
18 print(response.content)
19 assert response.status_code == 200, response.text
20 assert response.json() == {"file_path": "/home/johndoe/myfile.txt"}
21
22
23 def test_openapi_schema():
24 response = client.get("/openapi.json")
25 assert response.status_code == 200, response.text
26 assert response.json() == snapshot(
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 )