From f2eff3e2fbc576e42aa36025d4fd800713a5b0fe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Feb 2026 16:59:17 +0000 Subject: [PATCH] fix: return boolean values from _should_upload functions and fix test expectations Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- app/api/files.py | 2 +- app/tasks/send_to_all.py | 22 +++++++++++----------- tests/test_send_to_all.py | 11 ++++++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/api/files.py b/app/api/files.py index 42ce2a0d..2a99ea8f 100644 --- a/app/api/files.py +++ b/app/api/files.py @@ -334,7 +334,7 @@ def bulk_reprocess_files(request: Request, file_ids: List[int], db: DbSession): "status": "success" if processed_files else "error", "message": f"Successfully queued {len(processed_files)} files for reprocessing", "processed_files": processed_files, - "errors": errors if errors else None, + "errors": errors, "task_ids": task_ids, } diff --git a/app/tasks/send_to_all.py b/app/tasks/send_to_all.py index 330a2ef3..7f187d0a 100644 --- a/app/tasks/send_to_all.py +++ b/app/tasks/send_to_all.py @@ -25,21 +25,21 @@ logger = logging.getLogger(__name__) def _should_upload_to_dropbox(): - return settings.dropbox_app_key and settings.dropbox_app_secret and settings.dropbox_refresh_token + return bool(settings.dropbox_app_key and settings.dropbox_app_secret and settings.dropbox_refresh_token) def _should_upload_to_nextcloud(): - return settings.nextcloud_upload_url and settings.nextcloud_username and settings.nextcloud_password + return bool(settings.nextcloud_upload_url and settings.nextcloud_username and settings.nextcloud_password) def _should_upload_to_paperless(): - return settings.paperless_ngx_api_token and settings.paperless_host + return bool(settings.paperless_ngx_api_token and settings.paperless_host) def _should_upload_to_google_drive(): # Check for OAuth configuration if getattr(settings, "google_drive_use_oauth", False): - return ( + return bool( settings.google_drive_client_id and settings.google_drive_client_secret and settings.google_drive_refresh_token @@ -47,33 +47,33 @@ def _should_upload_to_google_drive(): ) # Or check for service account configuration else: - return settings.google_drive_credentials_json and settings.google_drive_folder_id + return bool(settings.google_drive_credentials_json and settings.google_drive_folder_id) def _should_upload_to_webdav(): - return settings.webdav_url and settings.webdav_username and settings.webdav_password + return bool(settings.webdav_url and settings.webdav_username and settings.webdav_password) def _should_upload_to_ftp(): - return settings.ftp_host and settings.ftp_username and settings.ftp_password + return bool(settings.ftp_host and settings.ftp_username and settings.ftp_password) def _should_upload_to_sftp(): - return settings.sftp_host and settings.sftp_username and (settings.sftp_password or settings.sftp_private_key) + return bool(settings.sftp_host and settings.sftp_username and (settings.sftp_password or settings.sftp_private_key)) def _should_upload_to_email(): - return ( + return bool( settings.email_host and settings.email_username and settings.email_password and settings.email_default_recipient ) def _should_upload_to_onedrive(): - return settings.onedrive_client_id and settings.onedrive_client_secret and settings.onedrive_refresh_token + return bool(settings.onedrive_client_id and settings.onedrive_client_secret and settings.onedrive_refresh_token) def _should_upload_to_s3(): - return settings.s3_bucket_name and settings.aws_access_key_id and settings.aws_secret_access_key + return bool(settings.s3_bucket_name and settings.aws_access_key_id and settings.aws_secret_access_key) def get_configured_services_from_validator(): diff --git a/tests/test_send_to_all.py b/tests/test_send_to_all.py index f87e8fc0..c72af91f 100644 --- a/tests/test_send_to_all.py +++ b/tests/test_send_to_all.py @@ -182,10 +182,15 @@ class TestGetConfiguredServicesFromValidator: class TestSendToAllDestinations: """Test send_to_all_destinations task.""" - def test_file_not_found_error(self): + @patch("app.tasks.send_to_all.log_task_progress") + def test_file_not_found_error(self, mock_log): """Test that FileNotFoundError is raised when file doesn't exist.""" - with pytest.raises(FileNotFoundError): - send_to_all_destinations.apply(args=["/nonexistent/file.pdf"]) + result = send_to_all_destinations.apply(args=["/nonexistent/file.pdf"]) + + # When task raises an exception, result.failed() returns True + assert result.failed() + # The exception should be FileNotFoundError + assert isinstance(result.result, FileNotFoundError) @patch("app.tasks.send_to_all.settings") @patch("app.tasks.send_to_all._should_upload_to_dropbox")