1414from SoftLayer import testing
1515from SoftLayer import transports
1616from SoftLayer import exceptions
17+ from SoftLayer import auth as slauth
1718
1819
1920class Initialization (testing .TestCase ):
@@ -323,7 +324,6 @@ class EmployeeClientTests(testing.TestCase):
323324 def setup_response (filename , status_code = 200 , total_items = 1 ):
324325 basepath = os .path .dirname (__file__ )
325326 body = b''
326- print (f"Base Path: { basepath } " )
327327 with open (f"{ basepath } /../SoftLayer/fixtures/xmlrpc/{ filename } .xml" , 'rb' ) as fixture :
328328 body = fixture .read ()
329329 response = requests .Response ()
@@ -366,4 +366,46 @@ def test_refresh_token(self, api_response):
366366 result = self .client .refresh_token (9999 , 'qweasdzxcqweasdzxcqweasdzxc' )
367367 self .assertEqual (self .client .auth .user_id , 9999 )
368368 self .assertIn ('REFRESHEDTOKENaaaa' , self .client .auth .hash )
369-
369+
370+ @mock .patch ('SoftLayer.transports.xmlrpc.requests.Session.request' )
371+ def test_expired_token_is_refreshed (self , api_response ):
372+ api_response .side_effect = [
373+ self .setup_response ('expiredToken' ),
374+ self .setup_response ('refreshSuccess' ),
375+ self .setup_response ('Employee_getObject' )
376+ ]
377+ self .client .auth = slauth .EmployeeAuthentication (5555 , 'aabbccee' )
378+ self .client .settings ['softlayer' ]['userid' ] = '5555'
379+ result = self .client .call ('SoftLayer_User_Employee' , 'getObject' , id = 5555 )
380+ self .assertIn ('REFRESHEDTOKENaaaa' , self .client .auth .hash )
381+ self .assertEqual ('testUser' , result ['username' ])
382+
383+ @mock .patch ('SoftLayer.transports.xmlrpc.requests.Session.request' )
384+ def test_expired_token_is_really_expored (self , api_response ):
385+ api_response .side_effect = [
386+ self .setup_response ('expiredToken' ),
387+ self .setup_response ('expiredToken' )
388+ ]
389+ self .client .auth = slauth .EmployeeAuthentication (5555 , 'aabbccee' )
390+ self .client .settings ['softlayer' ]['userid' ] = '5555'
391+ exception = self .assertRaises (
392+ exceptions .SoftLayerAPIError ,
393+ self .client .call , 'SoftLayer_User_Employee' , 'getObject' , id = 5555 )
394+ self .assertEqual (None , self .client .auth )
395+ self .assertEqual (exception .faultCode , "SoftLayer_Exception_EncryptedToken_Expired" )
396+
397+ @mock .patch ('SoftLayer.API.BaseClient.call' )
398+ def test_account_check (self , _call ):
399+ self .client .transport = self .mocks
400+ exception = self .assertRaises (
401+ exceptions .SoftLayerError ,
402+ self .client .call , "SoftLayer_Account" , "getObject" )
403+ self .assertEqual (str (exception ), "SoftLayer_Account service requires an ID" )
404+ self .client .account_id = 1234
405+ self .client .call ("SoftLayer_Account" , "getObject" )
406+ self .client .call ("SoftLayer_Account" , "getObject1" , id = 9999 )
407+
408+ _call .assert_has_calls ([
409+ mock .call (self .client , 'SoftLayer_Account' , 'getObject' , id = 1234 ),
410+ mock .call (self .client , 'SoftLayer_Account' , 'getObject1' , id = 9999 ),
411+ ])
0 commit comments