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>
This commit is contained in:
google-labs-jules[bot]
2026-03-23 14:20:59 +00:00
parent 084171395d
commit be500e1a2b
+21
View File
@@ -47,6 +47,27 @@ class TestProcessEndpoints:
data = response.json() data = response.json()
assert data["task_id"] == "test-task-id" assert data["task_id"] == "test-task-id"
assert data["status"] == "queued" 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): def test_send_to_paperless_file_not_found(self, client):
"""Test POST /api/send_to_paperless/ with non-existent file.""" """Test POST /api/send_to_paperless/ with non-existent file."""