diff --git a/SoftLayer/CLI/order/place.py b/SoftLayer/CLI/order/place.py index 6d51ab935..eacfce898 100644 --- a/SoftLayer/CLI/order/place.py +++ b/SoftLayer/CLI/order/place.py @@ -76,7 +76,10 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type, manager = ordering.OrderingManager(env.client) if extras: - extras = json.loads(extras) + try: + extras = json.loads(extras) + except ValueError as err: + raise exceptions.CLIAbort("There was an error when parsing the --extras value: {}".format(err)) args = (package_keyname, location, order_items) kwargs = {'preset_keyname': preset, diff --git a/SoftLayer/CLI/order/place_quote.py b/SoftLayer/CLI/order/place_quote.py index 3f5215c40..c7bbe6265 100644 --- a/SoftLayer/CLI/order/place_quote.py +++ b/SoftLayer/CLI/order/place_quote.py @@ -6,6 +6,7 @@ import click from SoftLayer.CLI import environment +from SoftLayer.CLI import exceptions from SoftLayer.CLI import formatting from SoftLayer.managers import ordering @@ -68,7 +69,10 @@ def cli(env, package_keyname, location, preset, name, send_email, complex_type, manager = ordering.OrderingManager(env.client) if extras: - extras = json.loads(extras) + try: + extras = json.loads(extras) + except ValueError as err: + raise exceptions.CLIAbort("There was an error when parsing the --extras value: {}".format(err)) args = (package_keyname, location, order_items) kwargs = {'preset_keyname': preset, diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py index c35d6d380..854690ac6 100644 --- a/tests/CLI/modules/order_tests.py +++ b/tests/CLI/modules/order_tests.py @@ -5,6 +5,7 @@ """ import json +from SoftLayer.CLI import exceptions from SoftLayer import testing @@ -103,6 +104,13 @@ def test_place(self): 'status': 'APPROVED'}, json.loads(result.output)) + def test_place_extras_parameter_fail(self): + result = self.run_command(['-y', 'order', 'place', 'package', 'DALLAS13', 'ITEM1', + '--extras', '{"device":[']) + + self.assertEqual(result.exit_code, 2) + self.assertIsInstance(result.exception, exceptions.CLIAbort) + def test_place_quote(self): order_date = '2018-04-04 07:39:20' expiration_date = '2018-05-04 07:39:20' @@ -132,6 +140,13 @@ def test_place_quote(self): 'status': 'PENDING'}, json.loads(result.output)) + def test_place_quote_extras_parameter_fail(self): + result = self.run_command(['-y', 'order', 'place-quote', 'package', 'DALLAS13', 'ITEM1', + '--extras', '{"device":[']) + + self.assertEqual(result.exit_code, 2) + self.assertIsInstance(result.exception, exceptions.CLIAbort) + def test_verify_hourly(self): order_date = '2017-04-04 07:39:20' order = {'orderId': 1234, 'orderDate': order_date,