Skip to content

Commit 7a3af08

Browse files
author
Flavio Fernandes
committed
virtual detail: improve coverage
Add test for verifying host_id attribute
1 parent ad94609 commit 7a3af08

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
getObject = {
2+
'id': 37401,
3+
'memoryCapacity': 242,
4+
'modifyDate': '',
5+
'name': 'test-dedicated',
6+
'diskCapacity': 1200,
7+
'createDate': '2017-10-16T12:50:23-05:00',
8+
'cpuCount': 56,
9+
'accountId': 1199911
10+
}

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'networkVlans': [{'networkSpace': 'PUBLIC',
4545
'vlanNumber': 23,
4646
'id': 1}],
47+
'dedicatedHost': {'id': 37401},
4748
'operatingSystem': {
4849
'passwords': [{'username': 'user', 'password': 'pass'}],
4950
'softwareLicense': {

tests/CLI/modules/vs_tests.py

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import mock
1010

1111
from SoftLayer.CLI import exceptions
12+
from SoftLayer import SoftLayerAPIError
1213
from SoftLayer import testing
1314

1415

@@ -42,6 +43,8 @@ def test_detail_vs(self):
4243
'cores': 2,
4344
'created': '2013-08-01 15:23:45',
4445
'datacenter': 'TEST00',
46+
'dedicated_host': 'test-dedicated',
47+
'dedicated_host_id': 37401,
4548
'hostname': 'vs-test1',
4649
'domain': 'test.sftlyr.ws',
4750
'fqdn': 'vs-test1.test.sftlyr.ws',
@@ -88,6 +91,24 @@ def test_detail_vs_empty_tag(self):
8891
['example-tag'],
8992
)
9093

94+
def test_detail_vs_dedicated_host_not_found(self):
95+
ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
96+
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
97+
mock.side_effect = ex
98+
result = self.run_command(['vs', 'detail', '100'])
99+
self.assert_no_fail(result)
100+
self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401)
101+
self.assertIsNone(json.loads(result.output)['dedicated_host'])
102+
103+
def test_detail_vs_no_dedicated_host_hostname(self):
104+
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
105+
mock.return_value = {'this_is_a_fudged_Virtual_DedicatedHost': True,
106+
'name_is_not_provided': ''}
107+
result = self.run_command(['vs', 'detail', '100'])
108+
self.assert_no_fail(result)
109+
self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401)
110+
self.assertIsNone(json.loads(result.output)['dedicated_host'])
111+
91112
def test_create_options(self):
92113
result = self.run_command(['vs', 'create-options'])
93114

0 commit comments

Comments
 (0)