arkindex-base-worker 0.4.0rc4__py3-none-any.whl → 0.4.0rc6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arkindex-base-worker
3
- Version: 0.4.0rc4
3
+ Version: 0.4.0rc6
4
4
  Summary: Base Worker to easily build Arkindex ML workflows
5
5
  Author-email: Teklia <contact@teklia.com>
6
6
  Maintainer-email: Teklia <contact@teklia.com>
@@ -41,19 +41,19 @@ Classifier: Programming Language :: Python :: 3.12
41
41
  Requires-Python: >=3.10
42
42
  Description-Content-Type: text/markdown
43
43
  License-File: LICENSE
44
- Requires-Dist: humanize==4.10.0
44
+ Requires-Dist: humanize==4.11.0
45
45
  Requires-Dist: peewee~=3.17
46
- Requires-Dist: Pillow==10.4.0
47
- Requires-Dist: python-gnupg==0.5.2
46
+ Requires-Dist: Pillow==11.0.0
47
+ Requires-Dist: python-gnupg==0.5.3
48
48
  Requires-Dist: shapely==2.0.6
49
49
  Requires-Dist: teklia-toolbox==0.1.7b1
50
- Requires-Dist: zstandard==0.22.0
50
+ Requires-Dist: zstandard==0.23.0
51
51
  Provides-Extra: docs
52
- Requires-Dist: black==24.4.2; extra == "docs"
53
- Requires-Dist: mkdocs-material==9.5.33; extra == "docs"
54
- Requires-Dist: mkdocstrings-python==1.11.1; extra == "docs"
52
+ Requires-Dist: black==24.10.0; extra == "docs"
53
+ Requires-Dist: mkdocs-material==9.5.48; extra == "docs"
54
+ Requires-Dist: mkdocstrings-python==1.12.2; extra == "docs"
55
55
  Provides-Extra: tests
56
- Requires-Dist: pytest==8.3.2; extra == "tests"
56
+ Requires-Dist: pytest==8.3.4; extra == "tests"
57
57
  Requires-Dist: pytest-mock==3.14.0; extra == "tests"
58
58
  Requires-Dist: pytest-responses==0.5.1; extra == "tests"
59
59
 
@@ -3,16 +3,16 @@ arkindex_worker/cache.py,sha256=qTblc_zKdYC47Wip6_O9Jf5qBkQW2ozQQrg-nsx1WuY,1122
3
3
  arkindex_worker/image.py,sha256=oEgVCrSHiGh3D5-UXfM6PvT17TttSxC0115irpvB3Dw,18581
4
4
  arkindex_worker/models.py,sha256=bPQzGZNs5a6z6DEcygsa8T33VOqPlMUbwKzHqlKzwbw,9923
5
5
  arkindex_worker/utils.py,sha256=q1EeLdC6ebYIH-C0LOAqw2cNpjCjVoP-Vbr-39mF4w0,9884
6
- arkindex_worker/worker/__init__.py,sha256=tcqxrox9EpOjaN2EQgXumiABKpWHLsJiynPC2_sZuOQ,15880
6
+ arkindex_worker/worker/__init__.py,sha256=0_YHeOe31KR_8ynbnYMIMwnSQTVbKkkeLGmnlTMhFx0,16234
7
7
  arkindex_worker/worker/base.py,sha256=7Pmw-UQSxV-xkW8NO5cXsxJ8W8szzyppMaNjq_az81A,19844
8
8
  arkindex_worker/worker/classification.py,sha256=zECSNzGCZFzoPoDVZN4kuGYRNLzMQLBaRt3q1jnBSaA,10952
9
9
  arkindex_worker/worker/corpus.py,sha256=0TQFOwZ6Te-CZi6lgkZY1wzyJ5wO9LAmcVQtqHvZpPk,2291
10
10
  arkindex_worker/worker/dataset.py,sha256=LwzKwNFX4FqfLxh29LSvJydPwRw3VHaB1wjuFhUshsE,5267
11
11
  arkindex_worker/worker/element.py,sha256=Qvvq9kJnAHNATHW7zi96eIY1x-0MsR-T5rrSJg6e9Y4,45309
12
- arkindex_worker/worker/entity.py,sha256=ThhP22xOYR5Z4P1VH_pOl_y_uDKZFeQVDqxO6aRkIhg,15227
12
+ arkindex_worker/worker/entity.py,sha256=s5wjX6_JfTyk4qfMoV0OWfOXUx6T-9WpOiEpaoaCEFM,14808
13
13
  arkindex_worker/worker/image.py,sha256=t_Az6IGnj0EZyvcA4XxfPikOUjn_pztgsyxTkFZhaXU,621
14
14
  arkindex_worker/worker/metadata.py,sha256=VRajtd2kaBvar9GercX4knvR6l1WFYjoCdJWU9ccKgk,7291
15
- arkindex_worker/worker/process.py,sha256=I1rBt3Y8bV4zcPr8N1E2NRZ0UClSTqhExsO9CPcP41E,1012
15
+ arkindex_worker/worker/process.py,sha256=9TEHpMcBax1wc6PrWMMrdXe2uNfqyVj7n_dAYZRBGnY,1854
16
16
  arkindex_worker/worker/task.py,sha256=r1j7_qbdNu2Z8H8HbGzO3P3qdx-2N1pBbUPFDca0rqg,1519
17
17
  arkindex_worker/worker/training.py,sha256=H8FmCdzGcDW-WMMwcgvmZPlN5tPHwGo0BXn12qmzj8g,10875
18
18
  arkindex_worker/worker/transcription.py,sha256=52RY9kYsiR1sz9FxOigyo12Ker3VDbQ4U42gK9DpR3g,21146
@@ -37,24 +37,25 @@ tests/test_elements_worker/test_element_create_multiple.py,sha256=arYFGmxc0517ZU
37
37
  tests/test_elements_worker/test_element_create_single.py,sha256=Fa9zm12J2rQ3VrUe3yIlHAc7Vty_eQYb_YGnNPQB3IE,16697
38
38
  tests/test_elements_worker/test_element_list_children.py,sha256=2zH4h663w3EduqpzQr-7bf9zIDzO1x2WxdUYYHsIHkI,31358
39
39
  tests/test_elements_worker/test_element_list_parents.py,sha256=TXeGW-a3W-7GmB2QrhJH9mMnvxuybeAwQ4tL3iIxwXo,16734
40
- tests/test_elements_worker/test_entity_create.py,sha256=TkEoQDmwuP1AlSYf42WXJVMMa0lIEPMn6PGy5ExA_5c,31343
40
+ tests/test_elements_worker/test_entity_create.py,sha256=9Tjr9KA2yo44VFV283q_cs6XbbVguUMDNfCj-DILSJg,29353
41
41
  tests/test_elements_worker/test_entity_list_and_check.py,sha256=ENBLaqbXlRUDbHRvQla3080a0HJltrWAPYWNohUA9NU,4992
42
42
  tests/test_elements_worker/test_image.py,sha256=BljMNKgec_9a5bzNzFpYZIvSbuvwsWDfdqLHVJaTa7M,2079
43
43
  tests/test_elements_worker/test_metadata.py,sha256=Xfggy-vxw5DZ3hFKx3sB7OYb2d1tu1RiNK8fvKJIaBs,22294
44
+ tests/test_elements_worker/test_process.py,sha256=y4RoVhPfyHzR795fw7-_FXElBcKo3fy4Ew_HI-kxJic,3088
44
45
  tests/test_elements_worker/test_task.py,sha256=wTUWqN9UhfKmJn3IcFY75EW4I1ulRhisflmY1kmP47s,5574
45
46
  tests/test_elements_worker/test_training.py,sha256=Qxi9EzGr_uKcn2Fh5aE6jNrq1K8QKLiOiSew4upASPs,8721
46
47
  tests/test_elements_worker/test_transcription_create.py,sha256=yznO9B_BVsOR0Z_VY5ZL8gJp0ZPCz_4sPUs5dXtixAg,29281
47
48
  tests/test_elements_worker/test_transcription_create_with_elements.py,sha256=tmcyglgssEqMnt1Mdy_u6X1m2wgLWTo_HdWst3GrK2k,33056
48
49
  tests/test_elements_worker/test_transcription_list.py,sha256=ikz7HYPCoQWTdTRCd382SB-y-T2BbigPLlIcx5Eow-I,15324
49
50
  tests/test_elements_worker/test_version.py,sha256=xqCgcgukTFJzkMgYfQG-8mTbu0o2fdYjWC07FktThfw,2125
50
- tests/test_elements_worker/test_worker.py,sha256=fnFwkcDb6tx5i7lbelifeHD-BrGz6o5UBEojPCdtuAo,23474
51
+ tests/test_elements_worker/test_worker.py,sha256=pLUgjyrrXrzVD6T-kdH1ppk5Yn_iDuI8JdFGweTEMXE,25156
51
52
  worker-demo/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
53
  worker-demo/tests/conftest.py,sha256=XzNMNeg6pmABUAH8jN6eZTlZSFGLYjS3-DTXjiRN6Yc,1002
53
54
  worker-demo/tests/test_worker.py,sha256=3DLd4NRK4bfyatG5P_PK4k9P9tJHx9XQq5_ryFEEFVg,304
54
55
  worker-demo/worker_demo/__init__.py,sha256=2BPomV8ZMNf3YXJgloatKeHQCE6QOkwmsHGkO6MkQuM,125
55
56
  worker-demo/worker_demo/worker.py,sha256=Rt-DjWa5iBP08k58NDZMfeyPuFbtNcbX6nc5jFX7GNo,440
56
- arkindex_base_worker-0.4.0rc4.dist-info/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
57
- arkindex_base_worker-0.4.0rc4.dist-info/METADATA,sha256=Du-kBAZ-QL6SjvASaOK1Nxsw8yqN8Efx4L1JR-dA720,3338
58
- arkindex_base_worker-0.4.0rc4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
59
- arkindex_base_worker-0.4.0rc4.dist-info/top_level.txt,sha256=58NuslgxQC2vT4DiqZEgO4JqJRrYa2yeNI9QvkbfGQU,40
60
- arkindex_base_worker-0.4.0rc4.dist-info/RECORD,,
57
+ arkindex_base_worker-0.4.0rc6.dist-info/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
58
+ arkindex_base_worker-0.4.0rc6.dist-info/METADATA,sha256=gJd_0X7A26nuBe2EsIPHwap1XV2KnJBq2QwjBBB3Wi0,3339
59
+ arkindex_base_worker-0.4.0rc6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
60
+ arkindex_base_worker-0.4.0rc6.dist-info/top_level.txt,sha256=58NuslgxQC2vT4DiqZEgO4JqJRrYa2yeNI9QvkbfGQU,40
61
+ arkindex_base_worker-0.4.0rc6.dist-info/RECORD,,
@@ -27,7 +27,7 @@ from arkindex_worker.worker.element import ElementMixin
27
27
  from arkindex_worker.worker.entity import EntityMixin
28
28
  from arkindex_worker.worker.image import ImageMixin
29
29
  from arkindex_worker.worker.metadata import MetaDataMixin, MetaType # noqa: F401
30
- from arkindex_worker.worker.process import ActivityState, ProcessMode
30
+ from arkindex_worker.worker.process import ActivityState, ProcessMixin, ProcessMode
31
31
  from arkindex_worker.worker.task import TaskMixin
32
32
  from arkindex_worker.worker.transcription import TranscriptionMixin
33
33
  from arkindex_worker.worker.version import WorkerVersionMixin
@@ -44,6 +44,7 @@ class ElementsWorker(
44
44
  EntityMixin,
45
45
  MetaDataMixin,
46
46
  ImageMixin,
47
+ ProcessMixin,
47
48
  ):
48
49
  """
49
50
  Base class for ML workers that operate on Arkindex elements.
@@ -119,6 +120,9 @@ class ElementsWorker(
119
120
  return list(
120
121
  chain.from_iterable(map(self.list_set_elements, self.list_sets()))
121
122
  )
123
+ elif self.process_mode == ProcessMode.Export:
124
+ # For export mode processes, use list_process_elements and return element IDs
125
+ return {item["id"] for item in self.list_process_elements()}
122
126
 
123
127
  invalid_element_ids = list(filter(invalid_element_id, out))
124
128
  assert (
@@ -133,8 +137,12 @@ class ElementsWorker(
133
137
  Whether or not WorkerActivity support has been enabled on the DataImport
134
138
  used to run this worker.
135
139
  """
136
- if self.is_read_only or self.process_mode == ProcessMode.Dataset:
137
- # Worker activities are also disabled when running an ElementsWorker in a Dataset process.
140
+ if self.is_read_only or self.process_mode in [
141
+ ProcessMode.Dataset,
142
+ ProcessMode.Export,
143
+ ]:
144
+ # Worker activities are also disabled when running an ElementsWorker in a Dataset process
145
+ # and when running export processes.
138
146
  return False
139
147
  assert (
140
148
  self.process_information
@@ -16,9 +16,6 @@ from arkindex_worker.cache import (
16
16
  )
17
17
  from arkindex_worker.models import Element, Transcription
18
18
  from arkindex_worker.utils import (
19
- DEFAULT_BATCH_SIZE,
20
- batch_publication,
21
- make_batches,
22
19
  pluralize,
23
20
  )
24
21
 
@@ -219,12 +216,10 @@ class EntityMixin:
219
216
  return transcription_ent
220
217
 
221
218
  @unsupported_cache
222
- @batch_publication
223
219
  def create_transcription_entities(
224
220
  self,
225
221
  transcription: Transcription,
226
222
  entities: list[Entity],
227
- batch_size: int = DEFAULT_BATCH_SIZE,
228
223
  ) -> list[dict[str, str]]:
229
224
  """
230
225
  Create multiple entities attached to a transcription in a single API request.
@@ -247,8 +242,6 @@ class EntityMixin:
247
242
  confidence (float or None)
248
243
  Optional confidence score, between 0.0 and 1.0.
249
244
 
250
- :param batch_size: The size of each batch, which will be used to split the publication to avoid API errors.
251
-
252
245
  :return: List of dicts, with each dict having a two keys, `transcription_entity_id` and `entity_id`, holding the UUID of each created object.
253
246
  """
254
247
  assert transcription and isinstance(
@@ -300,18 +293,14 @@ class EntityMixin:
300
293
  )
301
294
  return
302
295
 
303
- created_entities = [
304
- created_entity
305
- for batch in make_batches(entities, "entity", batch_size)
306
- for created_entity in self.api_client.request(
307
- "CreateTranscriptionEntities",
308
- id=transcription.id,
309
- body={
310
- "worker_run_id": self.worker_run_id,
311
- "entities": batch,
312
- },
313
- )["entities"]
314
- ]
296
+ created_entities = self.api_client.request(
297
+ "CreateTranscriptionEntities",
298
+ id=transcription.id,
299
+ body={
300
+ "worker_run_id": self.worker_run_id,
301
+ "entities": entities,
302
+ },
303
+ )["entities"]
315
304
 
316
305
  return created_entities
317
306
 
@@ -1,5 +1,11 @@
1
+ from collections.abc import Iterator
1
2
  from enum import Enum
2
3
 
4
+ from arkindex_worker.cache import unsupported_cache
5
+
6
+ # Increases the number of elements returned per page by the API
7
+ PROCESS_ELEMENTS_PAGE_SIZE = 500
8
+
3
9
 
4
10
  class ActivityState(Enum):
5
11
  """
@@ -61,3 +67,26 @@ class ProcessMode(Enum):
61
67
  """
62
68
  Dataset processes.
63
69
  """
70
+
71
+ Export = "export"
72
+ """
73
+ Export processes.
74
+ """
75
+
76
+
77
+ class ProcessMixin:
78
+ @unsupported_cache
79
+ def list_process_elements(self, with_image: bool = False) -> Iterator[dict]:
80
+ """
81
+ List the elements of a process.
82
+
83
+ :param with_image: whether or not to include zone and image information in the elements response.
84
+ :returns: the process' elements.
85
+ """
86
+ return self.api_client.paginate(
87
+ "ListProcessElements",
88
+ id=self.process_information["id"],
89
+ with_image=with_image,
90
+ allow_missing_data=True,
91
+ page_size=PROCESS_ELEMENTS_PAGE_SIZE,
92
+ )
@@ -13,7 +13,6 @@ from arkindex_worker.cache import (
13
13
  CachedTranscriptionEntity,
14
14
  )
15
15
  from arkindex_worker.models import Transcription
16
- from arkindex_worker.utils import DEFAULT_BATCH_SIZE
17
16
  from arkindex_worker.worker.transcription import TextOrientation
18
17
  from tests import CORPUS_ID
19
18
 
@@ -836,89 +835,50 @@ def test_create_transcription_entities_wrong_entity(
836
835
  )
837
836
 
838
837
 
839
- @pytest.mark.parametrize("batch_size", [DEFAULT_BATCH_SIZE, 1])
840
- def test_create_transcription_entities(batch_size, responses, mock_elements_worker):
838
+ def test_create_transcription_entities(responses, mock_elements_worker):
841
839
  transcription = Transcription(id="transcription-id")
842
840
 
843
841
  # Call to Transcription entities creation in bulk
844
- if batch_size > 1:
845
- responses.add(
846
- responses.POST,
847
- "http://testserver/api/v1/transcription/transcription-id/entities/bulk/",
848
- status=201,
849
- match=[
850
- matchers.json_params_matcher(
851
- {
852
- "worker_run_id": "56785678-5678-5678-5678-567856785678",
853
- "entities": [
854
- {
855
- "name": "Teklia",
856
- "type_id": "22222222-2222-2222-2222-222222222222",
857
- "offset": 0,
858
- "length": 6,
859
- "confidence": 1.0,
860
- },
861
- {
862
- "name": "Team Rocket",
863
- "type_id": "22222222-2222-2222-2222-222222222222",
864
- "offset": 7,
865
- "length": 11,
866
- "confidence": 1.0,
867
- },
868
- ],
869
- }
870
- )
871
- ],
872
- json={
873
- "entities": [
874
- {
875
- "transcription_entity_id": "transc-entity-id",
876
- "entity_id": "entity-id1",
877
- },
878
- {
879
- "transcription_entity_id": "transc-entity-id",
880
- "entity_id": "entity-id2",
881
- },
882
- ]
883
- },
884
- )
885
- else:
886
- for idx, (name, offset, length) in enumerate(
887
- [
888
- ("Teklia", 0, 6),
889
- ("Team Rocket", 7, 11),
890
- ],
891
- start=1,
892
- ):
893
- responses.add(
894
- responses.POST,
895
- "http://testserver/api/v1/transcription/transcription-id/entities/bulk/",
896
- status=201,
897
- match=[
898
- matchers.json_params_matcher(
899
- {
900
- "worker_run_id": "56785678-5678-5678-5678-567856785678",
901
- "entities": [
902
- {
903
- "name": name,
904
- "type_id": "22222222-2222-2222-2222-222222222222",
905
- "offset": offset,
906
- "length": length,
907
- "confidence": 1.0,
908
- }
909
- ],
910
- }
911
- )
912
- ],
913
- json={
842
+ responses.add(
843
+ responses.POST,
844
+ "http://testserver/api/v1/transcription/transcription-id/entities/bulk/",
845
+ status=201,
846
+ match=[
847
+ matchers.json_params_matcher(
848
+ {
849
+ "worker_run_id": "56785678-5678-5678-5678-567856785678",
914
850
  "entities": [
915
851
  {
916
- "transcription_entity_id": "transc-entity-id",
917
- "entity_id": f"entity-id{idx}",
918
- }
919
- ]
920
- },
852
+ "name": "Teklia",
853
+ "type_id": "22222222-2222-2222-2222-222222222222",
854
+ "offset": 0,
855
+ "length": 6,
856
+ "confidence": 1.0,
857
+ },
858
+ {
859
+ "name": "Team Rocket",
860
+ "type_id": "22222222-2222-2222-2222-222222222222",
861
+ "offset": 7,
862
+ "length": 11,
863
+ "confidence": 1.0,
864
+ },
865
+ ],
866
+ }
921
867
  )
868
+ ],
869
+ json={
870
+ "entities": [
871
+ {
872
+ "transcription_entity_id": "transc-entity-id",
873
+ "entity_id": "entity-id1",
874
+ },
875
+ {
876
+ "transcription_entity_id": "transc-entity-id",
877
+ "entity_id": "entity-id2",
878
+ },
879
+ ]
880
+ },
881
+ )
922
882
 
923
883
  # Store entity type/slug correspondence on the worker
924
884
  mock_elements_worker.entity_types = {
@@ -942,26 +902,16 @@ def test_create_transcription_entities(batch_size, responses, mock_elements_work
942
902
  "confidence": 1.0,
943
903
  },
944
904
  ],
945
- batch_size=batch_size,
946
905
  )
947
906
 
948
907
  assert len(created_objects) == 2
949
908
 
950
- bulk_api_calls = [
909
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
910
+ assert [
911
+ (call.request.method, call.request.url) for call in responses.calls
912
+ ] == BASE_API_CALLS + [
951
913
  (
952
914
  "POST",
953
915
  "http://testserver/api/v1/transcription/transcription-id/entities/bulk/",
954
916
  )
955
917
  ]
956
- if batch_size != DEFAULT_BATCH_SIZE:
957
- bulk_api_calls.append(
958
- (
959
- "POST",
960
- "http://testserver/api/v1/transcription/transcription-id/entities/bulk/",
961
- )
962
- )
963
-
964
- assert len(responses.calls) == len(BASE_API_CALLS) + len(bulk_api_calls)
965
- assert [
966
- (call.request.method, call.request.url) for call in responses.calls
967
- ] == BASE_API_CALLS + bulk_api_calls
@@ -0,0 +1,89 @@
1
+ import pytest
2
+
3
+ from tests import PROCESS_ID
4
+
5
+
6
+ @pytest.mark.parametrize(
7
+ ("with_image", "elements"),
8
+ [
9
+ (
10
+ False,
11
+ [
12
+ {
13
+ "id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
14
+ "type_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
15
+ "name": "element 1",
16
+ "confidence": 1,
17
+ "image_id": None,
18
+ "image_width": None,
19
+ "image_height": None,
20
+ "image_url": None,
21
+ "polygon": None,
22
+ "rotation_angle": 0,
23
+ "mirrored": False,
24
+ },
25
+ {
26
+ "id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
27
+ "type_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
28
+ "name": "element 2",
29
+ "confidence": 1,
30
+ "image_id": None,
31
+ "image_width": None,
32
+ "image_height": None,
33
+ "image_url": None,
34
+ "polygon": None,
35
+ "rotation_angle": 0,
36
+ "mirrored": False,
37
+ },
38
+ ],
39
+ ),
40
+ (
41
+ True,
42
+ [
43
+ {
44
+ "id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
45
+ "type_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
46
+ "name": "element 1",
47
+ "confidence": 1,
48
+ "image_id": "aaa2aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
49
+ "image_width": 76,
50
+ "image_height": 138,
51
+ "image_url": "http://somewhere.com/iiif/image.jpeg",
52
+ "polygon": [[0, 0], [0, 40], [20, 40], [20, 0]],
53
+ "rotation_angle": 0,
54
+ "mirrored": False,
55
+ },
56
+ {
57
+ "id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
58
+ "type_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
59
+ "name": "element 2",
60
+ "confidence": 1,
61
+ "image_id": "aaa2aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
62
+ "image_width": 138,
63
+ "image_height": 76,
64
+ "image_url": "http://somewhere.com/iiif/image.jpeg",
65
+ "polygon": [[0, 0], [0, 40], [20, 40], [20, 0]],
66
+ "rotation_angle": 0,
67
+ "mirrored": False,
68
+ },
69
+ ],
70
+ ),
71
+ ],
72
+ )
73
+ def test_list_process_elements_with_image(
74
+ responses, mock_elements_worker, with_image, elements
75
+ ):
76
+ responses.add(
77
+ responses.GET,
78
+ f"http://testserver/api/v1/process/{PROCESS_ID}/elements/?page_size=500&with_count=true&with_image={with_image}",
79
+ status=200,
80
+ json={
81
+ "count": 2,
82
+ "next": None,
83
+ "results": elements,
84
+ },
85
+ )
86
+ assert (
87
+ list(mock_elements_worker.list_process_elements(with_image=with_image))
88
+ == elements
89
+ )
@@ -16,6 +16,7 @@ from arkindex_worker.models import Element
16
16
  from arkindex_worker.worker import ActivityState, ElementsWorker
17
17
  from arkindex_worker.worker.dataset import DatasetState
18
18
  from arkindex_worker.worker.process import ProcessMode
19
+ from tests import PROCESS_ID
19
20
 
20
21
  from . import BASE_API_CALLS
21
22
 
@@ -523,6 +524,51 @@ def test_get_elements_both_args_error(mocker, mock_elements_worker, tmp_path):
523
524
  worker.get_elements()
524
525
 
525
526
 
527
+ def test_get_elements_export_process(mock_elements_worker, responses):
528
+ responses.add(
529
+ responses.GET,
530
+ f"http://testserver/api/v1/process/{PROCESS_ID}/elements/?page_size=500&with_count=true&with_image=False",
531
+ status=200,
532
+ json={
533
+ "count": 2,
534
+ "next": None,
535
+ "results": [
536
+ {
537
+ "id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
538
+ "type_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
539
+ "name": "element 1",
540
+ "confidence": 1,
541
+ "image_id": None,
542
+ "image_width": None,
543
+ "image_height": None,
544
+ "image_url": None,
545
+ "polygon": None,
546
+ "rotation_angle": 0,
547
+ "mirrored": False,
548
+ },
549
+ {
550
+ "id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
551
+ "type_id": "baaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
552
+ "name": "element 2",
553
+ "confidence": 1,
554
+ "image_id": None,
555
+ "image_width": None,
556
+ "image_height": None,
557
+ "image_url": None,
558
+ "polygon": None,
559
+ "rotation_angle": 0,
560
+ "mirrored": False,
561
+ },
562
+ ],
563
+ },
564
+ )
565
+ mock_elements_worker.process_information["mode"] = "export"
566
+ assert set(mock_elements_worker.get_elements()) == {
567
+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
568
+ "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
569
+ }
570
+
571
+
526
572
  @pytest.mark.usefixtures("_mock_worker_run_api")
527
573
  def test_activities_disabled(responses, monkeypatch):
528
574
  """Test worker process elements without updating activities when they are disabled for the process"""