Skip to content

Commit dd3bd93

Browse files
author
jiangpeiling
committed
♻️ Refactor: cleanup data_process_app.py
1 parent ea758ff commit dd3bd93

File tree

2 files changed

+1
-79
lines changed

2 files changed

+1
-79
lines changed

backend/apps/data_process_app.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,6 @@ async def load_image(url: str):
162162
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=f"Error loading image: {str(e)}")
163163

164164

165-
@router.get("/{task_id}")
166-
async def get_task(task_id: str):
167-
"""Get basic status information for a specific task"""
168-
task = await get_task_info(task_id)
169-
170-
if not task:
171-
raise HTTPException(
172-
status_code=HTTPStatus.NOT_FOUND, detail=f"Task with ID {task_id} not found")
173-
return JSONResponse(
174-
status_code=HTTPStatus.OK,
175-
content={
176-
"id": task["id"],
177-
"task_name": task["task_name"],
178-
"index_name": task["index_name"],
179-
"path_or_url": task["path_or_url"],
180-
"original_filename": task["original_filename"],
181-
"status": task["status"],
182-
"created_at": task["created_at"],
183-
"updated_at": task["updated_at"],
184-
"error": task["error"]
185-
}
186-
)
187-
188-
189165
@router.get("")
190166
async def list_tasks():
191167
"""Get a list of all tasks with their basic status information"""
@@ -291,7 +267,7 @@ async def process_text_file(
291267
)
292268
return JSONResponse(content=result)
293269
except Exception as e:
294-
logger.error(
270+
logger.exception(
295271
f"Error processing uploaded file {file.filename}: {str(e)}")
296272
raise HTTPException(
297273
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,

test/backend/app/test_data_process_app.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,6 @@ async def load_image():
196196
image = self.service.load_image.return_value
197197
return {"success": True, "base64": "mock_base64_data", "content_type": "image/jpeg"}
198198

199-
@self.app.get("/tasks/{task_id}")
200-
@pytest.mark.asyncio
201-
async def get_task(task_id: str):
202-
# Simulate getting task information
203-
task = self.get_task_info.return_value
204-
205-
if not task:
206-
raise HTTPException(status_code=404, detail=f"Task with ID {task_id} not found")
207-
208-
return task
209-
210199
@self.app.get("/tasks")
211200
@pytest.mark.asyncio
212201
async def list_tasks():
@@ -503,49 +492,6 @@ def test_load_image_failure(self):
503492
self.assertEqual(response.status_code, 404)
504493
self.assertIn("Failed to load image", response.json()["detail"])
505494

506-
def test_get_task_success(self):
507-
"""
508-
Test getting task information successfully.
509-
Verifies that the endpoint returns the expected task data.
510-
"""
511-
# Set up mock
512-
task_data = {
513-
"id": self.task_id,
514-
"task_name": "process_and_forward",
515-
"index_name": self.index_name,
516-
"path_or_url": self.source,
517-
"status": "SUCCESS",
518-
"created_at": "2023-01-01T12:00:00",
519-
"updated_at": "2023-01-01T12:05:00",
520-
"error": None
521-
}
522-
self.get_task_info.return_value = task_data
523-
524-
# Execute request
525-
response = self.client.get(f"/tasks/{self.task_id}")
526-
527-
# Assert expectations
528-
self.assertEqual(response.status_code, 200)
529-
result = response.json()
530-
self.assertEqual(result["id"], self.task_id)
531-
self.assertEqual(result["status"], "SUCCESS")
532-
self.assertEqual(result["index_name"], self.index_name)
533-
534-
def test_get_task_not_found(self):
535-
"""
536-
Test getting non-existent task.
537-
Verifies that the endpoint returns an appropriate error response.
538-
"""
539-
# Set up mock to return None (task not found)
540-
self.get_task_info.return_value = None
541-
542-
# Execute request
543-
response = self.client.get("/tasks/nonexistent-id")
544-
545-
# Assert expectations
546-
self.assertEqual(response.status_code, 404)
547-
self.assertIn("not found", response.json()["detail"])
548-
549495
def test_list_tasks(self):
550496
"""
551497
Test listing all tasks.

0 commit comments

Comments
 (0)