diff --git a/app.py b/app.py index da5192b..10d902a 100644 --- a/app.py +++ b/app.py @@ -731,7 +731,7 @@ async def new_batch_import(): container_name = data["container_name"] user_id = container_name - folder_name = data["folder_name"] + folder_name = data.get("folder_name") if folder_name == "" : folder_name = None nb_pictures = data["nb_pictures"] @@ -772,12 +772,13 @@ async def upload_picture(): container_name = data["container_name"] user_id = container_name seed_name = data["seed_name"] + seed_id = data.get("seed_id") zoom_level = data["zoom_level"] nb_seeds = data["nb_seeds"] image_base64 = data["image"] picture_set_id = data["session_id"] - if not (container_name and seed_name and image_base64 and picture_set_id): + if not (container_name and (seed_name or seed_id) and image_base64 and picture_set_id): raise BatchImportError( "wrong request arguments: either seed_name, session_id, container_name or image is wrong") @@ -788,11 +789,11 @@ async def upload_picture(): _, encoded_data = image_base64.split(",", 1) image_bytes = base64.b64decode(encoded_data) - image_hash_value = await azure_storage.generate_hash(image_bytes) + connection = datastore.get_connection() cursor = datastore.get_cursor(connection) - response = await datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, [image_hash_value], seed_name, zoom_level, nb_seeds) + response = await datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, [image_bytes], seed_name, seed_id, zoom_level, nb_seeds) datastore.end_query(connection, cursor) if response: diff --git a/storage/datastore_storage_api.py b/storage/datastore_storage_api.py index cb7dcc3..9955efc 100644 --- a/storage/datastore_storage_api.py +++ b/storage/datastore_storage_api.py @@ -103,9 +103,9 @@ async def get_picture_id(cursor, user_id, image, container_client) : picture_id = await nachet_datastore.upload_picture_unknown(cursor, str(user_id), image, container_client) return picture_id -def upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name: str, zoom_level: float = None, nb_seeds: int = None) : +def upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name, seed_id: str, zoom_level: float = None, nb_seeds: int = None) : try : - return nachet_datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name, zoom_level, nb_seeds) + return nachet_datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name, seed_id, zoom_level, nb_seeds) except Exception as error: raise DatastoreError(error) diff --git a/tests/test_image_batch_import.py b/tests/test_image_batch_import.py index 26f9ea7..b88ef4d 100644 --- a/tests/test_image_batch_import.py +++ b/tests/test_image_batch_import.py @@ -164,6 +164,7 @@ def setUp(self): self.session_id = result_json.get("session_id") self.seed_name = "Ambrosia artemisiifolia" + self.seed_id = "14e96554-aadf-42e4-8665-d141354800d1" self.zoom_level = None self.nb_seeds = None current_dir = os.path.dirname(__file__) @@ -204,6 +205,7 @@ def test_upload_picture_successfull(self): "container_name": self.container_name, "session_id": self.session_id, "seed_name": self.seed_name, + "seed_id" : self.seed_id, "zoom_level": self.zoom_level, "nb_seeds": self.nb_seeds, "image": self.image @@ -230,6 +232,7 @@ def test_upload_picture_missing_arguments_error(self): "container_name": self.container_name, # missing session_id "seed_name": self.seed_name, + "seed_id" : self.seed_id, "zoom_level": self.zoom_level, "nb_seeds": self.nb_seeds, "image": self.image @@ -257,6 +260,7 @@ def test_upload_picture_wrong_arguments_error(self): "container_name": "", # wrong container_name "session_id": self.session_id, "seed_name": self.seed_name, + "seed_id" : self.seed_id, "zoom_level": self.zoom_level, "nb_seeds": self.nb_seeds, "image": self.image