Skip to content

Commit d989dfd

Browse files
author
Fernando Ojeda
committed
Refactored suspend cloud server order
1 parent d7473db commit d989dfd

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

SoftLayer/managers/ordering.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,7 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
357357
# can take that ID and create the proper price for us in the location
358358
# in which the order is made
359359
if matching_item['itemCategory']['categoryCode'] != "gpu0":
360-
price_id = None
361-
for price in matching_item['prices']:
362-
if not price['locationGroupId']:
363-
price_id = self.get_item_price_id(core, price, price_id)
360+
price_id = self.get_item_price_id(core, matching_item['prices'])
364361
else:
365362
# GPU items has two generic prices and they are added to the list
366363
# according to the number of gpu items added in the order.
@@ -374,19 +371,17 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
374371
return prices
375372

376373
@staticmethod
377-
def get_item_price_id(core, price, price_id):
374+
def get_item_price_id(core, prices):
378375
"""get item price id"""
379-
category_code = []
380-
capacity_min = int(price.get('capacityRestrictionMinimum', -1))
381-
capacity_max = int(price.get('capacityRestrictionMaximum', -1))
382-
if capacity_min == -1:
383-
if price['categories'][0]['categoryCode'] not in category_code:
384-
category_code.append(price['categories'][0]['categoryCode'])
385-
price_id = price['id']
386-
elif capacity_min <= int(core) <= capacity_max:
387-
if price['categories'][0]['categoryCode'] not in category_code:
388-
category_code.append(price['categories'][0]['categoryCode'])
389-
price_id = price['id']
376+
price_id = None
377+
for price in prices:
378+
if not price['locationGroupId']:
379+
capacity_min = int(price.get('capacityRestrictionMinimum', -1))
380+
capacity_max = int(price.get('capacityRestrictionMaximum', -1))
381+
if capacity_min == -1:
382+
price_id = price['id']
383+
elif capacity_min <= int(core) <= capacity_max:
384+
price_id = price['id']
390385
return price_id
391386

392387
def get_preset_prices(self, preset):

tests/managers/ordering_tests.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,21 @@ def test_location_groud_id_empty(self):
551551

552552
def test_get_item_price_id_without_capacity_restriction(self):
553553
category1 = {'categoryCode': 'cat1'}
554-
price1 = {'id': 1234, 'locationGroupId': '', 'categories': [category1]}
554+
category2 = {'categoryCode': 'cat2'}
555+
prices = [{'id': 1234, 'locationGroupId': '', 'categories': [category1]},
556+
{'id': 2222, 'locationGroupId': 509, 'categories': [category2]}]
555557

556-
price_id = self.ordering.get_item_price_id("8", price1, None)
558+
price_id = self.ordering.get_item_price_id("8", prices)
557559

558560
self.assertEqual(1234, price_id)
559561

560562
def test_get_item_price_id_with_capacity_restriction(self):
561563
category1 = {'categoryCode': 'cat1'}
562-
price1 = {'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
563-
"capacityRestrictionMinimum": "1", 'categories': [category1]}
564+
price1 = [{'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
565+
"capacityRestrictionMinimum": "1", 'categories': [category1]},
566+
{'id': 2222, 'locationGroupId': '', "capacityRestrictionMaximum": "56",
567+
"capacityRestrictionMinimum": "36", 'categories': [category1]}]
564568

565-
price_id = self.ordering.get_item_price_id("8", price1, None)
569+
price_id = self.ordering.get_item_price_id("8", price1)
566570

567571
self.assertEqual(1234, price_id)

0 commit comments

Comments
 (0)