fix: resolve 48 lint errors in test files

- Remove whitespace from 22 blank lines (W293)
- Remove 6 unused imports (F401): os, Mock, MagicMock, Path
- Add missing imports for 12 test functions (F821): sanitize_filename, extract_remote_path, MagicMock
- Fix 1 unsorted import block (I001)

All ruff checks now pass successfully.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-15 10:24:48 +00:00
parent bbb596dbd1
commit e24f83fdd0
11 changed files with 61 additions and 48 deletions
+1 -3
View File
@@ -361,9 +361,7 @@ class TestOAuthLogin:
result = await oauth_login(mock_request)
assert result == "oauth_redirect"
mock_authentik.authorize_redirect.assert_called_once_with(
mock_request, "http://localhost/oauth-callback"
)
mock_authentik.authorize_redirect.assert_called_once_with(mock_request, "http://localhost/oauth-callback")
@pytest.mark.unit
+1 -1
View File
@@ -1,6 +1,6 @@
"""Tests for app/api/diagnostic.py module."""
from unittest.mock import MagicMock, patch
from unittest.mock import patch
import pytest
+2 -1
View File
@@ -517,9 +517,10 @@ class TestSplitPdfBySizeEdgeCases:
def test_returns_empty_list_for_zero_page_pdf(self, tmp_path):
"""Test handling of PDF with zero pages."""
from app.utils.file_splitting import split_pdf_by_size
from pypdf import PdfWriter
from app.utils.file_splitting import split_pdf_by_size
# Create a technically valid but empty PDF
empty_pdf = tmp_path / "empty.pdf"
writer = PdfWriter()
+23 -3
View File
@@ -425,6 +425,8 @@ class TestSanitizeFilenameEdgeCases:
def test_handles_empty_string(self):
"""Test with empty string."""
from app.utils.filename_utils import sanitize_filename
result = sanitize_filename("")
# Should return a default document name
assert "document_" in result
@@ -432,23 +434,31 @@ class TestSanitizeFilenameEdgeCases:
def test_handles_only_periods(self):
"""Test with only periods."""
from app.utils.filename_utils import sanitize_filename
result = sanitize_filename("...")
# Should return a default document name
assert "document_" in result
def test_handles_only_dots(self):
"""Test with single dot."""
from app.utils.filename_utils import sanitize_filename
result = sanitize_filename(".")
# Should return a default document name
assert "document_" in result
def test_preserves_multiple_extensions(self):
"""Test that multiple extensions are preserved."""
from app.utils.filename_utils import sanitize_filename
result = sanitize_filename("file.tar.gz")
assert ".tar.gz" in result or "file_tar_gz" in result
def test_removes_null_bytes(self):
"""Test that null bytes are removed."""
from app.utils.filename_utils import sanitize_filename
result = sanitize_filename("file\x00name.pdf")
assert "\x00" not in result
assert "file" in result
@@ -456,6 +466,8 @@ class TestSanitizeFilenameEdgeCases:
def test_handles_unicode_characters(self):
"""Test handling of unicode characters."""
from app.utils.filename_utils import sanitize_filename
result = sanitize_filename("文档.pdf")
# Should preserve unicode or convert safely
assert ".pdf" in result
@@ -468,31 +480,39 @@ class TestExtractRemotePathEdgeCases:
def test_file_not_in_base_dir(self):
"""Test when file is not a subdirectory of base_dir."""
from app.utils.filename_utils import extract_remote_path
result = extract_remote_path("/other/path/file.pdf", "/base/dir", "/remote")
# Should just use filename
assert result == "remote/file.pdf"
def test_multiple_processed_directories(self):
"""Test path with multiple 'processed' directories."""
result = extract_remote_path(
"/base/processed/subdir/processed/file.pdf", "/base", "/remote"
)
from app.utils.filename_utils import extract_remote_path
result = extract_remote_path("/base/processed/subdir/processed/file.pdf", "/base", "/remote")
# Should remove all 'processed' directories
assert "processed" not in result.lower()
def test_remote_base_with_trailing_slash(self):
"""Test remote base that already has trailing slash."""
from app.utils.filename_utils import extract_remote_path
result = extract_remote_path("/base/file.pdf", "/base", "/remote/")
# Should handle gracefully
assert result.startswith("remote/")
def test_empty_remote_base(self):
"""Test with empty remote base."""
from app.utils.filename_utils import extract_remote_path
result = extract_remote_path("/base/subdir/file.pdf", "/base", "")
assert result == "subdir/file.pdf"
def test_windows_style_separators(self, monkeypatch):
"""Test handling of Windows-style path separators."""
from app.utils.filename_utils import extract_remote_path
result = extract_remote_path("/base/subdir/file.pdf", "/base", "/remote")
# Should use forward slashes in output
assert "\\" not in result
+3 -10
View File
@@ -1,6 +1,5 @@
"""Tests for app/tasks/send_to_all.py module."""
import os
from unittest.mock import MagicMock, patch
import pytest
@@ -247,9 +246,7 @@ class TestSendToAllDestinations:
@patch("app.tasks.send_to_all.settings")
@patch("app.tasks.send_to_all._should_upload_to_dropbox")
@patch("app.tasks.send_to_all.upload_to_dropbox")
def test_with_file_id_parameter(
self, mock_upload, mock_should, mock_settings, mock_session_local, tmp_path
):
def test_with_file_id_parameter(self, mock_upload, mock_should, mock_settings, mock_session_local, tmp_path):
"""Test send_to_all with explicit file_id parameter."""
test_file = tmp_path / "test.pdf"
test_file.write_text("test")
@@ -267,9 +264,7 @@ class TestSendToAllDestinations:
@patch("app.tasks.send_to_all.settings")
@patch("app.tasks.send_to_all.get_configured_services_from_validator")
@patch("app.tasks.send_to_all.upload_to_dropbox")
def test_uses_validator_when_enabled(
self, mock_upload, mock_validator, mock_settings, tmp_path
):
def test_uses_validator_when_enabled(self, mock_upload, mock_validator, mock_settings, tmp_path):
"""Test that validator is used when use_validator=True."""
test_file = tmp_path / "test.pdf"
test_file.write_text("test")
@@ -299,9 +294,7 @@ class TestSendToAllDestinations:
@patch("app.tasks.send_to_all.settings")
@patch("app.tasks.send_to_all._should_upload_to_dropbox")
@patch("app.tasks.send_to_all.upload_to_dropbox")
def test_handles_upload_task_queue_error(
self, mock_upload, mock_should, mock_settings, tmp_path
):
def test_handles_upload_task_queue_error(self, mock_upload, mock_should, mock_settings, tmp_path):
"""Test handling when queueing upload task fails."""
test_file = tmp_path / "test.pdf"
test_file.write_text("test")
+1 -1
View File
@@ -8,7 +8,7 @@ Focuses on:
- Mixed encryption states
"""
from unittest.mock import patch
from unittest.mock import MagicMock, patch
import pytest
from sqlalchemy.exc import SQLAlchemyError
-1
View File
@@ -1,6 +1,5 @@
"""Tests for app/tasks/upload_to_s3.py module."""
import os
from unittest.mock import MagicMock, patch
import pytest
+1 -2
View File
@@ -1,7 +1,6 @@
"""Tests for app/tasks/upload_to_sftp.py module."""
import os
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import MagicMock, patch
import paramiko
import pytest
-1
View File
@@ -1,6 +1,5 @@
"""Tests for app/views/license_routes.py module."""
from pathlib import Path
from unittest.mock import mock_open, patch
import pytest
+6 -2
View File
@@ -242,7 +242,9 @@ class TestContainerInfoDetection:
@patch("app.views.status.os.path.exists")
@patch("builtins.open", side_effect=IOError("Permission denied"))
@pytest.mark.asyncio
async def test_handles_cgroup_read_error(self, mock_file, mock_exists, mock_settings, mock_templates, mock_providers):
async def test_handles_cgroup_read_error(
self, mock_file, mock_exists, mock_settings, mock_templates, mock_providers
):
"""Test handles cgroup file read errors."""
from app.views.status import status_dashboard
@@ -269,7 +271,9 @@ class TestContainerInfoDetection:
@patch("app.views.status.os.path.exists")
@patch("builtins.open", new_callable=mock_open, read_data="12:cpuset:/system.slice\n13:memory:/user.slice")
@pytest.mark.asyncio
async def test_handles_cgroup_without_docker(self, mock_file, mock_exists, mock_settings, mock_templates, mock_providers):
async def test_handles_cgroup_without_docker(
self, mock_file, mock_exists, mock_settings, mock_templates, mock_providers
):
"""Test handles cgroup without docker in path."""
from app.views.status import status_dashboard