<s> from mock import call , patch , Mock <EOL> from nose . tools import eq_ , raises , assert_raises <EOL> import btsync <EOL> from responses import ResponseFixtures <EOL> fixtures = ResponseFixtures ( ) <EOL> def test_unrecognized_params_used_to_construct_client ( ) : <EOL> with assert_raises ( AssertionError ) as e : <EOL> btsync . Client ( host = '<STR_LIT>' , <EOL> port = '<STR_LIT>' , <EOL> user = '<STR_LIT>' , <EOL> pwd = '<STR_LIT>' ) <EOL> eq_ ( "<STR_LIT>" , <EOL> str ( e . exception ) ) <EOL> class TestClient ( object ) : <EOL> patchers = [ ] <EOL> HOST = '<STR_LIT:127.0.0.1>' <EOL> PORT = <NUM_LIT> <EOL> USERNAME = '<STR_LIT>' <EOL> PASSWORD = '<STR_LIT:password>' <EOL> def _patch ( self , * args , ** kwargs ) : <EOL> patcher = patch ( * args , ** kwargs ) <EOL> self . patchers . append ( patcher ) <EOL> return patcher . start ( ) <EOL> def _make_client ( self ) : <EOL> return btsync . Client ( <EOL> host = self . HOST , <EOL> port = self . PORT , <EOL> username = self . USERNAME , <EOL> password = self . PASSWORD , <EOL> ) <EOL> def _mock_token ( self , token = u'<STR_LIT:T>' ) : <EOL> self . get_token = self . _patch ( <EOL> '<STR_LIT>' , return_value = token ) <EOL> def _mock_response ( self , method , response_text ) : <EOL> getattr ( self . mock_session , method ) . return_value . text = response_text <EOL> def assert_request_url ( self , rest_url , method = '<STR_LIT>' ) : <EOL> url = '<STR_LIT>' . format ( <EOL> host = self . HOST , port = self . PORT , rest_url = rest_url ) <EOL> eq_ ( [ call ( url ) ] , <EOL> getattr ( self . mock_session , method ) . call_args_list ) <EOL> def setup ( self ) : <EOL> self . time = self . _patch ( <EOL> '<STR_LIT>' , return_value = <NUM_LIT> ) <EOL> self . mock_session = Mock ( ) <EOL> self . session_class = self . _patch ( <EOL> '<STR_LIT>' , <EOL> return_value = self . mock_session ) <EOL> def teardown ( self ) : <EOL> for patcher in self . patchers : <EOL> patcher . stop ( ) <EOL> self . __class__ . patchers = [ ] <EOL> def test_authenticate_should_send_auth_header_and_extract_token ( self ) : <EOL> TOKEN = u"<STR_LIT>" <EOL> self . _mock_response ( <EOL> '<STR_LIT>' , <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" <EOL> u"<STR_LIT>" . format ( token = TOKEN ) ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( self . mock_session . auth , ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> self . assert_request_url ( '<STR_LIT>' , method = '<STR_LIT>' ) <EOL> eq_ ( TOKEN , client . _token ) <EOL> def test_get_os_type ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GETOSTYPE ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( '<STR_LIT>' , client . os_type ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_get_version ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GETVERSION ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( '<STR_LIT>' , client . version ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_new_version ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . CHECKNEWVERSION ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( { '<STR_LIT:url>' : '<STR_LIT>' , '<STR_LIT:version>' : <NUM_LIT:0> } , client . new_version ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_sync_folders ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GETSYNCFOLDERS ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT:A>' * <NUM_LIT:32> , <EOL> '<STR_LIT:size>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : '<STR_LIT:B>' * <NUM_LIT:32> <EOL> } ] , client . sync_folders ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_generate_secret ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GENERATESECRET ) <EOL> client = self . _make_client ( ) <EOL> secrets = client . generate_secret ( ) <EOL> eq_ ( '<STR_LIT>' , secrets [ '<STR_LIT>' ] ) <EOL> eq_ ( '<STR_LIT>' , secrets [ '<STR_LIT>' ] ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_get_username ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GETUSERNAME ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( '<STR_LIT>' , client . username ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_add_sync_folder_succeeded ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . ADDSYNCFOLDER_SUCCESS ) <EOL> client = self . _make_client ( ) <EOL> client . add_sync_folder ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' ) <EOL> @ raises ( btsync . BtsyncException ) <EOL> def test_add_sync_folder_failed ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . ADDSYNCFOLDER_ERROR ) <EOL> client = self . _make_client ( ) <EOL> client . add_sync_folder ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_add_sync_folder_force_succeeded ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . ADDSYNCFOLDER_SUCCESS ) <EOL> client = self . _make_client ( ) <EOL> client . add_sync_folder ( '<STR_LIT>' , '<STR_LIT>' , force = True ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_remove_sync_folder ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . REMOVEFOLDER ) <EOL> client = self . _make_client ( ) <EOL> client . remove_sync_folder ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' ) <EOL> def test_settings ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GETSETTINGS ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } , client . settings ) <EOL> self . assert_request_url ( '<STR_LIT>' ) <EOL> def test_get_folder_preference ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GETFOLDERPREF ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , client . get_folder_preference ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' ) <EOL> def test_set_folder_preference ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . SETFOLDERPREF ) <EOL> client = self . _make_client ( ) <EOL> client . set_folder_preference ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_generate_invite ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GENERATEINVITE ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( '<STR_LIT>' , client . generate_invite ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' ) <EOL> def test_generate_readonly_invite ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . GENERATEROINVITE ) <EOL> client = self . _make_client ( ) <EOL> eq_ ( '<STR_LIT>' , <EOL> client . generate_invite ( '<STR_LIT>' , '<STR_LIT>' , readonly = True ) ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' ) <EOL> def test_update_secret ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . UPDATESECRET ) <EOL> client = self . _make_client ( ) <EOL> client . update_secret ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_set_settings ( self ) : <EOL> self . _mock_token ( ) <EOL> self . _mock_response ( '<STR_LIT>' , fixtures . SETSETTINGS ) <EOL> client = self . _make_client ( ) <EOL> client . set_settings ( { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } ) <EOL> self . assert_request_url ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) </s>
