@@ -119,3 +119,142 @@ def test_delete_not_found(self):
119119 )
120120
121121 self .assertIn ("Unable to delete record" , str (context .exception ))
122+
123+ def test_fetch_with_response_info (self ):
124+ self .holodeck .mock (
125+ Response (200 , '{"sid": "AC123", "name": "Test Account"}' , {"X-Custom-Header" : "test-value" }),
126+ Request (url = "https://api.twilio.com/2010-04-01/Accounts/AC123.json" ),
127+ )
128+ payload , status_code , headers = self .client .api .v2010 .fetch_with_response_info (
129+ method = "GET" , uri = "/Accounts/AC123.json"
130+ )
131+
132+ self .assertEqual (payload ["sid" ], "AC123" )
133+ self .assertEqual (payload ["name" ], "Test Account" )
134+ self .assertEqual (status_code , 200 )
135+ self .assertIn ("X-Custom-Header" , headers )
136+ self .assertEqual (headers ["X-Custom-Header" ], "test-value" )
137+
138+ def test_update_with_response_info (self ):
139+ self .holodeck .mock (
140+ Response (200 , '{"sid": "AC123", "name": "Updated Account"}' , {"X-Update-Header" : "updated" }),
141+ Request (
142+ method = "POST" ,
143+ url = "https://api.twilio.com/2010-04-01/Accounts/AC123.json" ,
144+ ),
145+ )
146+ payload , status_code , headers = self .client .api .v2010 .update_with_response_info (
147+ method = "POST" , uri = "/Accounts/AC123.json" , data = {"name" : "Updated Account" }
148+ )
149+
150+ self .assertEqual (payload ["sid" ], "AC123" )
151+ self .assertEqual (payload ["name" ], "Updated Account" )
152+ self .assertEqual (status_code , 200 )
153+ self .assertIn ("X-Update-Header" , headers )
154+
155+ def test_delete_with_response_info (self ):
156+ self .holodeck .mock (
157+ Response (204 , "" , {"X-Delete-Header" : "deleted" }),
158+ Request (
159+ method = "DELETE" ,
160+ url = "https://api.twilio.com/2010-04-01/Accounts/AC123/Messages/MM123.json" ,
161+ ),
162+ )
163+ success , status_code , headers = self .client .api .v2010 .delete_with_response_info (
164+ method = "DELETE" , uri = "/Accounts/AC123/Messages/MM123.json"
165+ )
166+
167+ self .assertTrue (success )
168+ self .assertEqual (status_code , 204 )
169+ self .assertIn ("X-Delete-Header" , headers )
170+
171+ def test_create_with_response_info (self ):
172+ self .holodeck .mock (
173+ Response (201 , '{"sid": "MM123", "body": "Hello World"}' , {"X-Create-Header" : "created" }),
174+ Request (
175+ method = "POST" ,
176+ url = "https://api.twilio.com/2010-04-01/Accounts/AC123/Messages.json" ,
177+ ),
178+ )
179+ payload , status_code , headers = self .client .api .v2010 .create_with_response_info (
180+ method = "POST" , uri = "/Accounts/AC123/Messages.json" , data = {"body" : "Hello World" }
181+ )
182+
183+ self .assertEqual (payload ["sid" ], "MM123" )
184+ self .assertEqual (payload ["body" ], "Hello World" )
185+ self .assertEqual (status_code , 201 )
186+ self .assertIn ("X-Create-Header" , headers )
187+
188+ def test_page_with_response_info (self ):
189+ self .holodeck .mock (
190+ Response (200 , '{"messages": [], "next_page_uri": null}' , {"X-Page-Header" : "page" }),
191+ Request (url = "https://api.twilio.com/2010-04-01/Accounts/AC123/Messages.json" ),
192+ )
193+ response , status_code , headers = self .client .api .v2010 .page_with_response_info (
194+ method = "GET" , uri = "/Accounts/AC123/Messages.json"
195+ )
196+
197+ self .assertIsNotNone (response )
198+ self .assertEqual (status_code , 200 )
199+ self .assertIn ("X-Page-Header" , headers )
200+
201+ def test_fetch_with_response_info_error (self ):
202+ self .holodeck .mock (
203+ Response (404 , '{"message": "Resource not found"}' ),
204+ Request (url = "https://api.twilio.com/2010-04-01/Accounts/AC456.json" ),
205+ )
206+
207+ with self .assertRaises (Exception ) as context :
208+ self .client .api .v2010 .fetch_with_response_info (
209+ method = "GET" , uri = "/Accounts/AC456.json"
210+ )
211+
212+ self .assertIn ("Unable to fetch record" , str (context .exception ))
213+
214+ def test_update_with_response_info_error (self ):
215+ self .holodeck .mock (
216+ Response (400 , '{"message": "Invalid request"}' ),
217+ Request (
218+ method = "POST" ,
219+ url = "https://api.twilio.com/2010-04-01/Accounts/AC123.json" ,
220+ ),
221+ )
222+
223+ with self .assertRaises (Exception ) as context :
224+ self .client .api .v2010 .update_with_response_info (
225+ method = "POST" , uri = "/Accounts/AC123.json" , data = {"invalid" : "data" }
226+ )
227+
228+ self .assertIn ("Unable to update record" , str (context .exception ))
229+
230+ def test_delete_with_response_info_error (self ):
231+ self .holodeck .mock (
232+ Response (404 , '{"message": "Resource not found"}' ),
233+ Request (
234+ method = "DELETE" ,
235+ url = "https://api.twilio.com/2010-04-01/Accounts/AC123/Messages/MM456.json" ,
236+ ),
237+ )
238+
239+ with self .assertRaises (Exception ) as context :
240+ self .client .api .v2010 .delete_with_response_info (
241+ method = "DELETE" , uri = "/Accounts/AC123/Messages/MM456.json"
242+ )
243+
244+ self .assertIn ("Unable to delete record" , str (context .exception ))
245+
246+ def test_create_with_response_info_error (self ):
247+ self .holodeck .mock (
248+ Response (400 , '{"message": "Invalid request"}' ),
249+ Request (
250+ method = "POST" ,
251+ url = "https://api.twilio.com/2010-04-01/Accounts/AC123/Messages.json" ,
252+ ),
253+ )
254+
255+ with self .assertRaises (Exception ) as context :
256+ self .client .api .v2010 .create_with_response_info (
257+ method = "POST" , uri = "/Accounts/AC123/Messages.json" , data = {"invalid" : "data" }
258+ )
259+
260+ self .assertIn ("Unable to create record" , str (context .exception ))
0 commit comments