@@ -349,22 +349,56 @@ def test_basic(self, request):
349349 timeout = None )
350350
351351 @mock .patch ('SoftLayer.transports.requests.Session.request' )
352- def test_error (self , request ):
352+ def test_http_and_json_error (self , request ):
353353 # Test JSON Error
354354 e = requests .HTTPError ('error' )
355355 e .response = mock .MagicMock ()
356356 e .response .status_code = 404
357- e .response .text = '''{
357+ e .response .text = '''
358358 "error": "description",
359359 "code": "Error Code"
360- }'''
360+ '''
361+ request ().raise_for_status .side_effect = e
362+
363+ req = transports .Request ()
364+ req .service = 'SoftLayer_Service'
365+ req .method = 'Resource'
366+ self .assertRaises (SoftLayer .SoftLayerAPIError , self .transport , req )
367+
368+ @mock .patch ('SoftLayer.transports.requests.Session.request' )
369+ def test_http_and_empty_error (self , request ):
370+ # Test JSON Error
371+ e = requests .HTTPError ('error' )
372+ e .response = mock .MagicMock ()
373+ e .response .status_code = 404
374+ e .response .text = ''
361375 request ().raise_for_status .side_effect = e
362376
363377 req = transports .Request ()
364378 req .service = 'SoftLayer_Service'
365379 req .method = 'Resource'
366380 self .assertRaises (SoftLayer .SoftLayerAPIError , self .transport , req )
367381
382+ @mock .patch ('SoftLayer.transports.requests.Session.request' )
383+ def test_empty_error (self , request ):
384+ # Test empty response error.
385+ request ().text = ''
386+
387+ req = transports .Request ()
388+ req .service = 'SoftLayer_Service'
389+ req .method = 'Resource'
390+ self .assertRaises (SoftLayer .SoftLayerAPIError , self .transport , req )
391+
392+ @mock .patch ('SoftLayer.transports.requests.Session.request' )
393+ def test_json_error (self , request ):
394+ # Test non-json response error.
395+ request ().text = 'Not JSON'
396+
397+ req = transports .Request ()
398+ req .service = 'SoftLayer_Service'
399+ req .method = 'Resource'
400+ self .assertRaises (SoftLayer .SoftLayerAPIError , self .transport , req )
401+
368402 def test_proxy_without_protocol (self ):
369403 req = transports .Request ()
370404 req .service = 'SoftLayer_Service'
0 commit comments