Skip to content

Commit ad84d58

Browse files
author
Fernando Ojeda
committed
unit test suspend cloud server
1 parent 192b192 commit ad84d58

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

SoftLayer/managers/ordering.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,9 @@ def get_price_id_list(self, package_keyname, item_keynames, core):
358358
# in which the order is made
359359
if matching_item['itemCategory']['categoryCode'] != "gpu0":
360360
price_id = None
361-
category_code = []
362361
for price in matching_item['prices']:
363362
if not price['locationGroupId']:
364-
price_id = self.save_price_id(category_code, core, price, price_id)
363+
price_id = self.get_item_price_id(core, price, price_id)
365364
else:
366365
# GPU items has two generic prices and they are added to the list
367366
# according to the number of gpu items added in the order.
@@ -375,8 +374,9 @@ def get_price_id_list(self, package_keyname, item_keynames, core):
375374
return prices
376375

377376
@staticmethod
378-
def save_price_id(category_code, core, price, price_id):
379-
"""Save item prices ids"""
377+
def get_item_price_id(core, price, price_id):
378+
"""get item price id"""
379+
category_code = []
380380
if 'capacityRestrictionMinimum' not in price:
381381
if price['categories'][0]['categoryCode'] not in category_code:
382382
category_code.append(price['categories'][0]['categoryCode'])

tests/managers/ordering_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,28 @@ def test_location_groud_id_empty(self):
548548

549549
list_mock.assert_called_once_with('PACKAGE_KEYNAME', mask='id, itemCategory, keyName, prices[categories]')
550550
self.assertEqual([price1['id'], price2['id']], prices)
551+
552+
def test_get_item_price_id_without_capacity_restriction(self):
553+
category1 = {'categoryCode': 'cat1'}
554+
price1 = {'id': 1234, 'locationGroupId': '', 'categories': [category1]}
555+
556+
with mock.patch.object(self.ordering, 'get_item_price_id') as list_mock:
557+
list_mock.return_value = [price1]
558+
559+
prices = self.ordering.get_item_price_id("8", price1)
560+
561+
list_mock.assert_called_once_with("8", price1)
562+
self.assertEqual(1234, prices[0]['id'])
563+
564+
def test_get_item_price_id_with_capacity_restriction(self):
565+
category1 = {'categoryCode': 'cat1'}
566+
price1 = {'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
567+
"capacityRestrictionMinimum": "1", 'categories': [category1]}
568+
569+
with mock.patch.object(self.ordering, 'get_item_price_id') as list_mock:
570+
list_mock.return_value = [price1]
571+
572+
prices = self.ordering.get_item_price_id("8", price1)
573+
574+
list_mock.assert_called_once_with("8", price1)
575+
self.assertEqual(1234, prices[0]['id'])

0 commit comments

Comments
 (0)