| 1 |
import pytest |
| 2 |
from fastapi.testclient import TestClient |
| 3 |
from inline_snapshot import snapshot |
| 4 |
|
| 5 |
from docs_src.path_operation_configuration.tutorial006_py310 import app |
| 6 |
|
| 7 |
client = TestClient(app) |
| 8 |
|
| 9 |
|
| 10 |
@pytest.mark.parametrize( |
| 11 |
"path,expected_status,expected_response", |
| 12 |
[ |
| 13 |
("/items/", 200, [{"name": "Foo", "price": 42}]), |
| 14 |
("/users/", 200, [{"username": "johndoe"}]), |
| 15 |
("/elements/", 200, [{"item_id": "Foo"}]), |
| 16 |
], |
| 17 |
) |
| 18 |
def test_query_params_str_validations(path, expected_status, expected_response): |
| 19 |
response = client.get(path) |
| 20 |
assert response.status_code == expected_status |
| 21 |
assert response.json() == expected_response |
| 22 |
|
| 23 |
|
| 24 |
def test_openapi_schema(): |
| 25 |
response = client.get("/openapi.json") |
| 26 |
assert response.status_code == 200, response.text |
| 27 |
assert response.json() == snapshot( |
| 28 |
{ |
| 29 |
"openapi": "3.1.0", |
| 30 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 31 |
"paths": { |
| 32 |
"/items/": { |
| 33 |
"get": { |
| 34 |
"responses": { |
| 35 |
"200": { |
| 36 |
"description": "Successful Response", |
| 37 |
"content": {"application/json": {"schema": {}}}, |
| 38 |
} |
| 39 |
}, |
| 40 |
"tags": ["items"], |
| 41 |
"summary": "Read Items", |
| 42 |
"operationId": "read_items_items__get", |
| 43 |
} |
| 44 |
}, |
| 45 |
"/users/": { |
| 46 |
"get": { |
| 47 |
"responses": { |
| 48 |
"200": { |
| 49 |
"description": "Successful Response", |
| 50 |
"content": {"application/json": {"schema": {}}}, |
| 51 |
} |
| 52 |
}, |
| 53 |
"tags": ["users"], |
| 54 |
"summary": "Read Users", |
| 55 |
"operationId": "read_users_users__get", |
| 56 |
} |
| 57 |
}, |
| 58 |
"/elements/": { |
| 59 |
"get": { |
| 60 |
"responses": { |
| 61 |
"200": { |
| 62 |
"description": "Successful Response", |
| 63 |
"content": {"application/json": {"schema": {}}}, |
| 64 |
} |
| 65 |
}, |
| 66 |
"tags": ["items"], |
| 67 |
"summary": "Read Elements", |
| 68 |
"operationId": "read_elements_elements__get", |
| 69 |
"deprecated": True, |
| 70 |
} |
| 71 |
}, |
| 72 |
}, |
| 73 |
} |
| 74 |
) |