mirror of
https://github.com/fastapi/fastapi.git
synced 2026-09-08 11:35:12 -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
@@ -14,41 +14,6 @@ def read_current_user(credentials: HTTPAuthorizationCredentials = Security(secur
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
openapi_schema = {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/users/me": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
"summary": "Read Current User",
|
||||
"operationId": "read_current_user_users_me_get",
|
||||
"security": [{"HTTPDigest": []}],
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"securitySchemes": {
|
||||
"HTTPDigest": {
|
||||
"type": "http",
|
||||
"scheme": "digest",
|
||||
"description": "HTTPDigest scheme",
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_openapi_schema():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == openapi_schema
|
||||
|
||||
|
||||
def test_security_http_digest():
|
||||
response = client.get("/users/me", headers={"Authorization": "Digest foobar"})
|
||||
@@ -68,3 +33,36 @@ def test_security_http_digest_incorrect_scheme_credentials():
|
||||
)
|
||||
assert response.status_code == 403, response.text
|
||||
assert response.json() == {"detail": "Invalid authentication credentials"}
|
||||
|
||||
|
||||
def test_openapi_schema():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/users/me": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
"summary": "Read Current User",
|
||||
"operationId": "read_current_user_users_me_get",
|
||||
"security": [{"HTTPDigest": []}],
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"securitySchemes": {
|
||||
"HTTPDigest": {
|
||||
"type": "http",
|
||||
"scheme": "digest",
|
||||
"description": "HTTPDigest scheme",
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user