From 1c04f39180b7741459eae771ab811429e820c2b6 Mon Sep 17 00:00:00 2001 From: Valentin Rigal <rigal@teklia.com> Date: Tue, 17 Dec 2019 15:57:24 +0000 Subject: [PATCH] Skip children fetching parameter for thumbnails generation only --- arkindex/dataimport/models.py | 5 ++++ .../dataimport/tests/test_workflows_api.py | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arkindex/dataimport/models.py b/arkindex/dataimport/models.py index 982680c197..9a75c7e460 100644 --- a/arkindex/dataimport/models.py +++ b/arkindex/dataimport/models.py @@ -122,6 +122,11 @@ class DataImport(IndexableModel): if elements: command = ' '.join([command, '--dataimport-id {}'.format(str(self.id))]) + # Do not retrieve elements children in case there of thumbnails generation only + thumbnails = self.payload.get('thumbnails') + if thumbnails and len(self.ml_tools) == 0: + command = ' '.join([command, '--skip-children'.format(str(self.id))]) + tasks = { import_task_name: { 'image': settings.ARKINDEX_TASKS_IMAGE, diff --git a/arkindex/dataimport/tests/test_workflows_api.py b/arkindex/dataimport/tests/test_workflows_api.py index 814aad9061..43be615e5d 100644 --- a/arkindex/dataimport/tests/test_workflows_api.py +++ b/arkindex/dataimport/tests/test_workflows_api.py @@ -499,3 +499,31 @@ class TestWorkflows(FixtureAPITestCase): 'python -m arkindex_tasks.init_elements --corpus-id {} --chunks-number 1 --dataimport-id {}' .format(str(self.corpus.id), str(dataimport.id)) ) + + def test_thumbnails_generation_only(self, ml_get_mock): + """ + Generating thumbnails without any workflow must generate an import task + which do not to retrieve filtered elements children + """ + self.client.force_login(self.user) + corpus_type = self.corpus.types.first() + response = self.client.post( + reverse('api:corpus-workflow'), + { + 'ml_tools': [], + 'corpus': str(self.corpus.id), + 'chunks': 3, + 'type': corpus_type.slug, + 'thumbnails': True + }, + format='json' + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + data = response.json() + dataimport = DataImport.objects.get(id=data['id']) + workflow = dataimport.workflow + self.assertEqual( + workflow.recipes['initialisation'].command, + 'python -m arkindex_tasks.init_elements --corpus-id {} --chunks-number 3 --type {} --skip-children' + .format(str(self.corpus.id), corpus_type.slug) + ) -- GitLab