예제 #1
0
def test_send_file_to_usb_device(mocker):
    """
    Ensure TemporaryDirectory is used when creating and sending the archive containing the export
    file 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.export_usb_call_success = mocker.MagicMock()
    export.export_usb_call_success.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    _run_disk_export = mocker.patch.object(export, "_run_disk_export")
    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_success.emit.assert_called_once_with()
    export.export_completed.emit.assert_called_once_with(["path1", "path2"])
예제 #2
0
def test_send_file_to_usb_device(mocker):
    '''
    Ensure TemporaryDirectory is used when creating and sending the archive containing the export
    file 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.export_usb_call_success = mocker.MagicMock()
    export.export_usb_call_success.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    _run_disk_export = mocker.patch.object(export, '_run_disk_export')
    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_success.emit.assert_called_once_with()
    export.export_completed.emit.assert_called_once_with(['path1', 'path2'])