Skip to content

Commit

Permalink
Refactored suspend cloud server order
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Ojeda committed Oct 11, 2018
1 parent d7473db commit d989dfd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
27 changes: 11 additions & 16 deletions SoftLayer/managers/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
# can take that ID and create the proper price for us in the location
# in which the order is made
if matching_item['itemCategory']['categoryCode'] != "gpu0":
price_id = None
for price in matching_item['prices']:
if not price['locationGroupId']:
price_id = self.get_item_price_id(core, price, price_id)
price_id = self.get_item_price_id(core, matching_item['prices'])
else:
# GPU items has two generic prices and they are added to the list
# according to the number of gpu items added in the order.
Expand All @@ -374,19 +371,17 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
return prices

@staticmethod
def get_item_price_id(core, price, price_id):
def get_item_price_id(core, prices):
"""get item price id"""
category_code = []
capacity_min = int(price.get('capacityRestrictionMinimum', -1))
capacity_max = int(price.get('capacityRestrictionMaximum', -1))
if capacity_min == -1:
if price['categories'][0]['categoryCode'] not in category_code:
category_code.append(price['categories'][0]['categoryCode'])
price_id = price['id']
elif capacity_min <= int(core) <= capacity_max:
if price['categories'][0]['categoryCode'] not in category_code:
category_code.append(price['categories'][0]['categoryCode'])
price_id = price['id']
price_id = None
for price in prices:
if not price['locationGroupId']:
capacity_min = int(price.get('capacityRestrictionMinimum', -1))
capacity_max = int(price.get('capacityRestrictionMaximum', -1))
if capacity_min == -1:
price_id = price['id']
elif capacity_min <= int(core) <= capacity_max:
price_id = price['id']
return price_id

def get_preset_prices(self, preset):
Expand Down
14 changes: 9 additions & 5 deletions tests/managers/ordering_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,17 +551,21 @@ def test_location_groud_id_empty(self):

def test_get_item_price_id_without_capacity_restriction(self):
category1 = {'categoryCode': 'cat1'}
price1 = {'id': 1234, 'locationGroupId': '', 'categories': [category1]}
category2 = {'categoryCode': 'cat2'}
prices = [{'id': 1234, 'locationGroupId': '', 'categories': [category1]},
{'id': 2222, 'locationGroupId': 509, 'categories': [category2]}]

price_id = self.ordering.get_item_price_id("8", price1, None)
price_id = self.ordering.get_item_price_id("8", prices)

self.assertEqual(1234, price_id)

def test_get_item_price_id_with_capacity_restriction(self):
category1 = {'categoryCode': 'cat1'}
price1 = {'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
"capacityRestrictionMinimum": "1", 'categories': [category1]}
price1 = [{'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
"capacityRestrictionMinimum": "1", 'categories': [category1]},
{'id': 2222, 'locationGroupId': '', "capacityRestrictionMaximum": "56",
"capacityRestrictionMinimum": "36", 'categories': [category1]}]

price_id = self.ordering.get_item_price_id("8", price1, None)
price_id = self.ordering.get_item_price_id("8", price1)

self.assertEqual(1234, price_id)

0 comments on commit d989dfd

Please sign in to comment.