mirror of
https://github.com/fastapi/fastapi.git
synced 2026-03-06 07:59:17 -05:00
🐛 Fix path in path parameters (#272)
This commit is contained in:
committed by
GitHub
parent
58f135ba2f
commit
703ade7967
0
tests/test_tutorial/test_path_params/__init__.py
Normal file
0
tests/test_tutorial/test_path_params/__init__.py
Normal file
91
tests/test_tutorial/test_path_params/test_tutorial004.py
Normal file
91
tests/test_tutorial/test_path_params/test_tutorial004.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from path_params.tutorial004 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
openapi_schema = {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "Fast API", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/files/{file_path}": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/HTTPValidationError"
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
"summary": "Read User Me",
|
||||
"operationId": "read_user_me_files__file_path__get",
|
||||
"parameters": [
|
||||
{
|
||||
"required": True,
|
||||
"schema": {"title": "File_Path", "type": "string"},
|
||||
"name": "file_path",
|
||||
"in": "path",
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"ValidationError": {
|
||||
"title": "ValidationError",
|
||||
"required": ["loc", "msg", "type"],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"loc": {
|
||||
"title": "Location",
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
},
|
||||
"msg": {"title": "Message", "type": "string"},
|
||||
"type": {"title": "Error Type", "type": "string"},
|
||||
},
|
||||
},
|
||||
"HTTPValidationError": {
|
||||
"title": "HTTPValidationError",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"detail": {
|
||||
"title": "Detail",
|
||||
"type": "array",
|
||||
"items": {"$ref": "#/components/schemas/ValidationError"},
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_openapi():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == openapi_schema
|
||||
|
||||
|
||||
def test_file_path():
|
||||
response = client.get("/files/home/johndoe/myfile.txt")
|
||||
print(response.content)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"file_path": "home/johndoe/myfile.txt"}
|
||||
|
||||
|
||||
def test_root_file_path():
|
||||
response = client.get("/files//home/johndoe/myfile.txt")
|
||||
print(response.content)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"file_path": "/home/johndoe/myfile.txt"}
|
||||
Reference in New Issue
Block a user