예제 #1
0
def test_send_file_to_usb_device_error(mocker):
    """
    Ensure TemporaryDirectory is used when creating and sending the archive containing the export
    file and that the failure signal is emitted.
    """
    mock_temp_dir = mocker.MagicMock()
    mock_temp_dir.__enter__ = mocker.MagicMock(return_value="mock_temp_dir")
    mocker.patch("securedrop_client.export.TemporaryDirectory",
                 return_value=mock_temp_dir)
    export = Export()
    export.export_usb_call_failure = mocker.MagicMock()
    export.export_usb_call_failure.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    error = ExportError("[mock_filepath]")
    _run_disk_export = mocker.patch.object(export,
                                           "_run_disk_export",
                                           side_effect=error)
    mocker.patch("os.path.exists", return_value=True)

    export.send_file_to_usb_device(["path1", "path2"], "mock passphrase")

    _run_disk_export.assert_called_once_with("mock_temp_dir",
                                             ["path1", "path2"],
                                             "mock passphrase")
    export.export_usb_call_failure.emit.assert_called_once_with(error)
    export.export_completed.emit.assert_called_once_with(["path1", "path2"])
예제 #2
0
def test_send_file_to_usb_device_error(mocker):
    '''
    Ensure TemporaryDirectory is used when creating and sending the archive containing the export
    file and that the failure signal is emitted.
    '''
    mock_temp_dir = mocker.MagicMock()
    mock_temp_dir.__enter__ = mocker.MagicMock(return_value='mock_temp_dir')
    mocker.patch('securedrop_client.export.TemporaryDirectory',
                 return_value=mock_temp_dir)
    export = Export()
    export.export_usb_call_failure = mocker.MagicMock()
    export.export_usb_call_failure.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    error = ExportError('[mock_filepath]')
    _run_disk_export = mocker.patch.object(export,
                                           '_run_disk_export',
                                           side_effect=error)
    mocker.patch('os.path.exists', return_value=True)

    export.send_file_to_usb_device(['path1', 'path2'], 'mock passphrase')

    _run_disk_export.assert_called_once_with('mock_temp_dir',
                                             ['path1', 'path2'],
                                             'mock passphrase')
    export.export_usb_call_failure.emit.assert_called_once_with(error)
    export.export_completed.emit.assert_called_once_with(['path1', 'path2'])