Skip to content
Snippets Groups Projects
Commit 3ff90ed9 authored by ml bonhomme's avatar ml bonhomme :bee: Committed by Erwan Rouchet
Browse files

Rename CreateElementsWorkflow to CreateProcess

parent 26574c38
No related branches found
No related tags found
1 merge request!2046Rename CreateElementsWorkflow to CreateProcess
......@@ -65,9 +65,9 @@ from arkindex.process.serializers.files import DataFileCreateSerializer, DataFil
from arkindex.process.serializers.git import ExternalRepositorySerializer, RevisionSerializer
from arkindex.process.serializers.imports import (
ApplyProcessTemplateSerializer,
CorpusProcessSerializer,
CreateImportTranskribusErrorResponseSerializer,
CreateProcessTemplateSerializer,
ElementsWorkflowSerializer,
FilesProcessSerializer,
ImportTranskribusSerializer,
ProcessDetailsSerializer,
......@@ -473,18 +473,18 @@ class FilesProcess(CreateAPIView):
@extend_schema_view(
post=extend_schema(
operation_id='CreateElementsWorkflow',
operation_id='CreateProcess',
tags=['process'],
responses={201: ProcessSerializer},
)
)
class CorpusWorkflow(SelectionMixin, CorpusACLMixin, CreateAPIView):
class CorpusProcess(SelectionMixin, CorpusACLMixin, CreateAPIView):
"""
Create a distributed process from elements of an Arkindex corpus.\n\n
Requires an **admin** access to the corpus.
"""
permission_classes = (IsVerified, )
serializer_class = ElementsWorkflowSerializer
serializer_class = CorpusProcessSerializer
@transaction.atomic
def create(self, request, pk=None, **kwargs):
......
......@@ -462,7 +462,7 @@ class ApplyProcessTemplateSerializer(ProcessACLMixin, serializers.Serializer):
return data
class ElementsWorkflowSerializer(serializers.Serializer):
class CorpusProcessSerializer(serializers.Serializer):
# TODO: Rewrite this as a ModelSerializer and merge the validation code from the API into it
corpus = serializers.UUIDField()
......
......@@ -13,9 +13,9 @@ from arkindex.project.tests import FixtureAPITestCase
from arkindex.users.models import Role
class TestCreateElementsWorkflow(FixtureAPITestCase):
class TestCreateProcess(FixtureAPITestCase):
"""
Test creating Workers processes with CreateElementsWorkflow
Test creating Workers processes with CreateProcess
"""
@classmethod
......@@ -52,11 +52,11 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
ARKINDEX_TASKS_IMAGE='tasks:latest',
PONOS_DEFAULT_ENV={'env': {'SOME_VAR': 'somevalue'}}
)
def test_page_workflow(self):
def test_page_process(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element_type': 'page',
......@@ -108,10 +108,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.assertEqual(init_task.image, 'tasks:latest')
self.assertEqual(init_task.command, f'python -m arkindex_tasks.init_elements {process.id} --chunks-number 1')
def test_volume_workflow(self):
def test_volume_process(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element': str(self.volume.id),
......@@ -151,10 +151,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
'test_folder_id': None,
})
def test_single_page_workflow(self):
def test_single_page_process(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element': str(self.pages.first().id),
......@@ -167,27 +167,27 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
process = Process.objects.get(id=data['id'])
self.assertEqual(process.element, self.pages.first())
def test_create_element_workflow_requires_login(self):
response = self.client.post(reverse('api:corpus-workflow'), {}, format='json')
def test_create_process_requires_login(self):
response = self.client.post(reverse('api:corpus-process'), {}, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_create_element_workflow_required_fields(self):
def test_create_process_required_fields(self):
self.client.force_login(self.user)
response = self.client.post(reverse('api:corpus-workflow'), {}, format='json')
response = self.client.post(reverse('api:corpus-process'), {}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(
response.json(),
{'corpus': ['This field is required.']}
)
def test_create_element_workflow_requires_corpus_admin(self):
def test_create_process_requires_corpus_admin(self):
"""
Only an admin of the target corpus can create a workers process
"""
self.client.force_login(self.user)
self.corpus.memberships.filter(user=self.user).update(level=Role.Contributor.value)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'name': 'Test',
......@@ -197,10 +197,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(response.json(), {'corpus': ['You do not have an admin access to this corpus.']})
def test_create_element_workflow_non_readable_corpus(self):
def test_create_process_non_readable_corpus(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.private_corpus.id),
'name': 'Test',
......@@ -210,10 +210,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(response.json(), {'corpus': ['Corpus with this ID does not exist.']})
def test_create_element_workflow_name_filter(self):
def test_create_process_name_filter(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element_name_contains': self.pages.first().name[2:5],
......@@ -225,10 +225,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
process = Process.objects.get(id=data['id'])
self.assertEqual(process.name_contains, self.pages.first().name[2:5])
def test_create_element_workflow_fields_max_length(self):
def test_create_process_fields_max_length(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'name': 'A' * 200,
......@@ -244,10 +244,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
'element_type': ['Ensure this field has no more than 50 characters.'],
})
def test_create_element_workflow_type_filter(self):
def test_create_process_type_filter(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element_type': 'volume',
......@@ -259,14 +259,14 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
process = Process.objects.get(id=data['id'])
self.assertEqual(process.element_type.slug, 'volume')
def test_create_element_workflow_empty_queryset(self):
def test_create_process_empty_queryset(self):
"""
An empty QuerySet is ignored: the user can change the element filtering later,
and running a process on no elements at all is harmless.
"""
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element_type': 'volume',
......@@ -282,10 +282,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.assertEqual(process.name_contains, 'ahahah')
self.assertFalse(process.list_elements().exists())
def test_create_element_workflow_empty_selection(self):
def test_create_process_empty_selection(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'selection': True,
......@@ -303,10 +303,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
['No element match those filters.']
)
def test_create_element_workflow_wrong_type(self):
def test_create_process_wrong_type(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element_type': 'arachnid',
......@@ -318,13 +318,13 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
'element_type': ['This type does not exist in corpus "Unit Tests"']
})
def test_create_element_workflow_mixed_element_filters(self):
def test_create_process_mixed_element_filters(self):
"""
Element parameter can be set with filtering parameters
"""
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element': str(self.pages.first().id),
......@@ -338,7 +338,7 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.client.force_login(self.user)
with self.assertNumQueries(12):
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'ml_class_id': str(self.ml_class.id),
......@@ -372,7 +372,7 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
'test_folder_id': None,
})
def test_create_element_workflow_non_folder_no_zone(self):
def test_create_process_non_folder_no_zone(self):
"""
An element that is not of a folder type and has no image or polygon
should still be usable to create a process
......@@ -381,7 +381,7 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
element = self.corpus.elements.create(type=self.pages.first().type, name='Kill me please')
with self.assertNumQueries(13):
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element': str(element.id),
......@@ -428,13 +428,13 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
'test_folder_id': None,
})
def test_create_element_workflow_mixed_selection_filters(self):
def test_create_process_mixed_selection_filters(self):
"""
Element and selection fields cannot be set together
"""
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element': str(self.volume.id),
......@@ -451,7 +451,7 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
}
)
def test_create_element_workflow_selection_filter(self):
def test_create_process_selection_filter(self):
self.client.force_login(self.user)
page = self.pages.first()
self.client.post(
......@@ -460,7 +460,7 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
format='json'
)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'selection': True,
......@@ -492,10 +492,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.assertEqual(data['results'][0]['id'], str(page.id))
@override_settings(ARKINDEX_FEATURES={'selection': False})
def test_create_element_workflow_selection_no_selection(self):
def test_create_process_selection_no_selection(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'selection': True,
......@@ -505,10 +505,10 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(response.json(), {'selection': ['Selection is not available on this instance.']})
def test_create_element_workflow_process_name(self):
def test_create_process_process_name(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'name': 'blah',
......@@ -528,7 +528,7 @@ class TestCreateElementsWorkflow(FixtureAPITestCase):
self.client.force_login(self.user)
corpus_type = self.corpus.types.first()
response = self.client.post(
reverse('api:corpus-workflow'),
reverse('api:corpus-process'),
{
'corpus': str(self.corpus.id),
'element_type': corpus_type.slug,
......
......@@ -80,9 +80,9 @@ from arkindex.process.api import (
AvailableRepositoriesList,
BucketList,
ClearProcess,
CorpusProcess,
CorpusWorkersActivity,
CorpusWorkerVersionList,
CorpusWorkflow,
CreateDockerWorkerVersion,
CreateProcessTemplate,
DataFileCreate,
......@@ -279,7 +279,7 @@ api = [
path('process/files/<uuid:pk>/', DataFileList.as_view(), name='file-list'),
path('process/files/create/', DataFileCreate.as_view(), name='file-create'),
path('process/file/<uuid:pk>/', DataFileRetrieve.as_view(), name='file-retrieve'),
path('process/corpus/', CorpusWorkflow.as_view(), name='corpus-workflow'),
path('process/corpus/', CorpusProcess.as_view(), name='corpus-process'),
path('process/<uuid:pk>/workers/', WorkerRunList.as_view(), name='worker-run-list'),
path('process/workers/<uuid:pk>/', WorkerRunDetails.as_view(), name='worker-run-details'),
path('process/<uuid:pk>/elements/', ListProcessElements.as_view(), name='process-elements-list'),
......
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