Repository: softlayer/softlayer-python
Pull request #1174 (2019-10-03 14:59:53)

Autoscale cli list and managers unit test.
Autoscale cli list and managers unit test.

```
Test Managers:

Name                                     Stmts   Miss  Cover   Missing
--------------------------------------------------------------------
SoftLayer\managers\__init__.py            23      0     100%
SoftLayer\managers\autoscale.py           21      0     100%

Test CLI:

Name                                      Stmts   Miss  Cover   Missing
-------------------------------------------------------------------
SoftLayer\CLI\autoscale\__init__.py        0       0      100%
SoftLayer\CLI\autoscale\list.py           16       0      100%
```




Patch:
diff --git a/SoftLayer/fixtures/SoftLayer_Account.py b/SoftLayer/fixtures/SoftLayer_Account.py
index a0c865e3..ddb2a435 100644
--- a/SoftLayer/fixtures/SoftLayer_Account.py
+++ b/SoftLayer/fixtures/SoftLayer_Account.py
@@ -769,3 +769,86 @@
         }
     }
 ]
+
+getScaleGroups = [
+    {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2016-10-25T01:48:34+08:00",
+        "id": 12222222,
+        "lastActionDate": "2016-10-25T01:48:34+08:00",
+        "maximumMemberCount": 5,
+        "minimumMemberCount": 0,
+        "name": "tests",
+        "regionalGroupId": 663,
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "sodg.com",
+            "hostname": "testing",
+            "id": None,
+            "maxCpu": None,
+            "maxMemory": 32768,
+            "startCpus": 32,
+            "blockDevices": [
+                {
+                    "device": "0",
+                    "diskImage": {
+                        "capacity": 25,
+                    }
+                }
+            ],
+            "datacenter": {
+                "name": "sao01",
+            },
+            "hourlyBillingFlag": True,
+            "operatingSystemReferenceCode": "CENTOS_LATEST",
+        },
+        "virtualGuestMemberCount": 0,
+        "status": {
+            "id": 1,
+            "keyName": "ACTIVE",
+            "name": "Active"
+        },
+    },
+    {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2018-04-24T04:22:00+08:00",
+        "id": 224533333,
+        "lastActionDate": "2019-01-19T04:53:18+08:00",
+        "maximumMemberCount": 10,
+        "minimumMemberCount": 0,
+        "modifyDate": "2019-01-19T04:53:21+08:00",
+        "name": "test-ajcb",
+        "regionalGroupId": 1025,
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "test.local",
+            "hostname": "autoscale-ajcb01",
+            "id": None,
+            "maxCpu": None,
+            "maxMemory": 1024,
+            "postInstallScriptUri": "http://test.com",
+            "startCpus": 1,
+            "blockDevices": [
+                {
+                    "device": "0",
+                    "diskImage": {
+                        "capacity": 25,
+                    }
+                }
+            ],
+            "datacenter": {
+                "name": "seo01",
+            },
+            "hourlyBillingFlag": True,
+            "operatingSystemReferenceCode": "CENTOS_7_64",
+        },
+        "virtualGuestMemberCount": 0,
+        "status": {
+            "id": 1,
+            "keyName": "ACTIVE",
+            "name": "Active"
+        }
+    }
+]
diff --git a/SoftLayer/fixtures/SoftLayer_Scale_Group.py b/SoftLayer/fixtures/SoftLayer_Scale_Group.py
new file mode 100644
index 00000000..403bd520
--- /dev/null
+++ b/SoftLayer/fixtures/SoftLayer_Scale_Group.py
@@ -0,0 +1,276 @@
+getObject = {
+    "accountId": 31111,
+    "cooldown": 1800,
+    "createDate": "2016-10-25T01:48:34+08:00",
+    "id": 12222222,
+    "lastActionDate": "2016-10-25T01:48:34+08:00",
+    "maximumMemberCount": 5,
+    "minimumMemberCount": 0,
+    "name": "tests",
+    "regionalGroupId": 663,
+    "virtualGuestMemberTemplate": {
+        "accountId": 31111,
+        "domain": "sodg.com",
+        "hostname": "testing",
+        "id": None,
+        "maxCpu": None,
+        "maxMemory": 32768,
+        "startCpus": 32,
+        "blockDevices": [
+            {
+                "device": "0",
+                "diskImage": {
+                    "capacity": 25,
+                }
+            }
+        ],
+        "datacenter": {
+            "name": "sao01",
+        },
+        "hourlyBillingFlag": True,
+        "operatingSystemReferenceCode": "CENTOS_LATEST",
+        "privateNetworkOnlyFlag": True
+    },
+    "virtualGuestMemberCount": 0,
+    "status": {
+        "id": 1,
+        "keyName": "ACTIVE",
+        "name": "Active"
+    },
+    "virtualGuestAssets": [],
+    "virtualGuestMembers": []
+}
+
+scale = [
+    {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2016-10-25T01:48:34+08:00",
+        "id": 12222222,
+        "maximumMemberCount": 5,
+        "minimumMemberCount": 0,
+        "name": "tests",
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "sodg.com",
+            "hostname": "testing",
+            "maxMemory": 32768,
+            "startCpus": 32,
+            "blockDevices": [
+                {
+                    "device": "0",
+                    "diskImage": {
+                        "capacity": 25,
+                    }
+                }
+            ],
+            "datacenter": {
+                "name": "sao01",
+            },
+            "hourlyBillingFlag": True,
+            "operatingSystemReferenceCode": "CENTOS_LATEST",
+            "privateNetworkOnlyFlag": True
+        },
+        "virtualGuestMemberCount": 0,
+        "status": {
+            "id": 1,
+            "keyName": "ACTIVE",
+            "name": "Active"
+        },
+        "virtualGuestAssets": [],
+        "virtualGuestMembers": []
+    },
+    {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2018-04-24T04:22:00+08:00",
+        "id": 224533333,
+        "maximumMemberCount": 10,
+        "minimumMemberCount": 0,
+        "modifyDate": "2019-01-19T04:53:21+08:00",
+        "name": "test-ajcb",
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "test.local",
+            "hostname": "autoscale-ajcb01",
+            "id": None,
+            "maxCpu": None,
+            "maxMemory": 1024,
+            "postInstallScriptUri": "http://test.com",
+            "startCpus": 1,
+            "blockDevices": [
+                {
+                    "device": "0",
+                    "diskImage": {
+                        "capacity": 25,
+                    }
+                }
+            ],
+            "datacenter": {
+                "name": "seo01",
+            },
+            "hourlyBillingFlag": True,
+            "operatingSystemReferenceCode": "CENTOS_7_64",
+        },
+        "virtualGuestMemberCount": 0,
+        "status": {
+            "id": 1,
+            "keyName": "ACTIVE",
+            "name": "Active"
+        },
+        "virtualGuestAssets": [],
+        "virtualGuestMembers": []
+    },
+]
+
+scaleTo = [
+    {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2016-10-25T01:48:34+08:00",
+        "id": 12222222,
+        "lastActionDate": "2016-10-25T01:48:34+08:00",
+        "maximumMemberCount": 5,
+        "minimumMemberCount": 0,
+        "name": "tests",
+        "regionalGroupId": 663,
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "sodg.com",
+            "hostname": "testing",
+            "id": None,
+            "maxCpu": None,
+            "maxMemory": 32768,
+            "startCpus": 32,
+            "datacenter": {
+                "name": "sao01",
+            },
+            "hourlyBillingFlag": True,
+            "operatingSystemReferenceCode": "CENTOS_LATEST",
+            "privateNetworkOnlyFlag": True
+        },
+        "virtualGuestMemberCount": 0,
+        "status": {
+            "id": 1,
+            "keyName": "ACTIVE",
+            "name": "Active"
+        },
+        "virtualGuestAssets": [],
+        "virtualGuestMembers": []
+    },
+    {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2018-04-24T04:22:00+08:00",
+        "id": 224533333,
+        "lastActionDate": "2019-01-19T04:53:18+08:00",
+        "maximumMemberCount": 10,
+        "minimumMemberCount": 0,
+        "modifyDate": "2019-01-19T04:53:21+08:00",
+        "name": "test-ajcb",
+        "regionalGroupId": 1025,
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "test.local",
+            "hostname": "autoscale-ajcb01",
+            "id": None,
+            "maxCpu": None,
+            "maxMemory": 1024,
+            "postInstallScriptUri": "http://test.com",
+            "startCpus": 1,
+            "blockDevices": [
+                {
+                    "device": "0",
+                    "diskImage": {
+                        "capacity": 25,
+                    }
+                }
+            ],
+            "datacenter": {
+                "name": "seo01",
+            },
+            "hourlyBillingFlag": True,
+            "operatingSystemReferenceCode": "CENTOS_7_64",
+        },
+        "virtualGuestMemberCount": 0,
+        "status": {
+            "id": 1,
+            "keyName": "ACTIVE",
+            "name": "Active"
+        },
+        "virtualGuestAssets": [],
+        "virtualGuestMembers": []
+    },
+]
+
+getLogs = [
+    {
+        "createDate": "2019-10-03T04:26:11+08:00",
+        "description": "Scaling group to 6 member(s) by adding 3 member(s) as manually requested",
+        "id": 3821111,
+        "scaleGroupId": 2252222,
+        "scaleGroup": {
+            "accountId": 31111,
+            "cooldown": 1800,
+            "createDate": "2018-05-01T03:07:40+08:00",
+            "id": 2251111,
+            "lastActionDate": "2019-10-03T04:26:17+08:00",
+            "maximumMemberCount": 6,
+            "minimumMemberCount": 2,
+            "modifyDate": "2019-10-03T04:26:21+08:00",
+            "name": "ajcb-autoscale11",
+            "regionalGroupId": 663,
+            "terminationPolicyId": 2,
+            "virtualGuestMemberTemplate": {
+                "accountId": 31111,
+                "domain": "techsupport.com",
+                "hostname": "ajcb-autoscale22",
+                "maxMemory": 1024,
+                "postInstallScriptUri": "https://pastebin.com/raw/62wrEKuW",
+                "startCpus": 1,
+                "blockDevices": [
+                    {
+                        "device": "0",
+                        "diskImage": {
+                            "capacity": 25,
+                        }
+                    },
+                    {
+                        "device": "2",
+                        "diskImage": {
+                            "capacity": 10,
+                        }
+                    }
+                ],
+                "datacenter": {
+                    "name": "sao01",
+                },
+                "networkComponents": [
+                    {
+                        "maxSpeed": 100,
+                    }
+                ],
+                "operatingSystemReferenceCode": "CENTOS_LATEST",
+                "sshKeys": [
+                    {
+                        "id": 49111,
+                    }
+                ]
+            },
+            "logs": [
+                {
+                    "createDate": "2019-09-28T02:31:35+08:00",
+                    "description": "Scaling group to 3 member(s) by removing -1 member(s) as manually requested",
+                    "id": 3821111,
+                    "scaleGroupId": 2251111,
+                },
+                {
+                    "createDate": "2019-09-28T02:26:11+08:00",
+                    "description": "Scaling group to 4 member(s) by adding 2 member(s) as manually requested",
+                    "id": 38211111,
+                    "scaleGroupId": 2251111,
+                },
+            ]
+        }
+    },
+]
diff --git a/SoftLayer/fixtures/SoftLayer_Scale_Policy.py b/SoftLayer/fixtures/SoftLayer_Scale_Policy.py
new file mode 100644
index 00000000..5586fec1
--- /dev/null
+++ b/SoftLayer/fixtures/SoftLayer_Scale_Policy.py
@@ -0,0 +1,58 @@
+getObject = {
+    "cooldown": None,
+    "createDate": "2019-09-27T06:30:14+08:00",
+    "id": 11111,
+    "name": "prime-poly",
+    "scaleGroupId": 2255111,
+    "scaleGroup": {
+        "accountId": 31111,
+        "cooldown": 1800,
+        "createDate": "2018-05-01T03:07:40+08:00",
+        "id": 2252222,
+        "lastActionDate": "2019-09-28T02:31:47+08:00",
+        "maximumMemberCount": 6,
+        "minimumMemberCount": 2,
+        "modifyDate": "2019-09-28T02:31:50+08:00",
+        "name": "ajcb-autoscale11",
+        "regionalGroupId": 663,
+        "terminationPolicyId": 2,
+        "virtualGuestMemberTemplate": {
+            "accountId": 31111,
+            "domain": "techsupport.com",
+            "hostname": "ajcb-autoscale22",
+            "id": None,
+            "maxMemory": 1024,
+            "postInstallScriptUri": "https://pastebin.com/raw/62wrEKuW",
+            "startCpus": 1,
+            "blockDevices": [
+                {
+                    "device": "0",
+                    "diskImage": {
+                        "capacity": 25,
+                    }
+                },
+                {
+                    "device": "2",
+                    "diskImage": {
+                        "capacity": 10,
+                    }
+                }
+            ],
+            "datacenter": {
+                "id": None,
+                "name": "sao01",
+            },
+            "networkComponents": [
+                {
+                    "maxSpeed": 100,
+                }
+            ],
+            "operatingSystemReferenceCode": "CENTOS_LATEST",
+            "sshKeys": [
+                {
+                    "id": 490279,
+                }
+            ]
+        }
+    }
+}


Test patch:
diff --git a/tests/CLI/modules/autoscale_tests.py b/tests/CLI/modules/autoscale_tests.py
new file mode 100644
index 00000000..33bf4a37
--- /dev/null
+++ b/tests/CLI/modules/autoscale_tests.py
@@ -0,0 +1,14 @@
+"""
+    SoftLayer.tests.CLI.modules.autoscale_tests
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+    Tests for the user cli command
+"""
+from SoftLayer import testing
+
+
+class AutoScaleTests(testing.TestCase):
+
+    def test_autoscale_list(self):
+        result = self.run_command(['autoscale', 'list'])
+        self.assert_no_fail(result)
diff --git a/tests/managers/autoscale_tests.py b/tests/managers/autoscale_tests.py
new file mode 100644
index 00000000..124a8287
--- /dev/null
+++ b/tests/managers/autoscale_tests.py
@@ -0,0 +1,95 @@
+"""
+    SoftLayer.tests.managers.autoscale_tests
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+    :license: MIT, see LICENSE for more details.
+"""
+
+from SoftLayer.managers.autoscale import AutoScaleManager
+from SoftLayer import testing
+
+
+class AutoScaleTests(testing.TestCase):
+
+    def set_up(self):
+        self.autoscale = AutoScaleManager(self.client)
+
+    def test_autoscale_list(self):
+        self.autoscale.list()
+
+        self.assert_called_with(
+            'SoftLayer_Account',
+            'getScaleGroups'
+        )
+
+    def test_autoscale_list_with_mask(self):
+        self.autoscale.list(mask='mask[status,virtualGuestMemberCount]')
+
+        self.assert_called_with(
+            'SoftLayer_Account',
+            'getScaleGroups'
+        )
+
+    def test_autoscale_details(self):
+        self.autoscale.details(11111)
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Group',
+            'getObject',
+            identifier=11111
+        )
+
+    def test_autoscale_details_with_mask(self):
+        self.autoscale.details(11111, mask='mask[virtualGuestMembers[id,virtualGuest[hostname,domain,provisionDate]], '
+                                           'terminationPolicy,virtualGuestMemberCount]')
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Group',
+            'getObject',
+            identifier=11111
+        )
+
+    def test_autoscale_policy(self):
+        self.autoscale.get_policy(11111)
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Policy',
+            'getObject',
+            identifier=11111
+        )
+
+    def test_autoscale_policy_with_mask(self):
+        self.autoscale.get_policy(11111, mask='mask[cooldown, createDate, id, name, actions, triggers[type]]')
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Policy',
+            'getObject',
+            identifier=11111
+        )
+
+    def test_autoscale_scale(self):
+        self.autoscale.scale(11111, 3)
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Group',
+            'scale',
+            identifier=11111
+        )
+
+    def test_autoscale_scaleTo(self):
+        self.autoscale.scale_to(11111, 3)
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Group',
+            'scaleTo',
+            identifier=11111
+        )
+
+    def test_autoscale_getLogs(self):
+        self.autoscale.get_logs(11111)
+
+        self.assert_called_with(
+            'SoftLayer_Scale_Group',
+            'getLogs',
+            identifier=11111
+        )