From be500e1a2ba993d867e56c4034fb2661bf27746c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:20:59 +0000 Subject: [PATCH] Add explicit tests for send_to_dropbox_endpoint Adds missing unit tests for the send_to_dropbox_endpoint in app/api/process.py, covering both success (queued) and error (file not found) states to ensure better robustness and API reliability. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_api_process.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_api_process.py b/tests/test_api_process.py index 0d70042f..94a4154d 100644 --- a/tests/test_api_process.py +++ b/tests/test_api_process.py @@ -47,6 +47,27 @@ class TestProcessEndpoints: data = response.json() assert data["task_id"] == "test-task-id" assert data["status"] == "queued" + mock_task.delay.assert_called_once_with(str(test_file)) + + def test_send_to_dropbox_endpoint_file_not_found(self, client): + """Test POST /api/send_to_dropbox/ directly mapping to endpoint name with non-existent file.""" + response = client.post("/api/send_to_dropbox/?file_path=nonexistent_endpoint.pdf") + assert response.status_code == 400 + + def test_send_to_dropbox_endpoint_success(self, client, tmp_path): + """Test POST /api/send_to_dropbox/ directly mapping to endpoint name with existing file.""" + test_file = tmp_path / "processed" / "test_endpoint.pdf" + test_file.parent.mkdir(parents=True) + test_file.write_text("test content endpoint") + + with patch("app.api.process.upload_to_dropbox") as mock_task: + mock_task.delay.return_value = Mock(id="test-task-id-endpoint") + response = client.post(f"/api/send_to_dropbox/?file_path={test_file}") + assert response.status_code == 200 + data = response.json() + assert data["task_id"] == "test-task-id-endpoint" + assert data["status"] == "queued" + mock_task.delay.assert_called_once_with(str(test_file)) def test_send_to_paperless_file_not_found(self, client): """Test POST /api/send_to_paperless/ with non-existent file."""