Merge pull request #605 from christianlouis/copilot/enable-disable-storage-locations

feat(storage): explicit enable/disable flag per global storage destination
This commit is contained in:
Christian Krakau-Louis
2026-03-12 08:51:14 +01:00
committed by GitHub
7 changed files with 359 additions and 28 deletions
+143 -4
View File
@@ -163,6 +163,121 @@ class TestShouldUploadFunctions:
assert _should_upload_to_icloud() is False
@pytest.mark.unit
class TestShouldUploadEnabledFlag:
"""Test that the _should_upload_to_* functions respect the explicit enabled flag."""
@patch("app.tasks.send_to_all.settings")
def test_dropbox_disabled_with_credentials(self, mock_settings):
"""Test Dropbox upload is blocked when disabled even with valid credentials."""
mock_settings.dropbox_enabled = False
mock_settings.dropbox_app_key = "key"
mock_settings.dropbox_app_secret = "secret"
mock_settings.dropbox_refresh_token = "token"
assert _should_upload_to_dropbox() is False
@patch("app.tasks.send_to_all.settings")
def test_nextcloud_disabled_with_credentials(self, mock_settings):
"""Test Nextcloud upload is blocked when disabled even with valid credentials."""
mock_settings.nextcloud_enabled = False
mock_settings.nextcloud_upload_url = "https://nextcloud.example.com"
mock_settings.nextcloud_username = "user"
mock_settings.nextcloud_password = "pass"
assert _should_upload_to_nextcloud() is False
@patch("app.tasks.send_to_all.settings")
def test_paperless_disabled_with_credentials(self, mock_settings):
"""Test Paperless upload is blocked when disabled even with valid credentials."""
mock_settings.paperless_enabled = False
mock_settings.paperless_ngx_api_token = "token"
mock_settings.paperless_host = "https://paperless.example.com"
assert _should_upload_to_paperless() is False
@patch("app.tasks.send_to_all.settings")
def test_google_drive_disabled_with_credentials(self, mock_settings):
"""Test Google Drive upload is blocked when disabled even with valid credentials."""
mock_settings.google_drive_enabled = False
mock_settings.google_drive_use_oauth = False
mock_settings.google_drive_credentials_json = '{"type": "service_account"}'
mock_settings.google_drive_folder_id = "folder_id"
assert _should_upload_to_google_drive() is False
@patch("app.tasks.send_to_all.settings")
def test_webdav_disabled_with_credentials(self, mock_settings):
"""Test WebDAV upload is blocked when disabled even with valid credentials."""
mock_settings.webdav_enabled = False
mock_settings.webdav_url = "https://webdav.example.com"
mock_settings.webdav_username = "user"
mock_settings.webdav_password = "pass"
assert _should_upload_to_webdav() is False
@patch("app.tasks.send_to_all.settings")
def test_ftp_disabled_with_credentials(self, mock_settings):
"""Test FTP upload is blocked when disabled even with valid credentials."""
mock_settings.ftp_enabled = False
mock_settings.ftp_host = "ftp.example.com"
mock_settings.ftp_username = "user"
mock_settings.ftp_password = "pass"
assert _should_upload_to_ftp() is False
@patch("app.tasks.send_to_all.settings")
def test_sftp_disabled_with_credentials(self, mock_settings):
"""Test SFTP upload is blocked when disabled even with valid credentials."""
mock_settings.sftp_enabled = False
mock_settings.sftp_host = "sftp.example.com"
mock_settings.sftp_username = "user"
mock_settings.sftp_password = "pass"
mock_settings.sftp_private_key = None
assert _should_upload_to_sftp() is False
@patch("app.tasks.send_to_all.settings")
def test_email_disabled_with_credentials(self, mock_settings):
"""Test email upload is blocked when disabled even with valid credentials."""
mock_settings.dest_email_enabled = False
mock_settings.dest_email_host = "smtp.example.com"
mock_settings.dest_email_username = "user"
mock_settings.dest_email_password = "pass"
mock_settings.dest_email_default_recipient = "recipient@example.com"
assert _should_upload_to_email() is False
@patch("app.tasks.send_to_all.settings")
def test_onedrive_disabled_with_credentials(self, mock_settings):
"""Test OneDrive upload is blocked when disabled even with valid credentials."""
mock_settings.onedrive_enabled = False
mock_settings.onedrive_client_id = "client_id"
mock_settings.onedrive_client_secret = "client_secret"
mock_settings.onedrive_refresh_token = "refresh_token"
assert _should_upload_to_onedrive() is False
@patch("app.tasks.send_to_all.settings")
def test_s3_disabled_with_credentials(self, mock_settings):
"""Test S3 upload is blocked when disabled even with valid credentials."""
mock_settings.s3_enabled = False
mock_settings.s3_bucket_name = "my-bucket"
mock_settings.aws_access_key_id = "key_id"
mock_settings.aws_secret_access_key = "secret_key"
assert _should_upload_to_s3() is False
@patch("app.tasks.send_to_all.settings")
def test_icloud_disabled_with_credentials(self, mock_settings):
"""Test iCloud upload is blocked when disabled even with valid credentials."""
mock_settings.icloud_enabled = False
mock_settings.icloud_username = "user@example.com"
mock_settings.icloud_password = "app-specific-password"
assert _should_upload_to_icloud() is False
@pytest.mark.unit
class TestGetConfiguredServicesFromValidator:
"""Test get_configured_services_from_validator function."""
@@ -171,9 +286,9 @@ class TestGetConfiguredServicesFromValidator:
def test_returns_configured_services(self, mock_get_status):
"""Test that configured services are returned correctly."""
mock_get_status.return_value = {
"Dropbox": {"configured": True},
"NextCloud": {"configured": False},
"S3 Storage": {"configured": True},
"Dropbox": {"configured": True, "enabled": True},
"NextCloud": {"configured": False, "enabled": True},
"S3 Storage": {"configured": True, "enabled": True},
}
result = get_configured_services_from_validator()
@@ -186,7 +301,7 @@ class TestGetConfiguredServicesFromValidator:
def test_handles_missing_providers(self, mock_get_status):
"""Test handling when some providers are not in status."""
mock_get_status.return_value = {
"Dropbox": {"configured": True},
"Dropbox": {"configured": True, "enabled": True},
}
result = get_configured_services_from_validator()
@@ -194,6 +309,30 @@ class TestGetConfiguredServicesFromValidator:
assert result["dropbox"] is True
# Other services not in result
@patch("app.tasks.send_to_all.get_provider_status")
def test_configured_but_disabled_service_not_active(self, mock_get_status):
"""Test that a configured but disabled service is not returned as active."""
mock_get_status.return_value = {
"Dropbox": {"configured": True, "enabled": False},
"S3 Storage": {"configured": True, "enabled": True},
}
result = get_configured_services_from_validator()
assert result["dropbox"] is False
assert result["s3"] is True
@patch("app.tasks.send_to_all.get_provider_status")
def test_missing_enabled_field_defaults_to_true_for_backward_compatibility(self, mock_get_status):
"""Test that missing 'enabled' key defaults to True (backward compatible)."""
mock_get_status.return_value = {
"Dropbox": {"configured": True},
}
result = get_configured_services_from_validator()
assert result["dropbox"] is True
@pytest.mark.unit
class TestSendToAllDestinations: