Skip to content
Snippets Groups Projects
Verified Commit 39a4527f authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Allow a manual TranscriptionEntity that is the same as a WorkerRun's

parent 0893cf01
No related branches found
No related tags found
1 merge request!1911Allow a manual TranscriptionEntity that is the same as a WorkerRun's
......@@ -426,12 +426,18 @@ class TranscriptionEntityCreateSerializer(serializers.ModelSerializer):
if worker_run is not None:
data['worker_version_id'] = worker_run.version_id
existing_transcription_entities = TranscriptionEntity.objects.filter(transcription=data['transcription'], entity=data['entity'], offset=data['offset'], length=data['length'])
if worker_run:
if existing_transcription_entities.filter(worker_run=worker_run).exists():
existing_transcription_entities = TranscriptionEntity.objects.filter(
transcription=data['transcription'],
entity=data['entity'],
offset=data['offset'],
length=data['length'],
worker_run=worker_run,
)
if existing_transcription_entities.exists():
if worker_run:
errors['__all__'] = ['This entity is already linked to this transcription by this worker run at this position.']
elif existing_transcription_entities.exists():
errors['__all__'] = ['This entity is already linked to this transcription at this position.']
else:
errors['__all__'] = ['This entity is already linked to this transcription at this position.']
if errors:
raise serializers.ValidationError(errors)
......
......@@ -975,6 +975,42 @@ class TestEntitiesAPI(FixtureAPITestCase):
'__all__': ['This entity is already linked to this transcription by this worker run at this position.']
})
def test_create_transcription_entity_manual_existing_worker_run(self):
"""
A manual TranscriptionEntity can be created even when one exists with the same attributes from a WorkerRun
"""
self.client.force_login(self.internal_user)
TranscriptionEntity.objects.create(
transcription=self.transcription,
entity=self.entity,
offset=4,
length=8,
worker_run=self.worker_run,
worker_version=self.worker_version_1
)
with self.assertNumQueries(6):
response = self.client.post(
reverse('api:transcription-entity-create', kwargs={'pk': str(self.transcription.id)}),
data={
'entity': str(self.entity.id),
'offset': 4,
'length': 8,
},
format='json'
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
transcription_entity = self.transcription.transcription_entities.filter(worker_run=None, entity=self.entity).get()
self.assertDictEqual(
response.json(),
{
'entity': str(transcription_entity.entity.id),
'offset': transcription_entity.offset,
'length': transcription_entity.length,
'worker_run': None,
'confidence': None
}
)
def test_create_transcription_entity_key_missing(self):
self.client.force_login(self.user)
data = self.tr_entities_sample
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment