diff --git a/arkindex_worker/worker.py b/arkindex_worker/worker.py index bddb65e038bf8633ead7119591e12d2962ea5032..b9825eae73828da19fb3c6f3380e966bd57a908c 100644 --- a/arkindex_worker/worker.py +++ b/arkindex_worker/worker.py @@ -687,7 +687,7 @@ class ElementsWorker(BaseWorker): f"A sub_element of {element.id} with type {sub_element_type} was created during transcriptions bulk creation" ) self.report.add_element(element.id, sub_element_type) - self.report.add_transcription(annotation["id"]) + self.report.add_transcription(annotation["element_id"]) if self.cache: # Store transcriptions and their associated element (if created) in local cache @@ -698,8 +698,11 @@ class ElementsWorker(BaseWorker): worker_version_id_hex = convert_str_uuid_to_hex(self.worker_version_id) for index, annotation in enumerate(annotations): transcription = transcriptions[index] - element_id_hex = convert_str_uuid_to_hex(annotation["id"]) - if annotation["created"] and annotation["id"] not in created_ids: + element_id_hex = convert_str_uuid_to_hex(annotation["element_id"]) + if ( + annotation["created"] + and annotation["element_id"] not in created_ids + ): elements_to_insert.append( CachedElement( id=element_id_hex, @@ -709,12 +712,11 @@ class ElementsWorker(BaseWorker): worker_version_id=worker_version_id_hex, ) ) - created_ids.append(annotation["id"]) + created_ids.append(annotation["element_id"]) transcriptions_to_insert.append( CachedTranscription( - # TODO: Retrieve real transcription_id through API - id=convert_str_uuid_to_hex(str(uuid.uuid4())), + id=convert_str_uuid_to_hex(annotation["id"]), element_id=element_id_hex, text=transcription["text"], confidence=transcription["score"], diff --git a/tests/test_elements_worker/test_transcriptions.py b/tests/test_elements_worker/test_transcriptions.py index 7d350e3558135638115d1e3a7ce382bdad9be287..1fa9845e39feaf79ce1fef7ef9e321990967f5f2 100644 --- a/tests/test_elements_worker/test_transcriptions.py +++ b/tests/test_elements_worker/test_transcriptions.py @@ -582,26 +582,28 @@ def test_create_element_transcriptions_api_error(responses, mock_elements_worker ] -def test_create_element_transcriptions( - mocker, responses, mock_elements_worker_with_cache -): - mocker.patch( - "uuid.uuid4", - side_effect=[ - "56785678-5678-5678-5678-567856785678", - "67896789-6789-6789-6789-678967896789", - "78907890-7890-7890-7890-789078907890", - ], - ) +def test_create_element_transcriptions(responses, mock_elements_worker_with_cache): elt = Element({"id": "12341234-1234-1234-1234-123412341234"}) responses.add( responses.POST, f"http://testserver/api/v1/element/{elt.id}/transcriptions/bulk/", status=200, json=[ - {"id": "11111111-1111-1111-1111-111111111111", "created": True}, - {"id": "22222222-2222-2222-2222-222222222222", "created": False}, - {"id": "11111111-1111-1111-1111-111111111111", "created": True}, + { + "id": "56785678-5678-5678-5678-567856785678", + "element_id": "11111111-1111-1111-1111-111111111111", + "created": True, + }, + { + "id": "67896789-6789-6789-6789-678967896789", + "element_id": "22222222-2222-2222-2222-222222222222", + "created": False, + }, + { + "id": "78907890-7890-7890-7890-789078907890", + "element_id": "11111111-1111-1111-1111-111111111111", + "created": True, + }, ], ) @@ -625,9 +627,21 @@ def test_create_element_transcriptions( "return_elements": True, } assert annotations == [ - {"id": "11111111-1111-1111-1111-111111111111", "created": True}, - {"id": "22222222-2222-2222-2222-222222222222", "created": False}, - {"id": "11111111-1111-1111-1111-111111111111", "created": True}, + { + "id": "56785678-5678-5678-5678-567856785678", + "element_id": "11111111-1111-1111-1111-111111111111", + "created": True, + }, + { + "id": "67896789-6789-6789-6789-678967896789", + "element_id": "22222222-2222-2222-2222-222222222222", + "created": False, + }, + { + "id": "78907890-7890-7890-7890-789078907890", + "element_id": "11111111-1111-1111-1111-111111111111", + "created": True, + }, ] # Check that created transcriptions and elements were properly stored in SQLite cache