Skip to content
2 changes: 1 addition & 1 deletion SoftLayer/CLI/order/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
'extras': extras,
'quantity': 1,
'complex_type': complex_type,
'hourly': True if billing == 'hourly' else False}
'hourly': bool(billing == 'hourly')}

if verify:
table = formatting.Table(COLUMNS)
Expand Down
1 change: 0 additions & 1 deletion SoftLayer/CLI/virt/capacity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ def get_command(self, ctx, cmd_name):
@click.group(cls=CapacityCommands, context_settings=CONTEXT)
def cli():
"""Base command for all capacity related concerns"""
pass
3 changes: 2 additions & 1 deletion SoftLayer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

:license: MIT, see LICENSE for more details.
"""
# pylint: disable=w0401,invalid-name
# pylint: disable=r0401,invalid-name,wildcard-import
# NOQA appears to no longer be working. The code might have been upgraded.
from SoftLayer import consts

from SoftLayer.API import * # NOQA
Expand Down
7 changes: 0 additions & 7 deletions SoftLayer/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,27 @@ class TransportError(SoftLayerAPIError):
# XMLRPC Errors
class NotWellFormed(ParseError):
"""Request was not well formed."""
pass


class UnsupportedEncoding(ParseError):
"""Encoding not supported."""
pass


class InvalidCharacter(ParseError):
"""There was an invalid character."""
pass


class SpecViolation(ServerError):
"""There was a spec violation."""
pass


class MethodNotFound(SoftLayerAPIError):
"""Method name not found."""
pass


class InvalidMethodParameters(SoftLayerAPIError):
"""Invalid method paramters."""
pass


class InternalError(ServerError):
"""Internal Server Error."""
pass
1 change: 0 additions & 1 deletion SoftLayer/shell/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

class ShellExit(Exception):
"""Exception raised to quit the shell."""
pass


@click.command()
Expand Down
2 changes: 0 additions & 2 deletions SoftLayer/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ def tearDownClass(cls):

def set_up(self):
"""Aliased from setUp."""
pass

def tear_down(self):
"""Aliased from tearDown."""
pass

def setUp(self): # NOQA
testtools.TestCase.setUp(self)
Expand Down
1 change: 0 additions & 1 deletion SoftLayer/testing/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def do_POST(self):

def log_message(self, fmt, *args):
"""Override log_message."""
pass


def _item_by_key_postfix(dictionary, key_prefix):
Expand Down
21 changes: 18 additions & 3 deletions SoftLayer/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,15 @@ def __call__(self, request):
request.url = resp.url

resp.raise_for_status()
result = json.loads(resp.text)

if resp.text != "":
try:
result = json.loads(resp.text)
except ValueError as json_ex:
raise exceptions.SoftLayerAPIError(resp.status_code, str(json_ex))
else:
raise exceptions.SoftLayerAPIError(resp.status_code, "Empty response.")

request.result = result

if isinstance(result, list):
Expand All @@ -388,8 +396,15 @@ def __call__(self, request):
else:
return result
except requests.HTTPError as ex:
message = json.loads(ex.response.text)['error']
request.url = ex.response.url
try:
message = json.loads(ex.response.text)['error']
request.url = ex.response.url
except ValueError as json_ex:
if ex.response.text == "":
raise exceptions.SoftLayerAPIError(resp.status_code, "Empty response.")
else:
raise exceptions.SoftLayerAPIError(resp.status_code, str(json_ex))

raise exceptions.SoftLayerAPIError(ex.response.status_code, message)
except requests.RequestException as ex:
raise exceptions.TransportError(0, str(ex))
Expand Down
17 changes: 17 additions & 0 deletions tests/CLI/modules/shell_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
SoftLayer.tests.CLI.modules.shell_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:license: MIT, see LICENSE for more details.
"""
from SoftLayer import testing

import mock


class ShellTests(testing.TestCase):
@mock.patch('prompt_toolkit.shortcuts.prompt')
def test_shell_quit(self, prompt):
prompt.return_value = "quit"
result = self.run_command(['shell'])
self.assertEqual(result.exit_code, 0)
40 changes: 37 additions & 3 deletions tests/transport_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,22 +349,56 @@ def test_basic(self, request):
timeout=None)

@mock.patch('SoftLayer.transports.requests.Session.request')
def test_error(self, request):
def test_http_and_json_error(self, request):
# Test JSON Error
e = requests.HTTPError('error')
e.response = mock.MagicMock()
e.response.status_code = 404
e.response.text = '''{
e.response.text = '''
"error": "description",
"code": "Error Code"
}'''
'''
request().raise_for_status.side_effect = e

req = transports.Request()
req.service = 'SoftLayer_Service'
req.method = 'Resource'
self.assertRaises(SoftLayer.SoftLayerAPIError, self.transport, req)

@mock.patch('SoftLayer.transports.requests.Session.request')
def test_http_and_empty_error(self, request):
# Test JSON Error
e = requests.HTTPError('error')
e.response = mock.MagicMock()
e.response.status_code = 404
e.response.text = ''
request().raise_for_status.side_effect = e

req = transports.Request()
req.service = 'SoftLayer_Service'
req.method = 'Resource'
self.assertRaises(SoftLayer.SoftLayerAPIError, self.transport, req)

@mock.patch('SoftLayer.transports.requests.Session.request')
def test_empty_error(self, request):
# Test empty response error.
request().text = ''

req = transports.Request()
req.service = 'SoftLayer_Service'
req.method = 'Resource'
self.assertRaises(SoftLayer.SoftLayerAPIError, self.transport, req)

@mock.patch('SoftLayer.transports.requests.Session.request')
def test_json_error(self, request):
# Test non-json response error.
request().text = 'Not JSON'

req = transports.Request()
req.service = 'SoftLayer_Service'
req.method = 'Resource'
self.assertRaises(SoftLayer.SoftLayerAPIError, self.transport, req)

def test_proxy_without_protocol(self):
req = transports.Request()
req.service = 'SoftLayer_Service'
Expand Down