コード例 #1
0
ファイル: test_export.py プロジェクト: rmol/securedrop-client
def test_print_error(mocker):
    """
    Ensure TemporaryDirectory is used when creating and sending the archive containing the file to
    print 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.print_call_failure = mocker.MagicMock()
    export.print_call_failure.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    error = ExportError("[mock_filepath]")
    _run_print = mocker.patch.object(export, "_run_print", side_effect=error)
    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_failure.emit.assert_called_once_with(error)
    export.export_completed.emit.assert_called_once_with(["path1", "path2"])
コード例 #2
0
def test_print_error(mocker):
    '''
    Ensure TemporaryDirectory is used when creating and sending the archive containing the file to
    print 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.print_call_failure = mocker.MagicMock()
    export.print_call_failure.emit = mocker.MagicMock()
    export.export_completed = mocker.MagicMock()
    export.export_completed.emit = mocker.MagicMock()
    error = ExportError('[mock_filepath]')
    _run_print = mocker.patch.object(export, '_run_print', side_effect=error)
    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_failure.emit.assert_called_once_with(error)
    export.export_completed.emit.assert_called_once_with(['path1', 'path2'])