33from dirty_equals import IsDict
44from fastapi import FastAPI , Form
55from fastapi .testclient import TestClient
6- from pydantic import BaseModel
6+ from pydantic import BaseModel , Field
77from typing_extensions import Annotated
88
99app = FastAPI ()
@@ -14,6 +14,7 @@ class FormModel(BaseModel):
1414 lastname : str
1515 age : Optional [int ] = None
1616 tags : List [str ] = ["foo" , "bar" ]
17+ alias_with : str = Field (alias = "with" , default = "nothing" )
1718
1819
1920@app .post ("/form/" )
@@ -32,6 +33,7 @@ def test_send_all_data():
3233 "lastname" : "Sanchez" ,
3334 "age" : "70" ,
3435 "tags" : ["plumbus" , "citadel" ],
36+ "with" : "something" ,
3537 },
3638 )
3739 assert response .status_code == 200 , response .text
@@ -40,6 +42,7 @@ def test_send_all_data():
4042 "lastname" : "Sanchez" ,
4143 "age" : 70 ,
4244 "tags" : ["plumbus" , "citadel" ],
45+ "with" : "something" ,
4346 }
4447
4548
@@ -51,6 +54,7 @@ def test_defaults():
5154 "lastname" : "Sanchez" ,
5255 "age" : None ,
5356 "tags" : ["foo" , "bar" ],
57+ "with" : "nothing" ,
5458 }
5559
5660
@@ -100,13 +104,13 @@ def test_no_data():
100104 "type" : "missing" ,
101105 "loc" : ["body" , "username" ],
102106 "msg" : "Field required" ,
103- "input" : {"tags" : ["foo" , "bar" ]},
107+ "input" : {"tags" : ["foo" , "bar" ], "with" : "nothing" },
104108 },
105109 {
106110 "type" : "missing" ,
107111 "loc" : ["body" , "lastname" ],
108112 "msg" : "Field required" ,
109- "input" : {"tags" : ["foo" , "bar" ]},
113+ "input" : {"tags" : ["foo" , "bar" ], "with" : "nothing" },
110114 },
111115 ]
112116 }
0 commit comments