Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions SoftLayer/CLI/order/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
@click.option('--verify',
is_flag=True,
help="Flag denoting whether or not to only verify the order, not place it")
@click.option('--quantity',
type=int,
default=1,
help="The quantity of the item being ordered")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a default of 1 here, so users just ordering 1 item don't have to specify that option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@click.option('--billing',
type=click.Choice(['hourly', 'monthly']),
default='hourly',
Expand All @@ -35,7 +39,7 @@
@click.argument('order_items', nargs=-1)
@environment.pass_env
def cli(env, package_keyname, location, preset, verify, billing, complex_type,
extras, order_items):
quantity, extras, order_items):
"""Place or verify an order.

This CLI command is used for placing/verifying an order of the specified package in
Expand Down Expand Up @@ -84,7 +88,7 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
args = (package_keyname, location, order_items)
kwargs = {'preset_keyname': preset,
'extras': extras,
'quantity': 1,
'quantity': quantity,
'complex_type': complex_type,
'hourly': bool(billing == 'hourly')}

Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/managers/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ def generate_order(self, package_keyname, location, item_keynames, complex_type=
# 'domain': 'softlayer.com'}]}
order.update(extras)
order['packageId'] = package['id']
order['location'] = self.get_location_id(location)
order['quantity'] = quantity
order['location'] = self.get_location_id(location)
order['useHourlyPricing'] = hourly

preset_core = None
Expand Down
21 changes: 21 additions & 0 deletions tests/CLI/modules/order_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ def test_place(self):
'status': 'APPROVED'},
json.loads(result.output))

def test_place_with_quantity(self):
order_date = '2017-04-04 07:39:20'
order = {'orderId': 1234, 'orderDate': order_date, 'placedOrder': {'status': 'APPROVED'}}
verify_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder')
place_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
items_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')

verify_mock.return_value = self._get_verified_order_return()
place_mock.return_value = order
items_mock.return_value = self._get_order_items()

result = self.run_command(['-y', 'order', 'place', '--quantity=2', 'package', 'DALLAS13', 'ITEM1',
'--complex-type', 'SoftLayer_Container_Product_Order_Thing'])

self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
self.assertEqual({'id': 1234,
'created': order_date,
'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":['])
Expand Down
57 changes: 57 additions & 0 deletions tests/managers/ordering_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,36 @@ def test_generate_order_with_preset(self):
mock_get_ids.assert_called_once_with(pkg, items, 8)
self.assertEqual(expected_order, order)

def test_generate_order_with_quantity(self):
pkg = 'PACKAGE_KEYNAME'
quantity = 2
items = ['ITEM1', 'ITEM2']
extras = {"hardware": [{"hostname": "test01", "domain": "example.com"},
{"hostname": "test02", "domain": "example.com"}]}
complex_type = 'My_Type'
expected_order = {'orderContainers': [
{'complexType': 'My_Type',
'hardware': [{'domain': 'example.com',
'hostname': 'test01'},
{'domain': 'example.com',
'hostname': 'test02'}],
'location': 1854895,
'packageId': 1234,
'prices': [{'id': 1111}, {'id': 2222}],
'quantity': 2,
'useHourlyPricing': True}
]}

mock_pkg, mock_preset, mock_get_ids = self._patch_for_generate()

order = self.ordering.generate_order(pkg, 'DALLAS13', items, complex_type=complex_type, quantity=quantity,
extras=extras)

mock_pkg.assert_called_once_with(pkg, mask='id')
mock_preset.assert_not_called()
mock_get_ids.assert_called_once_with(pkg, items, None)
self.assertEqual(expected_order, order)

def test_generate_order(self):
pkg = 'PACKAGE_KEYNAME'
items = ['ITEM1', 'ITEM2']
Expand Down Expand Up @@ -444,6 +474,33 @@ def test_place_order(self):
extras=extras, quantity=quantity)
self.assertEqual(ord_mock.return_value, order)

def test_place_order_with_quantity(self):
ord_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
ord_mock.return_value = {'id': 1234}
pkg = 'PACKAGE_KEYNAME'
location = 'DALLAS13'
items = ['ITEM1', 'ITEM2']
hourly = True
preset_keyname = 'PRESET'
complex_type = 'Complex_Type'
extras = {"hardware": [{"hostname": "test01", "domain": "example.com"},
{"hostname": "test02", "domain": "example.com"}]}
quantity = 2

with mock.patch.object(self.ordering, 'generate_order') as gen_mock:
gen_mock.return_value = {'order': {}}

order = self.ordering.place_order(pkg, location, items, hourly=hourly,
preset_keyname=preset_keyname,
complex_type=complex_type,
extras=extras, quantity=quantity)

gen_mock.assert_called_once_with(pkg, location, items, hourly=hourly,
preset_keyname=preset_keyname,
complex_type=complex_type,
extras=extras, quantity=quantity)
self.assertEqual(ord_mock.return_value, order)

def test_place_quote(self):
ord_mock = self.set_mock('SoftLayer_Product_Order', 'placeQuote')
ord_mock.return_value = {'id': 1234}
Expand Down