def test_signal_interception(mocker, homedir): # check that initializing an app calls configure_signal_handlers mocker.patch("securedrop_client.app.QApplication") mocker.patch("securedrop_client.app.prevent_second_instance") mocker.patch("sys.exit") mocker.patch("securedrop_client.db.make_session_maker") mocker.patch("securedrop_client.app.init") mocker.patch("securedrop_client.logic.Controller.setup") mocker.patch("securedrop_client.logic.GpgHelper") mocker.patch("securedrop_client.app.configure_logging") mock_signal_handlers = mocker.patch("securedrop_client.app.configure_signal_handlers") mock_args = mocker.Mock() mock_args.sdc_home = homedir start_app(mock_args, []) assert mock_signal_handlers.called # check that a signal interception calls quit on the app mock_app = mocker.MagicMock() mock_quit = mocker.patch.object(mock_app, "quit") mock_signal = mocker.patch("signal.signal") configure_signal_handlers(mock_app) assert mock_signal.called assert not mock_quit.called signal_handler = mock_signal.call_args_list[0][0][1] signal_handler() assert mock_quit.called
def test_start_app(homedir, mocker): """ Ensure the expected things are configured and the application is started. """ mock_session_maker = mocker.MagicMock() mock_args = mocker.MagicMock() mock_qt_args = mocker.MagicMock() mock_args.sdc_home = str(homedir) mock_args.proxy = False mocker.patch("securedrop_client.app.configure_logging") mock_app = mocker.patch("securedrop_client.app.QApplication") mock_win = mocker.patch("securedrop_client.app.Window") mocker.patch("securedrop_client.resources.path", return_value=mock_args.sdc_home + "dummy.jpg") mock_controller = mocker.patch("securedrop_client.app.Controller") mocker.patch("securedrop_client.app.prevent_second_instance") mocker.patch("securedrop_client.app.sys") mocker.patch("securedrop_client.app.make_session_maker", return_value=mock_session_maker) start_app(mock_args, mock_qt_args) mock_app.assert_called_once_with(mock_qt_args) mock_win.assert_called_once_with() mock_controller.assert_called_once_with( "http://localhost:8081/", mock_win(), mock_session_maker, homedir, False, False )
def test_start_app(homedir, mocker): """ Ensure the expected things are configured and the application is started. """ mock_session_class = mocker.MagicMock() mock_args = mocker.MagicMock() mock_qt_args = mocker.MagicMock() mock_args.sdc_home = str(homedir) mock_args.proxy = False mocker.patch('securedrop_client.app.configure_logging') mock_app = mocker.patch('securedrop_client.app.QApplication') mock_win = mocker.patch('securedrop_client.app.Window') mock_controller = mocker.patch('securedrop_client.app.Controller') mocker.patch('securedrop_client.app.prevent_second_instance') mocker.patch('securedrop_client.app.sys') mocker.patch('securedrop_client.app.sessionmaker', return_value=mock_session_class) start_app(mock_args, mock_qt_args) mock_app.assert_called_once_with(mock_qt_args) mock_win.assert_called_once_with() mock_controller.assert_called_once_with('http://localhost:8081/', mock_win(), mock_session_class(), homedir, False)
def test_start_app(safe_tmpdir): """ Ensure the expected things are configured and the application is started. """ mock_session_class = mock.MagicMock() mock_args = mock.MagicMock() mock_qt_args = mock.MagicMock() sdc_home = str(safe_tmpdir) mock_args.sdc_home = sdc_home mock_args.proxy = False with mock.patch('securedrop_client.app.configure_logging'), \ mock.patch('securedrop_client.app.QApplication') as mock_app, \ mock.patch('securedrop_client.app.Window') as mock_win, \ mock.patch('securedrop_client.app.Client') as mock_client, \ mock.patch('securedrop_client.app.prevent_second_instance'), \ mock.patch('securedrop_client.app.sys'), \ mock.patch('securedrop_client.app.sessionmaker', return_value=mock_session_class): start_app(mock_args, mock_qt_args) mock_app.assert_called_once_with(mock_qt_args) mock_win.assert_called_once_with() mock_client.assert_called_once_with('http://localhost:8081/', mock_win(), mock_session_class(), sdc_home, False)
def test_signal_interception(): # check that initializing an app calls configure_signal_handlers with mock.patch('securedrop_client.app.QApplication'), \ mock.patch('securedrop_client.app.prevent_second_instance'), \ mock.patch('sys.exit'), \ mock.patch('securedrop_client.models.make_engine'), \ mock.patch('securedrop_client.app.init'), \ mock.patch('securedrop_client.logic.Client.setup'), \ mock.patch('securedrop_client.app.configure_logging'), \ mock.patch('securedrop_client.app.configure_signal_handlers') \ as mock_signal_handlers: start_app(mock.MagicMock(), []) assert mock_signal_handlers.called # check that a signal interception calls quit on the app mock_app = mock.MagicMock() with mock.patch.object(mock_app, 'quit') as mock_quit, \ mock.patch('signal.signal') as mock_signal: configure_signal_handlers(mock_app) assert mock_signal.called assert not mock_quit.called signal_handler = mock_signal.call_args_list[0][0][1] signal_handler() assert mock_quit.called
def func(): start_app(mock_args, mock_qt_args)