def test_APICallRunner_call_api(): """ A result is obtained so emit True and put the result in self.result. """ mock_api_call = mock.MagicMock(return_value='foo') mock_api_call.__name__ = 'my_function' mock_current_object = mock.MagicMock() cr = APICallRunner(mock_api_call, mock_current_object, 'foo', bar='baz') cr.call_finished = mock.MagicMock() cr.call_api() assert cr.result == 'foo' cr.call_finished.emit.assert_called_once_with()
def test_APICallRunner_with_exception(): """ An exception has occured so emit False. """ ex = Exception('boom') mock_api_call = mock.MagicMock(side_effect=ex) mock_api_call.__name__ = 'my_function' cr = APICallRunner(mock_api_call, 'foo', bar='baz') cr.call_finished = mock.MagicMock() with mock.patch('securedrop_client.logic.QTimer') as mock_timer: cr.call_api() assert cr.result == ex cr.call_finished.emit.assert_called_once_with(False)
def test_APICallRunner_call_api(): """ A result is obtained so emit True and put the result in self.result. """ mock_api_call = mock.MagicMock(return_value='foo') mock_api_call.__name__ = 'my_function' cr = APICallRunner(mock_api_call, 'foo', bar='baz') cr.call_finished = mock.MagicMock() with mock.patch('securedrop_client.logic.QTimer') as mock_timer: cr.call_api() assert cr.timer == mock_timer() assert cr.result == 'foo' cr.call_finished.emit.assert_called_once_with(True)