Example #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"])
Example #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'])
Example #3
0
def test_print(mocker):
    """
    Ensure TemporaryDirectory is used when creating and sending the archive containing the file to
    print and that the success 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.print_call_success = mocker.MagicMock()
    export.print_call_success.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    _run_print = mocker.patch.object(export, "_run_print")
    mocker.patch("os.path.exists", return_value=True)

    export.print(["path1", "path2"])

    _run_print.assert_called_once_with("mock_temp_dir", ["path1", "path2"])
    export.print_call_success.emit.assert_called_once_with()
    export.export_completed.emit.assert_called_once_with(["path1", "path2"])
Example #4
0
def test_print(mocker):
    '''
    Ensure TemporaryDirectory is used when creating and sending the archive containing the file to
    print and that the success 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.print_call_success = mocker.MagicMock()
    export.print_call_success.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    _run_print = mocker.patch.object(export, '_run_print')
    mocker.patch('os.path.exists', return_value=True)

    export.print(['path1', 'path2'])

    _run_print.assert_called_once_with('mock_temp_dir', ['path1', 'path2'])
    export.print_call_success.emit.assert_called_once_with()
    export.export_completed.emit.assert_called_once_with(['path1', 'path2'])