<s> """<STR_LIT>""" <EOL> import mock <EOL> import SoftLayer <EOL> import SoftLayer . API <EOL> from SoftLayer import testing <EOL> from SoftLayer import transports <EOL> class Inititialization ( testing . TestCase ) : <EOL> def test_init ( self ) : <EOL> client = SoftLayer . Client ( username = '<STR_LIT>' , <EOL> api_key = '<STR_LIT>' , <EOL> timeout = <NUM_LIT:10> ) <EOL> self . assertIsInstance ( client . auth , SoftLayer . BasicAuthentication ) <EOL> self . assertEqual ( client . auth . username , '<STR_LIT>' ) <EOL> self . assertEqual ( client . auth . api_key , '<STR_LIT>' ) <EOL> self . assertIsNotNone ( client . transport ) <EOL> self . assertIsInstance ( client . transport , transports . XmlRpcTransport ) <EOL> self . assertEqual ( client . transport . timeout , <NUM_LIT:10> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_env ( self , get_client_settings ) : <EOL> auth = mock . Mock ( ) <EOL> get_client_settings . return_value = { <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> client = SoftLayer . Client ( auth = auth ) <EOL> self . assertEqual ( client . auth . get_headers ( ) , auth . get_headers ( ) ) <EOL> self . assertEqual ( client . transport . timeout , <NUM_LIT:10> ) <EOL> self . assertEqual ( client . transport . endpoint_url , '<STR_LIT>' ) <EOL> class ClientMethods ( testing . TestCase ) : <EOL> def test_repr ( self ) : <EOL> client = SoftLayer . Client ( <EOL> username = '<STR_LIT>' , <EOL> api_key = '<STR_LIT>' <EOL> ) <EOL> self . assertIn ( "<STR_LIT>" , repr ( client ) ) <EOL> def test_service_repr ( self ) : <EOL> client = SoftLayer . Client ( <EOL> username = '<STR_LIT>' , <EOL> api_key = '<STR_LIT>' <EOL> ) <EOL> self . assertIn ( "<STR_LIT>" , repr ( client [ '<STR_LIT>' ] ) ) <EOL> def test_len ( self ) : <EOL> client = SoftLayer . Client ( <EOL> username = '<STR_LIT>' , <EOL> api_key = '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( len ( client ) , <NUM_LIT:0> ) <EOL> class APIClient ( testing . TestCase ) : <EOL> def test_simple_call ( self ) : <EOL> mock = self . set_mock ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mock . return_value = { "<STR_LIT:test>" : "<STR_LIT:result>" } <EOL> resp = self . client [ '<STR_LIT>' ] . METHOD ( ) <EOL> self . assertEqual ( resp , { "<STR_LIT:test>" : "<STR_LIT:result>" } ) <EOL> self . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , <EOL> mask = None , <EOL> filter = None , <EOL> identifier = None , <EOL> args = tuple ( ) , <EOL> limit = None , <EOL> offset = None , <EOL> ) <EOL> def test_complex ( self ) : <EOL> mock = self . set_mock ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mock . return_value = { "<STR_LIT:test>" : "<STR_LIT:result>" } <EOL> _filter = { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } } <EOL> resp = self . client [ '<STR_LIT>' ] . METHOD ( <EOL> <NUM_LIT> , <EOL> id = <NUM_LIT> , <EOL> mask = { '<STR_LIT:object>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> headers = { '<STR_LIT>' : '<STR_LIT:value>' } , <EOL> raw_headers = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> filter = _filter , <EOL> limit = <NUM_LIT:9> , <EOL> offset = <NUM_LIT:10> ) <EOL> self . assertEqual ( resp , { "<STR_LIT:test>" : "<STR_LIT:result>" } ) <EOL> self . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , <EOL> mask = { '<STR_LIT:object>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> filter = _filter , <EOL> identifier = <NUM_LIT> , <EOL> args = ( <NUM_LIT> , ) , <EOL> limit = <NUM_LIT:9> , <EOL> offset = <NUM_LIT:10> , <EOL> ) <EOL> calls = self . calls ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( calls ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , calls [ <NUM_LIT:0> ] . headers ) <EOL> self . assertEqual ( calls [ <NUM_LIT:0> ] . headers [ '<STR_LIT>' ] , '<STR_LIT:value>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_iterate ( self , _iter_call ) : <EOL> self . client [ '<STR_LIT>' ] . METHOD ( iter = True ) <EOL> _iter_call . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_service_iter_call ( self , _iter_call ) : <EOL> self . client [ '<STR_LIT>' ] . iter_call ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _iter_call . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_service_iter_call_with_chunk ( self , _iter_call ) : <EOL> self . client [ '<STR_LIT>' ] . iter_call ( '<STR_LIT>' , '<STR_LIT>' , chunk = <NUM_LIT:2> ) <EOL> _iter_call . assert_called_with ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , chunk = <NUM_LIT:2> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_iter_call ( self , _call ) : <EOL> _call . side_effect = [ list ( range ( <NUM_LIT:100> ) ) , list ( range ( <NUM_LIT:100> , <NUM_LIT> ) ) ] <EOL> result = list ( self . client . iter_call ( '<STR_LIT>' , '<STR_LIT>' , iter = True ) ) <EOL> self . assertEqual ( list ( range ( <NUM_LIT> ) ) , result ) <EOL> _call . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , limit = <NUM_LIT:100> , iter = False , offset = <NUM_LIT:0> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , limit = <NUM_LIT:100> , iter = False , offset = <NUM_LIT:100> ) , <EOL> ] ) <EOL> _call . reset_mock ( ) <EOL> _call . side_effect = [ list ( range ( <NUM_LIT:100> ) ) , list ( range ( <NUM_LIT:100> , <NUM_LIT:200> ) ) , [ ] ] <EOL> result = list ( self . client . iter_call ( '<STR_LIT>' , '<STR_LIT>' , iter = True ) ) <EOL> self . assertEqual ( list ( range ( <NUM_LIT:200> ) ) , result ) <EOL> _call . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , limit = <NUM_LIT:100> , iter = False , offset = <NUM_LIT:0> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , limit = <NUM_LIT:100> , iter = False , offset = <NUM_LIT:100> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , limit = <NUM_LIT:100> , iter = False , offset = <NUM_LIT:200> ) , <EOL> ] ) <EOL> _call . reset_mock ( ) <EOL> _call . side_effect = [ list ( range ( <NUM_LIT:0> , <NUM_LIT> ) ) , list ( range ( <NUM_LIT> , <NUM_LIT:30> ) ) ] <EOL> result = list ( self . client . iter_call ( <EOL> '<STR_LIT>' , '<STR_LIT>' , iter = True , limit = <NUM_LIT:30> , chunk = <NUM_LIT> ) ) <EOL> self . assertEqual ( list ( range ( <NUM_LIT:30> ) ) , result ) <EOL> _call . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , iter = False , limit = <NUM_LIT> , offset = <NUM_LIT:0> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , iter = False , limit = <NUM_LIT:5> , offset = <NUM_LIT> ) , <EOL> ] ) <EOL> _call . reset_mock ( ) <EOL> _call . side_effect = [ "<STR_LIT:test>" ] <EOL> result = list ( self . client . iter_call ( '<STR_LIT>' , '<STR_LIT>' , iter = True ) ) <EOL> self . assertEqual ( [ "<STR_LIT:test>" ] , result ) <EOL> _call . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , iter = False , limit = <NUM_LIT:100> , offset = <NUM_LIT:0> ) , <EOL> ] ) <EOL> _call . reset_mock ( ) <EOL> _call . side_effect = [ list ( range ( <NUM_LIT:0> , <NUM_LIT> ) ) , list ( range ( <NUM_LIT> , <NUM_LIT:30> ) ) ] <EOL> result = list ( self . client . iter_call ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> iter = True , <EOL> limit = <NUM_LIT:30> , <EOL> chunk = <NUM_LIT> , <EOL> offset = <NUM_LIT:12> ) ) <EOL> self . assertEqual ( list ( range ( <NUM_LIT:30> ) ) , result ) <EOL> _call . assert_has_calls ( [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> iter = False , limit = <NUM_LIT> , offset = <NUM_LIT:12> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> iter = False , limit = <NUM_LIT:5> , offset = <NUM_LIT> ) , <EOL> ] ) <EOL> self . assertRaises ( <EOL> AttributeError , <EOL> lambda : list ( self . client . iter_call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> iter = True , chunk = <NUM_LIT:0> ) ) ) <EOL> def test_call_invalid_arguments ( self ) : <EOL> self . assertRaises ( <EOL> TypeError , <EOL> self . client . call , '<STR_LIT>' , '<STR_LIT>' , invalid_kwarg = '<STR_LIT>' ) <EOL> def test_call_compression_disabled ( self ) : <EOL> mocked = self . set_mock ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mocked . return_value = { } <EOL> self . client [ '<STR_LIT>' ] . METHOD ( compress = False ) <EOL> calls = self . calls ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( calls ) , <NUM_LIT:1> ) <EOL> headers = calls [ <NUM_LIT:0> ] . transport_headers <EOL> self . assertEqual ( headers . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_call_compression_enabled ( self ) : <EOL> mocked = self . set_mock ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mocked . return_value = { } <EOL> self . client [ '<STR_LIT>' ] . METHOD ( compress = True ) <EOL> calls = self . calls ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( calls ) , <NUM_LIT:1> ) <EOL> headers = calls [ <NUM_LIT:0> ] . transport_headers <EOL> self . assertEqual ( headers . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_call_compression_override ( self ) : <EOL> mocked = self . set_mock ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mocked . return_value = { } <EOL> self . client [ '<STR_LIT>' ] . METHOD ( <EOL> compress = False , <EOL> raw_headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> calls = self . calls ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( calls ) , <NUM_LIT:1> ) <EOL> headers = calls [ <NUM_LIT:0> ] . transport_headers <EOL> self . assertEqual ( headers . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> class UnauthenticatedAPIClient ( testing . TestCase ) : <EOL> def set_up ( self ) : <EOL> self . client = SoftLayer . Client ( endpoint_url = "<STR_LIT>" ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_init ( self , get_client_settings ) : <EOL> get_client_settings . return_value = { } <EOL> client = SoftLayer . Client ( ) <EOL> self . assertIsNone ( client . auth ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_init_with_proxy ( self , get_client_settings ) : <EOL> get_client_settings . return_value = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client = SoftLayer . Client ( ) <EOL> self . assertEqual ( client . transport . proxy , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_authenticate_with_password ( self , _call ) : <EOL> _call . return_value = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . client . authenticate_with_password ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _call . assert_called_with ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> None , <EOL> None ) <EOL> self . assertIsNotNone ( self . client . auth ) <EOL> self . assertEqual ( self . client . auth . user_id , <NUM_LIT> ) <EOL> self . assertEqual ( self . client . auth . auth_token , '<STR_LIT>' ) </s>
