mirror of
https://github.com/fastapi/fastapi.git
synced 2026-10-25 03:09:50 -04:00
✅ Refactor OpenAPI tests, prepare for Pydantic v2 (#9503)
* ✅ Refactor OpenAPI tests, move inline, prepare for Pydantic v2 tests * ✅ Fix test module loading for conditional OpenAPI * 🐛 Fix missing pytest marker * ✅ Fix test for coverage
This commit is contained in:
1 parent
724060df43
commit
50c1a928fb
280 files changed
+34572
-33644
No files matched your search
@@ -4,35 +4,6 @@ from fastapi.testclient import TestClient
|
||||
|
||||
from docs_src.conditional_openapi import tutorial001
|
||||
|
||||
openapi_schema = {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"summary": "Root",
|
||||
"operationId": "root__get",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_default_openapi():
|
||||
client = TestClient(tutorial001.app)
|
||||
response = client.get("/openapi.json")
|
||||
assert response.json() == openapi_schema
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
response = client.get("/redoc")
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
|
||||
def test_disable_openapi(monkeypatch):
|
||||
monkeypatch.setenv("OPENAPI_URL", "")
|
||||
@@ -51,3 +22,31 @@ def test_root():
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "Hello World"}
|
||||
|
||||
|
||||
def test_default_openapi():
|
||||
importlib.reload(tutorial001)
|
||||
client = TestClient(tutorial001.app)
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
response = client.get("/redoc")
|
||||
assert response.status_code == 200, response.text
|
||||
response = client.get("/openapi.json")
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"summary": "Root",
|
||||
"operationId": "root__get",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user