mirror of
https://github.com/rjNemo/fastapi
synced 2026-06-06 10:36:39 +00:00
* ✨ Re-export main features used from Starlette to simplify developer's code * ♻️ Refactor Starlette exports * ♻️ Refactor tutorial examples to use re-exported utils from Starlette * 📝 Add examples for all middlewares * 📝 Add new docs for middlewares * 📝 Add examples for custom responses * 📝 Extend docs for custom responses * 📝 Update docs and add notes explaining re-exports from Starlette everywhere * 🍱 Update screenshot for HTTP status * 🔧 Update MkDocs config with new content * ♻️ Refactor tests to use re-exported utils from Starlette * ✨ Re-export WebSocketDisconnect from Starlette for tests * ✅ Add extra tests for extra re-exported middleware * ✅ Add tests for re-exported responses from Starlette * ✨ Add docs about mounting WSGI apps * ➕ Add Flask as a dependency to test WSGIMiddleware * ✅ Test WSGIMiddleware example
34 lines
1,016 B
Python
34 lines
1,016 B
Python
from fastapi.testclient import TestClient
|
|
|
|
from events.tutorial002 import app
|
|
|
|
openapi_schema = {
|
|
"openapi": "3.0.2",
|
|
"info": {"title": "FastAPI", "version": "0.1.0"},
|
|
"paths": {
|
|
"/items/": {
|
|
"get": {
|
|
"responses": {
|
|
"200": {
|
|
"description": "Successful Response",
|
|
"content": {"application/json": {"schema": {}}},
|
|
}
|
|
},
|
|
"summary": "Read Items",
|
|
"operationId": "read_items_items__get",
|
|
}
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
def test_events():
|
|
with TestClient(app) as client:
|
|
response = client.get("/openapi.json")
|
|
assert response.status_code == 200
|
|
assert response.json() == openapi_schema
|
|
response = client.get("/items/")
|
|
assert response.status_code == 200
|
|
assert response.json() == [{"name": "Foo"}]
|
|
with open("log.txt") as log:
|
|
assert "Application shutdown" in log.read()
|