def test_should_call_failure_callback_with_exception(self, mocker): mock_exception = Exception('something goes wrong!') mock_failure_callback = mocker.Mock() mocker.patch.object( Analytics, 'send_logs_to_fb', side_effect=mock_exception) dummy_zip_file = BytesIO(b'not important') cli_utils.send_logs_to_fb(dummy_zip_file, failure_callback=mock_failure_callback) mock_failure_callback.assert_called_with(mock_exception)
def test_should_call_failure_callback_with_exception(self): mock_failure_callback = Mock() mock_exception = Exception("something goes wrong!") dummy_zip_file = BytesIO(b"not important") with patch.object(Analytics, "send_logs_to_fb", side_effect=mock_exception): cli_utils.send_logs_to_fb(dummy_zip_file, failure_callback=mock_failure_callback) mock_failure_callback.assert_called_with(mock_exception)
def handle_upload_results(output, zipped_logs_file_handle): if send: click.echo('Sending logs to Facebook\nPlease wait...') cli_utils.send_logs_to_fb( zipped_logs_file_handle, success_callback=send_logs_result_interactive_success, failure_callback=send_result_interactive_failure) elif not opt_out: click.echo('Sending report to Facebook\nPlease wait...') cli_utils.send_results_to_fb( output, success_callback=send_usage_result_interactive_success, failure_callback=send_result_interactive_failure)
def test_should_call_success_callback_with_run_id(self, mocker): mock_success_callback = mocker.Mock() mock_run_id = '1234abcd' mocker.patch.object( Analytics, 'send_logs_to_fb', return_value=mock_run_id) dummy_zip_file = BytesIO(b'not important') cli_utils.send_logs_to_fb(dummy_zip_file, success_callback=mock_success_callback) Analytics.send_logs_to_fb.assert_called() mock_success_callback.assert_called_with(mock_run_id)
def test_should_call_success_callback_with_run_id(self): mock_success_callback = Mock() mock_run_id = "1234abcd" dummy_zip_file = BytesIO(b"not important") with patch.object(Analytics, "send_logs_to_fb", return_value=mock_run_id): cli_utils.send_logs_to_fb(dummy_zip_file, success_callback=mock_success_callback) Analytics.send_logs_to_fb.assert_called() mock_success_callback.assert_called_with(mock_run_id)
def handle_upload_results(output, zipped_logs_file_handle): if send: send_logs_result = cli_utils.send_logs_to_fb( zipped_logs_file_handle, success_callback=send_logs_result_json_success, failure_callback=send_result_json_failure) output.update(send_logs_result) elif not opt_out: cli_utils.send_results_to_fb( output, success_callback=send_usage_result_json_success, failure_callback=send_result_json_failure) click.echo(json.dumps(output))