@@ -274,6 +274,25 @@ def test_api_get_endpoint_only(self, mock_request):
274
274
)
275
275
self .assertEqual (response , expected_response )
276
276
277
+ @patch ('requests.request' )
278
+ def test_api_get_with_payload (self , mock_request ):
279
+ '''Test api_get: with payload'''
280
+ mock_response = Mock ()
281
+ expected_response = {'device' : 'info' }
282
+ mock_response .json .return_value = expected_response
283
+ mock_response .status_code = 200
284
+ mock_response .text = 'text'
285
+ mock_request .return_value = mock_response
286
+ # Call with endpoint only
287
+ response = self .fb .api_get ('device' , payload = {'key' : 'value' })
288
+ mock_request .assert_called_once_with (
289
+ method = 'GET' ,
290
+ url = 'https://my.farm.bot/api/device' ,
291
+ ** REQUEST_KWARGS_WITH_PAYLOAD ,
292
+ json = {'key' : 'value' },
293
+ )
294
+ self .assertEqual (response , expected_response )
295
+
277
296
@patch ('requests.request' )
278
297
def test_api_get_with_id (self , mock_request ):
279
298
'''POSITIVE TEST: function called with valid ID'''
@@ -372,6 +391,24 @@ def test_api_post(self, mock_request):
372
391
])
373
392
self .assertEqual (point , {'name' : 'new name' })
374
393
394
+ @patch ('requests.request' )
395
+ def test_api_post_no_payload (self , mock_request ):
396
+ '''test api_post: no payload'''
397
+ mock_response = Mock ()
398
+ mock_response .status_code = 200
399
+ mock_response .text = 'text'
400
+ mock_response .json .return_value = {'name' : 'new name' }
401
+ mock_request .return_value = mock_response
402
+ point = self .fb .api_post ('points' )
403
+ mock_request .assert_has_calls ([call (
404
+ method = 'POST' ,
405
+ url = 'https://my.farm.bot/api/points' ,
406
+ ** REQUEST_KWARGS ,
407
+ ),
408
+ call ().json (),
409
+ ])
410
+ self .assertEqual (point , {'name' : 'new name' })
411
+
375
412
@patch ('requests.request' )
376
413
def test_api_delete (self , mock_request ):
377
414
'''test api_delete function'''
@@ -388,6 +425,24 @@ def test_api_delete(self, mock_request):
388
425
)
389
426
self .assertEqual (result , {'name' : 'deleted' })
390
427
428
+ @patch ('requests.request' )
429
+ def test_api_delete_with_payload (self , mock_request ):
430
+ '''test api_delete: with payload'''
431
+ mock_response = Mock ()
432
+ mock_response .status_code = 200
433
+ mock_response .text = 'text'
434
+ mock_response .json .return_value = {'name' : 'deleted' }
435
+ mock_request .return_value = mock_response
436
+ result = self .fb .api_delete (
437
+ 'points' , 12345 , payload = {'key' : 'value' })
438
+ mock_request .assert_called_once_with (
439
+ method = 'DELETE' ,
440
+ url = 'https://my.farm.bot/api/points/12345' ,
441
+ ** REQUEST_KWARGS_WITH_PAYLOAD ,
442
+ json = {'key' : 'value' },
443
+ )
444
+ self .assertEqual (result , {'name' : 'deleted' })
445
+
391
446
@patch ('requests.request' )
392
447
def test_api_delete_requests_disabled (self , mock_request ):
393
448
'''test api_delete function: requests disabled'''
0 commit comments