fix: return boolean values from _should_upload functions and fix test expectations

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-16 16:59:17 +00:00
parent 6b4b0deefb
commit f2eff3e2fb
3 changed files with 20 additions and 15 deletions
+1 -1
View File
@@ -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,
}
+11 -11
View File
@@ -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():
+8 -3
View File
@@ -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")