Browse Source

Update tests and URL paths

pull/14168/head
Sebastián Ramírez 10 months ago
parent
commit
fc5932ec58
  1. 160
      tests/test_pydantic_v1_v2_01.py

160
tests/test_pydantic_v1_v2_01.py

@ -21,13 +21,13 @@ class Item(BaseModel):
app = FastAPI() app = FastAPI()
@app.post("/old-simple-model") @app.post("/simple-model")
def handle_old_models(data: SubItem) -> SubItem: def handle_simple_model(data: SubItem) -> SubItem:
return data return data
@app.post("/old-simple-model-filter", response_model=SubItem) @app.post("/simple-model-filter", response_model=SubItem)
def handle_old_models_filter(data: SubItem) -> Any: def handle_simple_model_filter(data: SubItem) -> Any:
extended_data = data.dict() extended_data = data.dict()
extended_data.update({"secret_price": 42}) extended_data.update({"secret_price": 42})
return extended_data return extended_data
@ -51,7 +51,7 @@ client = TestClient(app)
def test_old_simple_model(): def test_old_simple_model():
response = client.post( response = client.post(
"/old-simple-model", "/simple-model",
json={"name": "Foo"}, json={"name": "Foo"},
) )
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
@ -60,7 +60,7 @@ def test_old_simple_model():
def test_old_simple_model_validation_error(): def test_old_simple_model_validation_error():
response = client.post( response = client.post(
"/old-simple-model", "/simple-model",
json={"wrong_name": "Foo"}, json={"wrong_name": "Foo"},
) )
assert response.status_code == 422, response.text assert response.status_code == 422, response.text
@ -79,7 +79,7 @@ def test_old_simple_model_validation_error():
def test_old_simple_model_filter(): def test_old_simple_model_filter():
response = client.post( response = client.post(
"/old-simple-model-filter", "/simple-model-filter",
json={"name": "Foo"}, json={"name": "Foo"},
) )
assert response.status_code == 200, response.text assert response.status_code == 200, response.text
@ -217,89 +217,75 @@ def test_openapi_schema():
{ {
"openapi": "3.1.0", "openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"}, "info": {"title": "FastAPI", "version": "0.1.0"},
"paths": { "paths": {"/simple-model": {
"/old-simple-model": { "post": {
"post": { "summary": "Handle Simple Model",
"summary": "Handle Old Models", "operationId": "handle_simple_model_simple_model_post",
"operationId": "handle_old_models_old_simple_model_post", "requestBody": {
"requestBody": { "content": {
"content": { "application/json": {
"application/json": { "schema": {
"schema": { "allOf": [{"$ref": "#/components/schemas/SubItem"}],
"allOf": [ "title": "Data",
{"$ref": "#/components/schemas/SubItem"} }
], }
"title": "Data", },
} "required": True,
} },
}, "responses": {
"required": True, "200": {
}, "description": "Successful Response",
"responses": { "content": {
"200": { "application/json": {
"description": "Successful Response", "schema": {"$ref": "#/components/schemas/SubItem"}
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SubItem"
}
}
},
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
} }
}, },
"/old-simple-model-filter": { },
"post": { "422": {
"summary": "Handle Old Models Filter", "description": "Validation Error",
"operationId": "handle_old_models_filter_old_simple_model_filter_post", "content": {
"requestBody": { "application/json": {
"content": { "schema": {"$ref": "#/components/schemas/HTTPValidationError"}
"application/json": { }
"schema": { },
"allOf": [ },
{"$ref": "#/components/schemas/SubItem"} },
], }
"title": "Data", }, "/simple-model-filter": {
} "post": {
} "summary": "Handle Simple Model Filter",
}, "operationId": "handle_simple_model_filter_simple_model_filter_post",
"required": True, "requestBody": {
}, "content": {
"responses": { "application/json": {
"200": { "schema": {
"description": "Successful Response", "allOf": [{"$ref": "#/components/schemas/SubItem"}],
"content": { "title": "Data",
"application/json": { }
"schema": { }
"$ref": "#/components/schemas/SubItem" },
} "required": True,
} },
}, "responses": {
}, "200": {
"422": { "description": "Successful Response",
"description": "Validation Error", "content": {
"content": { "application/json": {
"application/json": { "schema": {"$ref": "#/components/schemas/SubItem"}
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
},
},
} }
}, "/item": { },
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/HTTPValidationError"}
}
},
},
},
}
}, "/item": {
"post": { "post": {
"summary": "Handle Item", "summary": "Handle Item",
"operationId": "handle_item_item_post", "operationId": "handle_item_item_post",

Loading…
Cancel
Save