| 1 |
from fastapi.testclient import TestClient |
| 2 |
from inline_snapshot import snapshot |
| 3 |
|
| 4 |
from docs_src.path_operation_configuration.tutorial002b_py310 import app |
| 5 |
|
| 6 |
client = TestClient(app) |
| 7 |
|
| 8 |
|
| 9 |
def test_get_items(): |
| 10 |
response = client.get("/items/") |
| 11 |
assert response.status_code == 200, response.text |
| 12 |
assert response.json() == ["Portal gun", "Plumbus"] |
| 13 |
|
| 14 |
|
| 15 |
def test_get_users(): |
| 16 |
response = client.get("/users/") |
| 17 |
assert response.status_code == 200, response.text |
| 18 |
assert response.json() == ["Rick", "Morty"] |
| 19 |
|
| 20 |
|
| 21 |
def test_openapi_schema(): |
| 22 |
response = client.get("/openapi.json") |
| 23 |
assert response.status_code == 200, response.text |
| 24 |
assert response.json() == snapshot( |
| 25 |
{ |
| 26 |
"openapi": "3.1.0", |
| 27 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 28 |
"paths": { |
| 29 |
"/items/": { |
| 30 |
"get": { |
| 31 |
"tags": ["items"], |
| 32 |
"summary": "Get Items", |
| 33 |
"operationId": "get_items_items__get", |
| 34 |
"responses": { |
| 35 |
"200": { |
| 36 |
"description": "Successful Response", |
| 37 |
"content": {"application/json": {"schema": {}}}, |
| 38 |
} |
| 39 |
}, |
| 40 |
} |
| 41 |
}, |
| 42 |
"/users/": { |
| 43 |
"get": { |
| 44 |
"tags": ["users"], |
| 45 |
"summary": "Read Users", |
| 46 |
"operationId": "read_users_users__get", |
| 47 |
"responses": { |
| 48 |
"200": { |
| 49 |
"description": "Successful Response", |
| 50 |
"content": {"application/json": {"schema": {}}}, |
| 51 |
} |
| 52 |
}, |
| 53 |
} |
| 54 |
}, |
| 55 |
}, |
| 56 |
} |
| 57 |
) |