Skip to content

Commit 9d98b3e

Browse files
Merge pull request #1428 from softlayer/issues1425
Checking for TermLength on prices
2 parents ffdca18 + 3b6aae8 commit 9d98b3e

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

SoftLayer/managers/ordering.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,16 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
406406
return prices
407407

408408
@staticmethod
409-
def get_item_price_id(core, prices):
410-
"""get item price id"""
409+
def get_item_price_id(core, prices, term=0):
410+
"""get item price id
411+
412+
core: None or a number to match against capacityRestrictionType
413+
prices: list of SoftLayer_Product_Item_Price
414+
term: int to match against SoftLayer_Product_Item_Price.termLength
415+
"""
411416
price_id = None
412417
for price in prices:
413-
if not price['locationGroupId']:
418+
if not price['locationGroupId'] and price.get('termLength', 0) in {term, '', None}:
414419
restriction = price.get('capacityRestrictionType', False)
415420
# There is a price restriction. Make sure the price is within the restriction
416421
if restriction and core is not None:

tests/managers/ordering_tests.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,45 @@ def test_resolve_location_name_invalid(self):
841841
def test_resolve_location_name_not_exist(self):
842842
exc = self.assertRaises(exceptions.SoftLayerError, self.ordering.resolve_location_name, "UNKNOWN_LOCATION_TEST")
843843
self.assertIn("does not exist", str(exc))
844+
845+
# https://github.com/softlayer/softlayer-python/issues/1425
846+
# Issues relating to checking prices based of the price.term relationship
847+
def test_issues1425_zeroterm(self):
848+
category1 = {'categoryCode': 'cat1'}
849+
price1 = {'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
850+
"capacityRestrictionMinimum": "1", "capacityRestrictionType": "STORAGE_SPACE",
851+
'categories': [category1], 'termLength': 36}
852+
price2 = {'id': 45678, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
853+
"capacityRestrictionMinimum": "1", "capacityRestrictionType": "STORAGE_SPACE",
854+
'categories': [category1], 'termLength': 0}
855+
856+
# Test 0 termLength
857+
price_id = self.ordering.get_item_price_id("8", [price2, price1])
858+
self.assertEqual(45678, price_id)
859+
860+
# Test None termLength
861+
price2['termLength'] = None
862+
price_id = self.ordering.get_item_price_id("8", [price2, price1])
863+
self.assertEqual(45678, price_id)
864+
865+
# Test '' termLength
866+
price2['termLength'] = ''
867+
price_id = self.ordering.get_item_price_id("8", [price2, price1])
868+
self.assertEqual(45678, price_id)
869+
870+
def test_issues1425_nonzeroterm(self):
871+
category1 = {'categoryCode': 'cat1'}
872+
price1 = {'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
873+
"capacityRestrictionMinimum": "1", "capacityRestrictionType": "STORAGE_SPACE",
874+
'categories': [category1], 'termLength': 36}
875+
price2 = {'id': 45678, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
876+
"capacityRestrictionMinimum": "1", "capacityRestrictionType": "STORAGE_SPACE",
877+
'categories': [category1], 'termLength': 0}
878+
879+
# Test 36 termLength
880+
price_id = self.ordering.get_item_price_id("8", [price2, price1], 36)
881+
self.assertEqual(1234, price_id)
882+
883+
# Test None-existing price for term
884+
price_id = self.ordering.get_item_price_id("8", [price2, price1], 37)
885+
self.assertEqual(None, price_id)

0 commit comments

Comments
 (0)