@@ -222,6 +222,65 @@ def test_put_for_object_with_valid_data(self, mock_request):
222
222
223
223
self .assertEqual (expected , response )
224
224
225
+ @requests_mock .Mocker ()
226
+ def test_patch (self , mock_request ):
227
+ url = "http://www.my-site.com/users/{user-id}"
228
+ path_params = {'user-id' : 123 }
229
+ full_url = "http://www.my-site.com/users/123"
230
+ user = {'name' : 'Peter' , 'email' : 'peter@my-site.com' }
231
+ text = json .dumps ({'data' : {'id' : 123 , 'name' : 'Peter' , 'email' : 'peter@my-site.com' }})
232
+
233
+ with self .app .app_context ():
234
+ mock_request .patch (full_url , text = text , status_code = 200 )
235
+ response = self .request .patch (url , path_params , json = user )
236
+
237
+ self .assertEqual (200 , response .status_code )
238
+ self .assertEqual (text , response .text )
239
+
240
+ @requests_mock .Mocker ()
241
+ def test_patch_for_object_without_json (self , mock_request ):
242
+ url = "http://www.my-site.com/users/{user-id}"
243
+ path_params = {'user-id' : 123 }
244
+ full_url = "http://www.my-site.com/users/123"
245
+ user = {'name' : 'Peter' , 'email' : 'peter@my-site.com' }
246
+ expected = {}
247
+
248
+ with self .app .app_context ():
249
+ mock_request .patch (full_url , status_code = 200 )
250
+ response = self .request .patch_for_object (url , path_params , json = user )
251
+
252
+ self .assertEqual (expected , response )
253
+
254
+ @requests_mock .Mocker ()
255
+ def test_patch_for_object_without_valid_json_data (self , mock_request ):
256
+ url = "http://www.my-site.com/users/{user-id}"
257
+ path_params = {'user-id' : 123 }
258
+ full_url = "http://www.my-site.com/users/123"
259
+ user = {'name' : 'Peter' , 'email' : 'peter@my-site.com' }
260
+ text = json .dumps ({'another_data' : {'id' : 123 , 'name' : 'Peter' , 'email' : 'peter@my-site.com.com' }})
261
+ expected = {}
262
+
263
+ with self .app .app_context ():
264
+ mock_request .patch (full_url , text = text , status_code = 200 )
265
+ response = self .request .patch_for_object (url , path_params , json = user )
266
+
267
+ self .assertEqual (expected , response )
268
+
269
+ @requests_mock .Mocker ()
270
+ def test_patch_for_object_with_valid_data (self , mock_request ):
271
+ url = "http://www.my-site.com/users/{user-id}"
272
+ path_params = {'user-id' : 123 }
273
+ full_url = "http://www.my-site.com/users/123"
274
+ user = {'name' : 'Peter' , 'email' : 'peter@my-site.com' }
275
+ text = json .dumps ({'data' : {'id' : 123 , 'name' : 'Peter' , 'email' : 'peter@my-site.com.com' }})
276
+ expected = {'id' : 123 , 'name' : 'Peter' , 'email' : 'peter@my-site.com.com' }
277
+
278
+ with self .app .app_context ():
279
+ mock_request .patch (full_url , text = text , status_code = 200 )
280
+ response = self .request .patch_for_object (url , path_params , json = user )
281
+
282
+ self .assertEqual (expected , response )
283
+
225
284
@requests_mock .Mocker ()
226
285
def test_delete (self , mock_request ):
227
286
url = "http://www.my-site.com/users/{user-id}"
0 commit comments