From 0f242b1ad91b08299082f3eddc5db5092d3298bb Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Tue, 9 Jul 2024 20:06:12 +0800 Subject: [PATCH] Fix a bug in images api when querying image in-queue by id --- app/Controllers/images.py | 4 +++- tests/api/test_upload.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Controllers/images.py b/app/Controllers/images.py index d16be2c..903ed95 100644 --- a/app/Controllers/images.py +++ b/app/Controllers/images.py @@ -26,7 +26,9 @@ async def query_image_by_id(image_id: Annotated[UUID, Path(description="The id o message="Success query the image with the given ID.") except PointNotFoundError as ex: if services.upload_service and image_id in services.upload_service.uploading_ids: - return QueryByIdApiResponse(img_status=ImageStatus.IN_QUEUE, message="The image is in the indexing queue.") + return QueryByIdApiResponse(img=None, + img_status=ImageStatus.IN_QUEUE, + message="The image is in the indexing queue.") raise HTTPException(404, "Cannot find the image with the given ID.") from ex diff --git a/tests/api/test_upload.py b/tests/api/test_upload.py index 55dedd6..03e6ffa 100644 --- a/tests/api/test_upload.py +++ b/tests/api/test_upload.py @@ -67,6 +67,11 @@ def validate(hashes): resp = upload(f) assert resp.status_code == 409, i + # Query by ID + query = test_client.get(f'/images/id/{image_id}') + assert query.status_code == 200 + assert query.json()['img_status'] == 'mapped' if i == 1 else 'in_queue' + # Validate val_resp = validate(test_file_hashes) assert val_resp.status_code == 200, i