Repository: softlayer/softlayer-python
Pull request #1196 (2019-12-11 19:44:38)

Fix quote file storage.
Fix quote file storage https://github.com/softlayer/softlayer-python/issues/1155.


Patch:
diff --git a/SoftLayer/managers/ordering.py b/SoftLayer/managers/ordering.py
index 0cd015e7..cc9a6344 100644
--- a/SoftLayer/managers/ordering.py
+++ b/SoftLayer/managers/ordering.py
@@ -405,7 +405,9 @@ def get_item_price_id(core, prices):
                     price_id = price['id']
                 # this check is mostly to work nicely with preset configs
                 elif capacity_min <= int(core) <= capacity_max:
-                    price_id = price['id']
+                    if "STORAGE" in price.get("capacityRestrictionType") or "CORE" in price.get(
+                            "capacityRestrictionType"):
+                        price_id = price['id']
         return price_id
 
     def get_item_capacity(self, items, item_keynames):
@@ -417,6 +419,9 @@ def get_item_capacity(self, items, item_keynames):
                     if "GUEST_CORE" in item["keyName"]:
                         item_capacity = item['capacity']
                         break
+                    if "TIER" in item["keyName"]:
+                        item_capacity = item['capacity']
+                        break
         return item_capacity
 
     def get_preset_prices(self, preset):


Test patch:
diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py
index a76289ca..35d5b819 100644
--- a/tests/managers/ordering_tests.py
+++ b/tests/managers/ordering_tests.py
@@ -640,12 +640,27 @@ def test_get_item_price_id_without_capacity_restriction(self):
 
         self.assertEqual(1234, price_id)
 
-    def test_get_item_price_id_with_capacity_restriction(self):
+    def test_get_item_price_id_core_with_capacity_restriction(self):
         category1 = {'categoryCode': 'cat1'}
         price1 = [{'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
-                   "capacityRestrictionMinimum": "1", 'categories': [category1]},
+                   "capacityRestrictionMinimum": "1", "capacityRestrictionType": "CORE",
+                   'categories': [category1]},
                   {'id': 2222, 'locationGroupId': '', "capacityRestrictionMaximum": "56",
-                   "capacityRestrictionMinimum": "36", 'categories': [category1]}]
+                   "capacityRestrictionMinimum": "36", "capacityRestrictionType": "CORE",
+                   'categories': [category1]}]
+
+        price_id = self.ordering.get_item_price_id("8", price1)
+
+        self.assertEqual(1234, price_id)
+
+    def test_get_item_price_id_storage_with_capacity_restriction(self):
+        category1 = {'categoryCode': 'cat1'}
+        price1 = [{'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "16",
+                   "capacityRestrictionMinimum": "1", "capacityRestrictionType": "STORAGE_SPACE",
+                   'categories': [category1]},
+                  {'id': 2222, 'locationGroupId': '', "capacityRestrictionMaximum": "56",
+                   "capacityRestrictionMinimum": "36", "capacityRestrictionType": "STORAGE_SPACE",
+                   'categories': [category1]}]
 
         price_id = self.ordering.get_item_price_id("8", price1)
 
@@ -696,7 +711,7 @@ def test_clean_quote_verify(self):
         self.assertNotIn('testProperty', order_container)
         self.assertNotIn('reservedCapacityId', order_container)
 
-    def test_get_item_capacity(self):
+    def test_get_item_capacity_core(self):
 
         items = [{
             "capacity": "1",
@@ -712,3 +727,20 @@ def test_get_item_capacity(self):
         item_capacity = self.ordering.get_item_capacity(items, ['GUEST_CORE_1_DEDICATED', 'OS_RHEL_7_X_LAMP_64_BIT'])
 
         self.assertEqual(1, int(item_capacity))
+
+    def test_get_item_capacity_storage(self):
+
+        items = [{
+            "capacity": "1",
+            "id": 6131,
+            "keyName": "STORAGE_SPACE_FOR_2_IOPS_PER_GB",
+        },
+            {
+                "capacity": "1",
+                "id": 10201,
+                "keyName": "READHEAVY_TIER",
+            }]
+
+        item_capacity = self.ordering.get_item_capacity(items, ['READHEAVY_TIER', 'STORAGE_SPACE_FOR_2_IOPS_PER_GB'])
+
+        self.assertEqual(1, int(item_capacity))