1 changed files with 116 additions and 0 deletions
@ -0,0 +1,116 @@ |
|||||
|
import pytest |
||||
|
from fastapi.testclient import TestClient |
||||
|
|
||||
|
from docs_src.path_params.tutorial001 import app |
||||
|
|
||||
|
client = TestClient(app) |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
("item_id", "expected_response"), |
||||
|
[ |
||||
|
(1, {"item_id": "1"}), |
||||
|
("alice", {"item_id": "alice"}), |
||||
|
], |
||||
|
) |
||||
|
def test_get_items(item_id, expected_response): |
||||
|
response = client.get(f"/items/{item_id}") |
||||
|
assert response.status_code == 200, response.text |
||||
|
assert response.json() == expected_response |
||||
|
|
||||
|
|
||||
|
def test_openapi_schema(): |
||||
|
response = client.get("/openapi.json") |
||||
|
assert response.status_code == 200, response.text |
||||
|
assert response.json() == { |
||||
|
"openapi": "3.1.0", |
||||
|
"info": {"title": "FastAPI", "version": "0.1.0"}, |
||||
|
"paths": { |
||||
|
"/items/{item_id}": { |
||||
|
"get": { |
||||
|
"operationId": "read_item_items__item_id__get", |
||||
|
"parameters": [ |
||||
|
{ |
||||
|
"in": "path", |
||||
|
"name": "item_id", |
||||
|
"required": True, |
||||
|
"schema": { |
||||
|
"title": "Item Id", |
||||
|
}, |
||||
|
}, |
||||
|
], |
||||
|
"responses": { |
||||
|
"200": { |
||||
|
"content": { |
||||
|
"application/json": { |
||||
|
"schema": {}, |
||||
|
}, |
||||
|
}, |
||||
|
"description": "Successful Response", |
||||
|
}, |
||||
|
"422": { |
||||
|
"content": { |
||||
|
"application/json": { |
||||
|
"schema": { |
||||
|
"$ref": "#/components/schemas/HTTPValidationError", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
"description": "Validation Error", |
||||
|
}, |
||||
|
}, |
||||
|
"summary": "Read Item", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
"components": { |
||||
|
"schemas": { |
||||
|
"HTTPValidationError": { |
||||
|
"properties": { |
||||
|
"detail": { |
||||
|
"items": { |
||||
|
"$ref": "#/components/schemas/ValidationError", |
||||
|
}, |
||||
|
"title": "Detail", |
||||
|
"type": "array", |
||||
|
}, |
||||
|
}, |
||||
|
"title": "HTTPValidationError", |
||||
|
"type": "object", |
||||
|
}, |
||||
|
"ValidationError": { |
||||
|
"properties": { |
||||
|
"loc": { |
||||
|
"items": { |
||||
|
"anyOf": [ |
||||
|
{ |
||||
|
"type": "string", |
||||
|
}, |
||||
|
{ |
||||
|
"type": "integer", |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
"title": "Location", |
||||
|
"type": "array", |
||||
|
}, |
||||
|
"msg": { |
||||
|
"title": "Message", |
||||
|
"type": "string", |
||||
|
}, |
||||
|
"type": { |
||||
|
"title": "Error Type", |
||||
|
"type": "string", |
||||
|
}, |
||||
|
}, |
||||
|
"required": [ |
||||
|
"loc", |
||||
|
"msg", |
||||
|
"type", |
||||
|
], |
||||
|
"title": "ValidationError", |
||||
|
"type": "object", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
} |
||||
Loading…
Reference in new issue