示例#1
0
def test_run_printer_preflight(mocker):
    """
    Ensure TemporaryDirectory is used when creating and sending the archives during the preflight
    checks and that the success signal is emitted by Export.
    """
    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.printer_preflight_success = mocker.MagicMock()
    export.printer_preflight_success.emit = mocker.MagicMock()
    _run_printer_preflight = mocker.patch.object(export,
                                                 "_run_printer_preflight")

    export.run_printer_preflight()

    _run_printer_preflight.assert_called_once_with("mock_temp_dir")
    export.printer_preflight_success.emit.assert_called_once_with()
示例#2
0
def test_run_printer_preflight_error(mocker):
    '''
    Ensure TemporaryDirectory is used when creating and sending the archives during the preflight
    checks and that the failure signal is emitted by Export.
    '''
    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.printer_preflight_failure = mocker.MagicMock()
    export.printer_preflight_failure.emit = mocker.MagicMock()
    error = ExportError('bang!')
    _run_print_preflight = mocker.patch.object(export,
                                               '_run_printer_preflight',
                                               side_effect=error)

    export.run_printer_preflight()

    _run_print_preflight.assert_called_once_with('mock_temp_dir')
    export.printer_preflight_failure.emit.assert_called_once_with(error)