1- import json
2-
31import pytest
2+ from pydantic_core import from_json , to_json
43
54
65class TestFalconIntegration :
@@ -10,7 +9,7 @@ def test_get_items_sync(self, sync_client):
109 response = sync_client .simulate_get ("/items-sync" )
1110
1211 assert response .status_code == 200
13- result = json . loads (response .text )
12+ result = from_json (response .text )
1413 assert len (result ) == 2
1514 assert result [0 ]["name" ] == "Item 1"
1615 assert result [1 ]["name" ] == "Item 2"
@@ -21,7 +20,7 @@ async def test_get_items(self, async_client):
2120 response = await async_client .simulate_get ("/items" )
2221
2322 assert response .status_code == 200
24- result = json . loads (response .text )
23+ result = from_json (response .text )
2524 assert len (result ) == 2
2625 assert result [0 ]["name" ] == "Item 1"
2726 assert result [1 ]["name" ] == "Item 2"
@@ -32,7 +31,7 @@ async def test_get_items_fail(self, async_client):
3231 response = await async_client .simulate_get ("/items-fail" )
3332
3433 assert response .status_code == 500
35- result = json . loads (response .text )
34+ result = from_json (response .text )
3635 assert result ["error" ]["message" ] == "TEST ERROR"
3736
3837 @pytest .mark .asyncio
@@ -41,7 +40,7 @@ async def test_get_item(self, async_client):
4140 response = await async_client .simulate_get ("/items/1" )
4241
4342 assert response .status_code == 200
44- result = json . loads (response .text )
43+ result = from_json (response .text )
4544 assert result ["id" ] == 1
4645 assert result ["name" ] == "Item 1"
4746 assert result ["description" ] == "Description 1"
@@ -52,7 +51,7 @@ async def test_get_item_bad_request(self, async_client):
5251 response = await async_client .simulate_get ("/items/abc" )
5352
5453 assert response .status_code == 400
55- result = json . loads (response .text )
54+ result = from_json (response .text )
5655 assert result ["error" ]["message" ] == (
5756 "Error parsing parameter 'item_id'. Must be a valid int"
5857 )
@@ -70,12 +69,12 @@ async def test_create_item(self, async_client):
7069 new_item = {"name" : "New Item" , "description" : "New Description" }
7170 response = await async_client .simulate_post (
7271 "/items" ,
73- body = json . dumps (new_item ),
72+ body = to_json (new_item ). decode ( "utf-8" ),
7473 headers = {"Content-Type" : "application/json" },
7574 )
7675
7776 assert response .status_code == 201
78- result = json . loads (response .text )
77+ result = from_json (response .text )
7978 assert result ["id" ] == 3
8079 assert result ["name" ] == "New Item"
8180 assert result ["description" ] == "New Description"
@@ -86,12 +85,12 @@ async def test_create_item_incorrect(self, async_client):
8685 new_item = {"name" : None , "description" : "New Description" }
8786 response = await async_client .simulate_post (
8887 "/items" ,
89- body = json . dumps (new_item ),
88+ body = to_json (new_item ). decode ( "utf-8" ),
9089 headers = {"Content-Type" : "application/json" },
9190 )
9291
9392 assert response .status_code == 422
94- result = json . loads (response .text )
93+ result = from_json (response .text )
9594 assert "Validation error for parameter" in result ["error" ]["message" ]
9695
9796 @pytest .mark .asyncio
@@ -104,7 +103,7 @@ async def test_create_item_invalid_json(self, async_client):
104103 )
105104
106105 assert response .status_code == 422
107- result = json . loads (response .text )
106+ result = from_json (response .text )
108107 assert "Validation error for parameter" in result ["error" ]["message" ]
109108
110109 @pytest .mark .asyncio
@@ -113,12 +112,12 @@ async def test_update_item(self, async_client):
113112 update_data = {"name" : "Updated Item" , "description" : "Updated Description" }
114113 response = await async_client .simulate_put (
115114 "/items/2" ,
116- body = json . dumps (update_data ),
115+ body = to_json (update_data ). decode ( "utf-8" ),
117116 headers = {"Content-Type" : "application/json" },
118117 )
119118
120119 assert response .status_code == 200
121- result = json . loads (response .text )
120+ result = from_json (response .text )
122121 assert result ["id" ] == 2
123122 assert result ["name" ] == "Updated Item"
124123 assert result ["description" ] == "Updated Description"
@@ -140,7 +139,7 @@ async def test_openapi_schema_endpoint(self, async_client):
140139 response = await async_client .simulate_get ("/openapi.json" )
141140
142141 assert response .status_code == 200
143- schema = json . loads (response .text )
142+ schema = from_json (response .text )
144143 assert schema ["info" ]["title" ] == "Test API"
145144 assert "/items" in schema ["paths" ]
146145 assert "/items/{item_id}" in schema ["paths" ]
@@ -169,15 +168,15 @@ async def test_query_parameters_handling(self, async_client):
169168 # Test with a single value parameter
170169 response = await async_client .get ("/list-test?param1=single_value" )
171170 assert response .status_code == 200
172- data = json . loads (response .text )
171+ data = from_json (response .text )
173172 assert data ["received_param1" ] == "single_value"
174173
175174 # Test with a parameter that has multiple values
176175 response = await async_client .get (
177176 "/list-test?param1=first_value¶m2=value1¶m2=value2"
178177 )
179178 assert response .status_code == 200
180- data = json . loads (response .text )
179+ data = from_json (response .text )
181180 assert data ["received_param1" ] == "first_value"
182181 assert isinstance (data ["received_param2" ], list )
183182 assert data ["received_param2" ] == ["value1" , "value2" ]
0 commit comments