Repository: softlayer/softlayer-python
Pull request #1070 (2018-11-06 22:55:36)

fixed price lookup bug
fixed price lookup bug and resolved/ignored a bunch of new pylint errors

#1067 


Patch:
diff --git a/SoftLayer/CLI/virt/create_options.py b/SoftLayer/CLI/virt/create_options.py
index 7bacd8bf..b50fde3d 100644
--- a/SoftLayer/CLI/virt/create_options.py
+++ b/SoftLayer/CLI/virt/create_options.py
@@ -1,5 +1,6 @@
 """Virtual server order options."""
 # :license: MIT, see LICENSE for more details.
+# pylint: disable=too-many-statements
 import os
 import os.path
 
diff --git a/SoftLayer/CLI/vpn/ipsec/translation/add.py b/SoftLayer/CLI/vpn/ipsec/translation/add.py
index a0b7a35e..952f7fd6 100644
--- a/SoftLayer/CLI/vpn/ipsec/translation/add.py
+++ b/SoftLayer/CLI/vpn/ipsec/translation/add.py
@@ -11,12 +11,10 @@
 
 @click.command()
 @click.argument('context_id', type=int)
-# todo: Update to utilize custom IP address type
 @click.option('-s',
               '--static-ip',
               required=True,
               help='Static IP address value')
-# todo: Update to utilize custom IP address type
 @click.option('-r',
               '--remote-ip',
               required=True,
diff --git a/SoftLayer/CLI/vpn/ipsec/translation/update.py b/SoftLayer/CLI/vpn/ipsec/translation/update.py
index b78585db..4f070900 100644
--- a/SoftLayer/CLI/vpn/ipsec/translation/update.py
+++ b/SoftLayer/CLI/vpn/ipsec/translation/update.py
@@ -15,12 +15,10 @@
               required=True,
               type=int,
               help='Translation identifier to update')
-# todo: Update to utilize custom IP address type
 @click.option('-s',
               '--static-ip',
               default=None,
               help='Static IP address value')
-# todo: Update to utilize custom IP address type
 @click.option('-r',
               '--remote-ip',
               default=None,
diff --git a/SoftLayer/CLI/vpn/ipsec/update.py b/SoftLayer/CLI/vpn/ipsec/update.py
index 4056f3b8..738a1d9f 100644
--- a/SoftLayer/CLI/vpn/ipsec/update.py
+++ b/SoftLayer/CLI/vpn/ipsec/update.py
@@ -13,7 +13,6 @@
 @click.option('--friendly-name',
               default=None,
               help='Friendly name value')
-# todo: Update to utilize custom IP address type
 @click.option('--remote-peer',
               default=None,
               help='Remote peer IP address value')
diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py
index 6980f439..9f97a1d3 100644
--- a/SoftLayer/managers/hardware.py
+++ b/SoftLayer/managers/hardware.py
@@ -92,7 +92,7 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate=
         billing_id = hw_billing['billingItem']['id']
 
         if immediate and not hw_billing['hourlyBillingFlag']:
-            LOGGER.warning("Immediate cancelation of montly servers is not guaranteed. " +
+            LOGGER.warning("Immediate cancelation of montly servers is not guaranteed."
                            "Please check the cancelation ticket for updates.")
 
             result = self.client.call('Billing_Item', 'cancelItem',
diff --git a/SoftLayer/managers/ipsec.py b/SoftLayer/managers/ipsec.py
index 130623c4..29317516 100644
--- a/SoftLayer/managers/ipsec.py
+++ b/SoftLayer/managers/ipsec.py
@@ -227,10 +227,6 @@ def update_translation(self, context_id, translation_id, static_ip=None,
             translation.pop('customerIpAddressId', None)
         if notes is not None:
             translation['notes'] = notes
-        # todo: Update this signature to return the updated translation
-        #       once internal and customer IP addresses can be fetched
-        #       and set on the translation object, i.e. that which is
-        #       currently being handled in get_translations
         self.context.editAddressTranslation(translation, id=context_id)
         return True
 
diff --git a/SoftLayer/managers/ordering.py b/SoftLayer/managers/ordering.py
index 18a606b0..c0eca1dc 100644
--- a/SoftLayer/managers/ordering.py
+++ b/SoftLayer/managers/ordering.py
@@ -378,8 +378,10 @@ def get_item_price_id(core, prices):
             if not price['locationGroupId']:
                 capacity_min = int(price.get('capacityRestrictionMinimum', -1))
                 capacity_max = int(price.get('capacityRestrictionMaximum', -1))
-                if capacity_min == -1:
+                # return first match if no restirction, or no core to check
+                if capacity_min == -1 or core is None:
                     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']
         return price_id
diff --git a/tox.ini b/tox.ini
index ae456665..e5c7c2f6 100644
--- a/tox.ini
+++ b/tox.ini
@@ -36,6 +36,10 @@ commands =
            -d locally-disabled \
            -d no-else-return \ 
            -d len-as-condition \
+           -d useless-object-inheritance \
+           -d consider-using-in \
+           -d consider-using-dict-comprehension \
+           -d useless-import-alias \
            --max-args=25 \
            --max-branches=20 \
            --max-statements=65 \


Test patch:
diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py
index 4b2c431c..b5d2aaa4 100644
--- a/tests/managers/ordering_tests.py
+++ b/tests/managers/ordering_tests.py
@@ -569,3 +569,31 @@ def test_get_item_price_id_with_capacity_restriction(self):
         price_id = self.ordering.get_item_price_id("8", price1)
 
         self.assertEqual(1234, price_id)
+
+    def test_issues1067(self):
+        # https://github.com/softlayer/softlayer-python/issues/1067
+        item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
+        item_mock_return = [
+            {
+                'id': 10453,
+                'itemCategory': {'categoryCode': 'server'},
+                'keyName': 'INTEL_INTEL_XEON_4110_2_10',
+                'prices': [
+                    {
+                        'capacityRestrictionMaximum': '2',
+                        'capacityRestrictionMinimum': '2',
+                        'capacityRestrictionType': 'PROCESSOR',
+                        'categories': [{'categoryCode': 'os'}],
+                        'id': 201161,
+                        'locationGroupId': None,
+                        'recurringFee': '250',
+                        'setupFee': '0'
+                    }
+                ]
+            }
+        ]
+        item_mock.return_value = item_mock_return
+        item_keynames = ['INTEL_INTEL_XEON_4110_2_10']
+        package = 'DUAL_INTEL_XEON_PROCESSOR_SCALABLE_FAMILY_4_DRIVES'
+        result = self.ordering.get_price_id_list(package, item_keynames, None)
+        self.assertIn(201161, result)