44
55 :license: MIT, see LICENSE for more details.
66"""
7+ import io
78from unittest import mock as mock
9+ import requests
810
911import SoftLayer
1012import SoftLayer .API
1113from SoftLayer import testing
1214from SoftLayer import transports
15+ from SoftLayer import exceptions
1316
1417
1518class Initialization (testing .TestCase ):
@@ -310,3 +313,47 @@ def test_authenticate_with_password(self, _call):
310313 self .assertIsNotNone (self .client .auth )
311314 self .assertEqual (self .client .auth .user_id , 12345 )
312315 self .assertEqual (self .client .auth .auth_token , 'TOKEN' )
316+
317+
318+ class EmployeeClientTests (testing .TestCase ):
319+
320+ @staticmethod
321+ def failed_log ():
322+ response = requests .Response ()
323+ list_body = b'''<?xml version="1.0" encoding="iso-8859-1"?>
324+ <methodResponse>
325+ <fault>
326+ <value>
327+ <struct>
328+ <member>
329+ <name>faultCode</name>
330+ <value>
331+ <string>SoftLayer_Exception_Public</string>
332+ </value>
333+ </member>
334+ <member>
335+ <name>faultString</name>
336+ <value>
337+ <string>Invalid username/password</string>
338+ </value>
339+ </member>
340+ </struct>
341+ </value>
342+ </fault>
343+ </methodResponse>'''
344+ response .raw = io .BytesIO (list_body )
345+ response .status_code = 200
346+ return response
347+
348+ def set_up (self ):
349+ self .client = SoftLayer .API .EmployeeClient (config_file = './tests/testconfig' )
350+
351+ @mock .patch ('SoftLayer.transports.xmlrpc.requests.Session.request' )
352+ def test_auth_with_pass (self , api_response ):
353+ api_response .return_value = self .failed_log ()
354+ exception = self .assertRaises (
355+ exceptions .SoftLayerAPIError ,
356+ self .client .authenticate_with_password , 'testUser' , 'testPassword' , '123456' )
357+
358+
359+ self .assertEqual (exception .faultCode , "SoftLayer_Exception_Public" )
0 commit comments