def test_get_remote_data_handles_api_error(mocker): """ Ensure any error encountered when accessing the API is logged but the caller handles the exception. """ mock_api = mocker.MagicMock() mock_api.get_sources.side_effect = Exception('BANG!') with pytest.raises(Exception): get_remote_data(mock_api)
def test_get_remote_data(mocker): """ In the good case, a tuple of results is returned. """ # Some source, submission and reply objects from the API. mock_api = mocker.MagicMock() source = make_remote_source() mock_api.get_sources.return_value = [ source, ] submission = mocker.MagicMock() mock_api.get_submissions.return_value = [ submission, ] reply = mocker.MagicMock() mock_api.get_all_replies.return_value = [ reply, ] sources, submissions, replies = get_remote_data(mock_api) assert sources == [ source, ] assert submissions == [ submission, ] assert replies == [ reply, ]
def call_api(self, api_client: API, session: Session) -> Any: ''' Override ApiJob. Download new metadata, update the local database, import new keys, and then the success signal will let the controller know to add any new download jobs. ''' # TODO: Once https://github.com/freedomofpress/securedrop-client/issues/648, we will want to # pass the default request timeout to api calls instead of setting it on the api object # directly. api_client.default_request_timeout = 40 remote_sources, remote_submissions, remote_replies = get_remote_data( api_client) update_local_storage(session, self.gpg, remote_sources, remote_submissions, remote_replies, self.data_dir)