fix: make log_task_progress resilient to DB errors and fix test assertions

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-17 11:40:34 +00:00
parent 6c7f36cb3c
commit 13a3c41482
3 changed files with 58 additions and 50 deletions
+1 -1
View File
@@ -921,7 +921,7 @@ class TestBulkReprocessExceptions:
db_session.commit()
# Cause an exception during task queuing
with patch("app.tasks.process_document.process_document") as mock_task:
with patch("app.api.files.process_document") as mock_task:
mock_task.delay.side_effect = Exception("Task queue error")
response = client.post("/api/files/bulk-reprocess", json=[file.id])
assert response.status_code == 200 # Errors are collected in response
+12 -8
View File
@@ -122,8 +122,9 @@ class TestUploadToSFTP:
mock_settings.sftp_port = 22
mock_settings.sftp_username = "testuser"
with pytest.raises(FileNotFoundError):
upload_to_sftp.apply(args=["/nonexistent/file.pdf"])
result = upload_to_sftp.apply(args=["/nonexistent/file.pdf"])
assert isinstance(result.result, Exception)
assert "File not found" in str(result.result)
@patch("app.tasks.upload_to_sftp.settings")
def test_upload_missing_configuration(self, mock_settings, tmp_path):
@@ -159,8 +160,9 @@ class TestUploadToSFTP:
mock_ssh = MagicMock()
mock_ssh_class.return_value = mock_ssh
with pytest.raises(Exception, match="No authentication method"):
upload_to_sftp.apply(args=[str(test_file)])
result = upload_to_sftp.apply(args=[str(test_file)])
assert isinstance(result.result, Exception)
assert "No authentication method" in str(result.result)
@patch("app.tasks.upload_to_sftp.paramiko.SSHClient")
@patch("app.tasks.upload_to_sftp.settings")
@@ -205,6 +207,7 @@ class TestUploadToSFTP:
mock_settings.sftp_port = 22
mock_settings.sftp_username = "testuser"
mock_settings.sftp_password = "testpass"
mock_settings.sftp_private_key = None
mock_settings.sftp_folder = ""
mock_settings.workdir = str(tmp_path)
mock_settings.sftp_disable_host_key_verification = False
@@ -215,9 +218,10 @@ class TestUploadToSFTP:
mock_sftp.put.side_effect = Exception("Upload failed")
mock_ssh_class.return_value = mock_ssh
with pytest.raises(Exception, match="Upload failed"):
upload_to_sftp.apply(args=[str(test_file)])
result = upload_to_sftp.apply(args=[str(test_file)])
assert isinstance(result.result, Exception)
assert "Upload failed" in str(result.result)
# Verify cleanup was attempted
mock_sftp.close.assert_called_once()
mock_ssh.close.assert_called_once()
mock_sftp.close.assert_called()
mock_ssh.close.assert_called()