Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit44c849c

Browse files
authored
🔥 Remove Pydantic v1 specific test variants (#14611)
1 parent8322a44 commit44c849c

File tree

104 files changed

+4073
-8008
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+4073
-8008
lines changed

‎tests/test_additional_properties_bool.py‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
fromtypingimportUnion
22

3-
fromdirty_equalsimportIsDict
43
fromfastapiimportFastAPI
54
fromfastapi.testclientimportTestClient
65
frompydanticimportBaseModel,ConfigDict
@@ -52,19 +51,13 @@ def test_openapi_schema():
5251
"requestBody": {
5352
"content": {
5453
"application/json": {
55-
"schema":IsDict(
56-
{
57-
"anyOf": [
58-
{"$ref":"#/components/schemas/Foo"},
59-
{"type":"null"},
60-
],
61-
"title":"Foo",
62-
}
63-
)
64-
|IsDict(
65-
# TODO: remove when deprecating Pydantic v1
66-
{"$ref":"#/components/schemas/Foo"}
67-
)
54+
"schema": {
55+
"anyOf": [
56+
{"$ref":"#/components/schemas/Foo"},
57+
{"type":"null"},
58+
],
59+
"title":"Foo",
60+
}
6861
}
6962
}
7063
},
Lines changed: 93 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
fromdirty_equalsimportIsDict
21
fromfastapiimportAPIRouter,FastAPI
32
fromfastapi.testclientimportTestClient
3+
frominline_snapshotimportsnapshot
44
frompydanticimportBaseModel,HttpUrl
55
fromstarlette.responsesimportJSONResponse
66

@@ -32,121 +32,114 @@ def main_route(callback_url: HttpUrl):
3232
deftest_openapi_schema():
3333
response=client.get("/openapi.json")
3434
assertresponse.status_code==200,response.text
35-
assertresponse.json()== {
36-
"openapi":"3.1.0",
37-
"info": {"title":"FastAPI","version":"0.1.0"},
38-
"paths": {
39-
"/": {
40-
"post": {
41-
"summary":"Main Route",
42-
"operationId":"main_route__post",
43-
"parameters": [
44-
{
45-
"required":True,
46-
"schema":IsDict(
47-
{
48-
"title":"Callback Url",
49-
"minLength":1,
50-
"type":"string",
51-
"format":"uri",
52-
}
53-
)
54-
# TODO: remove when deprecating Pydantic v1
55-
|IsDict(
56-
{
35+
assertresponse.json()==snapshot(
36+
{
37+
"openapi":"3.1.0",
38+
"info": {"title":"FastAPI","version":"0.1.0"},
39+
"paths": {
40+
"/": {
41+
"post": {
42+
"summary":"Main Route",
43+
"operationId":"main_route__post",
44+
"parameters": [
45+
{
46+
"required":True,
47+
"schema": {
5748
"title":"Callback Url",
5849
"maxLength":2083,
5950
"minLength":1,
6051
"type":"string",
6152
"format":"uri",
62-
}
63-
),
64-
"name":"callback_url",
65-
"in":"query",
66-
}
67-
],
68-
"responses": {
69-
"200":{
70-
"description":"Successful Response",
71-
"content": {"application/json": {"schema": {}}},
72-
},
73-
"422":{
74-
"description":"Validation Error",
75-
"content": {
76-
"application/json": {
77-
"schema":{
78-
"$ref":"#/components/schemas/HTTPValidationError"
53+
},
54+
"name":"callback_url",
55+
"in":"query",
56+
}
57+
],
58+
"responses": {
59+
"200": {
60+
"description":"Successful Response",
61+
"content":{"application/json": {"schema": {}}},
62+
},
63+
"422": {
64+
"description":"Validation Error",
65+
"content":{
66+
"application/json": {
67+
"schema": {
68+
"$ref":"#/components/schemas/HTTPValidationError"
69+
}
7970
}
80-
}
71+
},
8172
},
8273
},
83-
},
84-
"callbacks": {
85-
"callback_route": {
86-
"{$callback_url}/callback/": {
87-
"get":{
88-
"summary":"Callback Route",
89-
"operationId":"callback_route__callback_url__callback__get",
90-
"responses": {
91-
"400": {
92-
"content": {
93-
"application/json": {
94-
"schema":{
95-
"$ref":"#/components/schemas/CustomModel"
74+
"callbacks": {
75+
"callback_route": {
76+
"{$callback_url}/callback/": {
77+
"get": {
78+
"summary":"Callback Route",
79+
"operationId":"callback_route__callback_url__callback__get",
80+
"responses":{
81+
"400": {
82+
"content": {
83+
"application/json": {
84+
"schema": {
85+
"$ref":"#/components/schemas/CustomModel"
86+
}
9687
}
97-
}
88+
},
89+
"description":"Bad Request",
9890
},
99-
"description":"Bad Request",
100-
},
101-
"200": {
102-
"description":"Successful Response",
103-
"content": {
104-
"application/json": {"schema": {}}
91+
"200": {
92+
"description":"Successful Response",
93+
"content": {
94+
"application/json": {"schema": {}}
95+
},
10596
},
10697
},
107-
},
98+
}
10899
}
109100
}
110-
}
111-
},
101+
},
102+
}
112103
}
113-
}
114-
},
115-
"components": {
116-
"schemas": {
117-
"CustomModel": {
118-
"title":"CustomModel",
119-
"required": ["a"],
120-
"type":"object",
121-
"properties": {"a": {"title":"A","type":"integer"}},
122-
},
123-
"HTTPValidationError": {
124-
"title":"HTTPValidationError",
125-
"type":"object",
126-
"properties": {
127-
"detail": {
128-
"title":"Detail",
129-
"type":"array",
130-
"items": {"$ref":"#/components/schemas/ValidationError"},
131-
}
104+
},
105+
"components": {
106+
"schemas": {
107+
"CustomModel": {
108+
"title":"CustomModel",
109+
"required": ["a"],
110+
"type":"object",
111+
"properties": {"a": {"title":"A","type":"integer"}},
132112
},
133-
},
134-
"ValidationError": {
135-
"title":"ValidationError",
136-
"required": ["loc","msg","type"],
137-
"type":"object",
138-
"properties": {
139-
"loc": {
140-
"title":"Location",
141-
"type":"array",
142-
"items": {
143-
"anyOf": [{"type":"string"}, {"type":"integer"}]
113+
"HTTPValidationError": {
114+
"title":"HTTPValidationError",
115+
"type":"object",
116+
"properties": {
117+
"detail": {
118+
"title":"Detail",
119+
"type":"array",
120+
"items": {
121+
"$ref":"#/components/schemas/ValidationError"
122+
},
123+
}
124+
},
125+
},
126+
"ValidationError": {
127+
"title":"ValidationError",
128+
"required": ["loc","msg","type"],
129+
"type":"object",
130+
"properties": {
131+
"loc": {
132+
"title":"Location",
133+
"type":"array",
134+
"items": {
135+
"anyOf": [{"type":"string"}, {"type":"integer"}]
136+
},
144137
},
138+
"msg": {"title":"Message","type":"string"},
139+
"type": {"title":"Error Type","type":"string"},
145140
},
146-
"msg": {"title":"Message","type":"string"},
147-
"type": {"title":"Error Type","type":"string"},
148141
},
149-
},
150-
}
151-
},
152-
}
142+
}
143+
},
144+
}
145+
)

‎tests/test_annotated.py‎

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fromtypingimportAnnotated
22

33
importpytest
4-
fromdirty_equalsimportIsDict
54
fromfastapiimportAPIRouter,FastAPI,Query
65
fromfastapi.testclientimportTestClient
76

@@ -32,44 +31,23 @@ async def unrelated(foo: Annotated[str, object()]):
3231

3332
foo_is_missing= {
3433
"detail": [
35-
IsDict(
36-
{
37-
"loc": ["query","foo"],
38-
"msg":"Field required",
39-
"type":"missing",
40-
"input":None,
41-
}
42-
)
43-
# TODO: remove when deprecating Pydantic v1
44-
|IsDict(
45-
{
46-
"loc": ["query","foo"],
47-
"msg":"field required",
48-
"type":"value_error.missing",
49-
}
50-
)
34+
{
35+
"loc": ["query","foo"],
36+
"msg":"Field required",
37+
"type":"missing",
38+
"input":None,
39+
}
5140
]
5241
}
5342
foo_is_short= {
5443
"detail": [
55-
IsDict(
56-
{
57-
"ctx": {"min_length":1},
58-
"loc": ["query","foo"],
59-
"msg":"String should have at least 1 character",
60-
"type":"string_too_short",
61-
"input":"",
62-
}
63-
)
64-
# TODO: remove when deprecating Pydantic v1
65-
|IsDict(
66-
{
67-
"ctx": {"limit_value":1},
68-
"loc": ["query","foo"],
69-
"msg":"ensure this value has at least 1 characters",
70-
"type":"value_error.any_str.min_length",
71-
}
72-
)
44+
{
45+
"ctx": {"min_length":1},
46+
"loc": ["query","foo"],
47+
"msg":"String should have at least 1 character",
48+
"type":"string_too_short",
49+
"input":"",
50+
}
7351
]
7452
}
7553

‎tests/test_application.py‎

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
importpytest
2-
fromdirty_equalsimportIsDict
32
fromfastapi.testclientimportTestClient
43

54
from .mainimportapp
@@ -274,14 +273,10 @@ def test_openapi_schema():
274273
"name":"item_id",
275274
"in":"path",
276275
"required":True,
277-
"schema":IsDict(
278-
{
279-
"anyOf": [{"type":"string"}, {"type":"null"}],
280-
"title":"Item Id",
281-
}
282-
)
283-
# TODO: remove when deprecating Pydantic v1
284-
|IsDict({"title":"Item Id","type":"string"}),
276+
"schema": {
277+
"anyOf": [{"type":"string"}, {"type":"null"}],
278+
"title":"Item Id",
279+
},
285280
}
286281
],
287282
}
@@ -984,14 +979,10 @@ def test_openapi_schema():
984979
"name":"query",
985980
"in":"query",
986981
"required":False,
987-
"schema":IsDict(
988-
{
989-
"anyOf": [{"type":"integer"}, {"type":"null"}],
990-
"title":"Query",
991-
}
992-
)
993-
# TODO: remove when deprecating Pydantic v1
994-
|IsDict({"title":"Query","type":"integer"}),
982+
"schema": {
983+
"anyOf": [{"type":"integer"}, {"type":"null"}],
984+
"title":"Query",
985+
},
995986
}
996987
],
997988
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp