@@ -26,6 +26,58 @@ def test_server_cancel_reasons(self):
2626 self .assert_no_fail (result )
2727 self .assertEqual (len (output ), 10 )
2828
29+ def test_server_credentials (self ):
30+ result = self .run_command (['hardware' , 'credentials' , '12345' ])
31+
32+ self .assert_no_fail (result )
33+ self .assertEqual (json .loads (result .output ),
34+ [{
35+ 'username' : 'root' ,
36+ 'password' : 'abc123'
37+ }])
38+
39+ def test_server_credentials_exception_passwords_not_found (self ):
40+ mock = self .set_mock ('SoftLayer_Hardware_Server' , 'getObject' )
41+ mock .return_value = {
42+ "accountId" : 11111 ,
43+ "domain" : "chechu.com" ,
44+ "fullyQualifiedDomainName" : "host3.vmware.chechu.com" ,
45+ "hardwareStatusId" : 5 ,
46+ "hostname" : "host3.vmware" ,
47+ "id" : 12345 ,
48+ "operatingSystem" : {}
49+ }
50+
51+ result = self .run_command (['hardware' , 'credentials' , '12345' ])
52+
53+ self .assertEqual (
54+ 'No passwords found in operatingSystem' ,
55+ str (result .exception )
56+ )
57+
58+ def test_server_credentials_exception_password_not_found (self ):
59+ mock = self .set_mock ('SoftLayer_Hardware_Server' , 'getObject' )
60+ mock .return_value = {
61+ "accountId" : 11111 ,
62+ "domain" : "chechu.com" ,
63+ "fullyQualifiedDomainName" : "host3.vmware.chechu.com" ,
64+ "hardwareStatusId" : 5 ,
65+ "hostname" : "host3.vmware" ,
66+ "id" : 12345 ,
67+ "operatingSystem" : {
68+ "hardwareId" : 22222 ,
69+ "id" : 333333 ,
70+ "passwords" : [{}]
71+ }
72+ }
73+
74+ result = self .run_command (['hardware' , 'credentials' , '12345' ])
75+
76+ self .assertEqual (
77+ 'None' ,
78+ str (result .exception )
79+ )
80+
2981 def test_server_details (self ):
3082 result = self .run_command (['server' , 'detail' , '1234' ,
3183 '--passwords' , '--price' ])
@@ -313,7 +365,7 @@ def test_create_server_missing_required(self):
313365
314366 @mock .patch ('SoftLayer.CLI.template.export_to_template' )
315367 def test_create_server_with_export (self , export_mock ):
316- if (sys .platform .startswith ("win" )):
368+ if (sys .platform .startswith ("win" )):
317369 self .skipTest ("Test doesn't work in Windows" )
318370 result = self .run_command (['--really' , 'server' , 'create' ,
319371 '--size=S1270_8GB_2X1TBSATA_NORAID' ,
@@ -387,7 +439,7 @@ def test_edit_server_failed(self, edit_mock):
387439 hostname = 'hardware-test1' )
388440
389441 def test_edit_server_userfile (self ):
390- if (sys .platform .startswith ("win" )):
442+ if (sys .platform .startswith ("win" )):
391443 self .skipTest ("Test doesn't work in Windows" )
392444 with tempfile .NamedTemporaryFile () as userfile :
393445 userfile .write (b"some data" )
0 commit comments