Example #1
0
 def test_files_and_folders_list_non_existing_path_fail(self, mock_client):
     path = 'non_existing_folder_path'
     args = 'ls {0}'.format(path)
     mock_client.files_list_folder.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.ListFolderError('path',
                                     files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text='')
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_list_folder.assert_called_once_with('/' + path)
     assert "ls: cannot access '/{0}'".format(path) in str(excinfo.value)
Example #2
0
 def test_create_folder_malformed_path_fail(self, mock_client):
     path = '/malformed_path/'
     mock_client.files_create_folder_v2.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.CreateFolderError(
             'path', files.WriteError('malformed_path', None)),
         user_message_locale='',
         user_message_text='')
     args = 'mkdir {0}'.format(path)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_create_folder_v2.assert_called_once_with(
         path, autorename=False)
     assert "mkdir: cannot create directory '{0}'".format(path) in str(
         excinfo.value)
Example #3
0
 def test_delete_non_existing_folder_fail(self, mock_client):
     path = '/non/existing/path'
     mock_client.files_delete_v2.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.DeleteError('path_lookup',
                                 files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text=''
     )
     args = 'rm {0}'.format(path)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_delete_v2.assert_called_once_with(path)
     assert "An error occurred while deleting '{0}':".format(
         path) in str(excinfo.value)
Example #4
0
 def test_restore_file_w_non_existing_revision_fail(self, mock_client):
     path = '/foo/bar.file'
     revision = 'b25e0155e1'
     mock_client.files_restore.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.RestoreError('invalid_revision', None),
         user_message_locale='',
         user_message_text=''
     )
     args = 'restore {0} --revision {1}'.format(path, revision)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_restore.assert_called_once_with(path, revision)
     assert "restore: cannot restore '{0}' file".format(
         os.path.basename(path)) in str(excinfo.value)
Example #5
0
 def test_show_file_revisions_non_existing_path_fail(self, mock_client):
     path = '/non/existing/path'
     mock_client.files_list_revisions.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.ListRevisionsError(
             'path', files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text=''
     )
     args = 'revs {0}'.format(path)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_list_revisions.assert_called_once_with(
         path, mode=files.ListRevisionsMode('path', None), limit=10)
     assert "revs: cannot fetch revisions for '{0}' at '{1}': ".format(
         os.path.basename(path), path) in str(excinfo.value)
Example #6
0
 def test_upload_file_insufficient_space_fail(self, mock_client, tmpdir):
     fake_file = tmpdir.join('fake_small_file.bin')
     fake_file.write('')
     args = 'put {0}'.format(fake_file)
     mock_client.files_upload.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.UploadError(
             'path', files.UploadWriteFailed(
                 reason=files.WriteError('insufficient_space', None),
                 upload_session_id='')),
         user_message_locale='',
         user_message_text=''
     )
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     assert "An error occurred while uploading '{}'".format(
         fake_file) in str(excinfo.value)
Example #7
0
 def test_show_status_non_existing_file_fail(self, mock_client):
     path = '/non/existing/path/fake.log'
     mock_client.files_get_metadata.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.GetMetadataError(
             'path', files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text=''
     )
     args = 'status {0}'.format(path)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_get_metadata.assert_called_once_with(
         path, include_media_info=False, include_deleted=False,
         include_has_explicit_shared_members=False)
     assert "status: cannot fetch metadata for '{0}'".format(path) in str(
         excinfo.value)
Example #8
0
 def test_find_file_or_folder_non_existing_path_fail(self, mock_client):
     path = '/non/existing/path'
     query = 'foo_bar'
     mock_client.files_search.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.SearchError('path',
                                 files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text=''
     )
     args = 'find {0} {1}'.format(path, query)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_search.assert_called_once_with(
         path, query, mode=files.SearchMode('filename', None),
         max_results=100, start=0)
     assert "find: cannot execute query '{0}' at '{1}': ".format(
         query, path) in str(excinfo.value)
Example #9
0
 def test_move_file_or_folder_non_existing_source_fail(self, mock_client):
     from_path = '/non/existing/path/fake.log'
     to_path = '/foo/bar/fake.log'
     mock_client.files_move_v2.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.RelocationError(
             'from_lookup', files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text=''
     )
     args = 'mv {0} {1}'.format(from_path, to_path)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_move_v2.assert_called_once_with(
         from_path, to_path, autorename=False, allow_shared_folder=False,
         allow_ownership_transfer=False)
     assert "mv: cannot move from '{0}' to '{1}': ".format(
         from_path, to_path) in str(excinfo.value)
Example #10
0
 def test_download_non_existing_file_fail(self, mock_client):
     path = '/non/existing/path/fake.log'
     dst_path = '/my/local/path/fake.log'
     mock_client.files_download_to_file.side_effect = exceptions.ApiError(
         request_id='ed9755c09d6f856ba81491ef2ec4a230',
         error=files.DownloadError(
             'path', files.LookupError('not_found', None)),
         user_message_locale='',
         user_message_text=''
     )
     args = 'get {0} {1}'.format(path, dst_path)
     with pytest.raises(error.ActionException) as excinfo:
         self.exec_command(args)
     mock_client.files_download_to_file.assert_called_once_with(dst_path,
                                                                path,
                                                                rev=None)
     assert "An error occurred while downloading '{0}'".format(
         path) in str(excinfo.value)
Example #11
0
def test_dropbox_api_to_maestral_error(error, maestral_exc):
    converted = dropbox_to_maestral_error(
        exceptions.ApiError("", error, "", ""))
    assert isinstance(converted, maestral_exc)