From 0fc5387cf50ea494d28f31b6d43907fa3eaa48b4 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Thu, 4 May 2023 14:14:32 -0400 Subject: [PATCH] Allow single file upload --- app/api/tasks.py | 4 ++-- app/tests/test_api_task.py | 11 ----------- nodeodm/models.py | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/app/api/tasks.py b/app/api/tasks.py index f3761dfb7..8e4d9f2eb 100644 --- a/app/api/tasks.py +++ b/app/api/tasks.py @@ -181,8 +181,8 @@ def commit(self, request, pk=None, project_pk=None): task.partial = False task.images_count = len(task.scan_images()) - if task.images_count < 2: - raise exceptions.ValidationError(detail=_("You need to upload at least 2 images before commit")) + if task.images_count < 1: + raise exceptions.ValidationError(detail=_("You need to upload at least 1 file before commit")) task.save() worker_tasks.process_task.delay(task.id) diff --git a/app/tests/test_api_task.py b/app/tests/test_api_task.py index 36881c5ad..dbbf8fe86 100644 --- a/app/tests/test_api_task.py +++ b/app/tests/test_api_task.py @@ -114,13 +114,6 @@ def test_task(self): }, format="multipart") self.assertTrue(res.status_code == status.HTTP_400_BAD_REQUEST) - # Cannot create a task with just 1 image - res = client.post("/api/projects/{}/tasks/".format(project.id), { - 'images': image1 - }, format="multipart") - self.assertTrue(res.status_code == status.HTTP_400_BAD_REQUEST) - image1.seek(0) - # Normal case with images[], name and processing node parameter res = client.post("/api/projects/{}/tasks/".format(project.id), { 'images': [image1, image2], @@ -1118,10 +1111,6 @@ def test_task_chunked_uploads(self): self.assertEqual(res.data['success'], True) image1.seek(0) - # Cannot commit with a single image - res = client.post("/api/projects/{}/tasks/{}/commit/".format(project.id, task.id)) - self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) - # And second image res = client.post("/api/projects/{}/tasks/{}/upload/".format(project.id, task.id), { 'images': [image2], diff --git a/nodeodm/models.py b/nodeodm/models.py index 8c5a77f5a..39f47af89 100644 --- a/nodeodm/models.py +++ b/nodeodm/models.py @@ -114,7 +114,7 @@ def process_new_task(self, images, name=None, options=[], progress_callback=None :returns UUID of the newly created task """ - if len(images) < 2: raise exceptions.NodeServerError("Need at least 2 images") + if len(images) < 1: raise exceptions.NodeServerError("Need at least 1 file") api_client = self.api_client()