arkindex-base-worker 0.4.0rc3__py3-none-any.whl → 0.4.0rc5__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.
Files changed (26) hide show
  1. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/METADATA +15 -14
  2. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/RECORD +24 -16
  3. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/WHEEL +1 -1
  4. arkindex_worker/cache.py +1 -1
  5. arkindex_worker/worker/__init__.py +6 -2
  6. arkindex_worker/worker/entity.py +8 -19
  7. arkindex_worker/worker/process.py +5 -0
  8. tests/test_elements_worker/{test_classifications.py → test_classification.py} +86 -0
  9. tests/test_elements_worker/test_corpus.py +31 -31
  10. tests/test_elements_worker/test_element.py +427 -0
  11. tests/test_elements_worker/test_element_create_multiple.py +715 -0
  12. tests/test_elements_worker/test_element_create_single.py +528 -0
  13. tests/test_elements_worker/test_element_list_children.py +969 -0
  14. tests/test_elements_worker/test_element_list_parents.py +530 -0
  15. tests/test_elements_worker/{test_entities.py → test_entity_create.py} +42 -245
  16. tests/test_elements_worker/test_entity_list_and_check.py +160 -0
  17. tests/test_elements_worker/test_transcription_create.py +873 -0
  18. tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
  19. tests/test_elements_worker/test_transcription_list.py +450 -0
  20. tests/test_elements_worker/test_version.py +60 -0
  21. tests/test_elements_worker/test_worker.py +525 -88
  22. tests/test_image.py +181 -198
  23. tests/test_elements_worker/test_elements.py +0 -3704
  24. tests/test_elements_worker/test_transcriptions.py +0 -2252
  25. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/LICENSE +0 -0
  26. {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc5.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arkindex-base-worker
3
- Version: 0.4.0rc3
3
+ Version: 0.4.0rc5
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>
@@ -37,24 +37,25 @@ Classifier: License :: OSI Approved :: MIT License
37
37
  Classifier: Programming Language :: Python :: 3 :: Only
38
38
  Classifier: Programming Language :: Python :: 3.10
39
39
  Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
40
41
  Requires-Python: >=3.10
41
42
  Description-Content-Type: text/markdown
42
43
  License-File: LICENSE
43
- Requires-Dist: humanize ==4.10.0
44
- Requires-Dist: peewee ~=3.17
45
- Requires-Dist: Pillow ==10.4.0
46
- Requires-Dist: python-gnupg ==0.5.2
47
- Requires-Dist: shapely ==2.0.5
48
- Requires-Dist: teklia-toolbox ==0.1.7b1
49
- Requires-Dist: zstandard ==0.22.0
44
+ Requires-Dist: humanize==4.10.0
45
+ Requires-Dist: peewee~=3.17
46
+ Requires-Dist: Pillow==10.4.0
47
+ Requires-Dist: python-gnupg==0.5.2
48
+ Requires-Dist: shapely==2.0.6
49
+ Requires-Dist: teklia-toolbox==0.1.7b1
50
+ Requires-Dist: zstandard==0.22.0
50
51
  Provides-Extra: docs
51
- Requires-Dist: black ==24.4.2 ; extra == 'docs'
52
- Requires-Dist: mkdocs-material ==9.5.33 ; extra == 'docs'
53
- Requires-Dist: mkdocstrings-python ==1.11.1 ; 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"
54
55
  Provides-Extra: tests
55
- Requires-Dist: pytest ==8.3.2 ; extra == 'tests'
56
- Requires-Dist: pytest-mock ==3.14.0 ; extra == 'tests'
57
- Requires-Dist: pytest-responses ==0.5.1 ; extra == 'tests'
56
+ Requires-Dist: pytest==8.3.2; extra == "tests"
57
+ Requires-Dist: pytest-mock==3.14.0; extra == "tests"
58
+ Requires-Dist: pytest-responses==0.5.1; extra == "tests"
58
59
 
59
60
  # Arkindex base Worker
60
61
 
@@ -1,18 +1,18 @@
1
1
  arkindex_worker/__init__.py,sha256=OlgCtTC9MaWeejviY0a3iQpALcRQGMVArFVVYwTF6I8,162
2
- arkindex_worker/cache.py,sha256=FTlB0coXofn5zTNRTcVIvh709mcw4a1bPGqkwWjKs3w,11248
2
+ arkindex_worker/cache.py,sha256=qTblc_zKdYC47Wip6_O9Jf5qBkQW2ozQQrg-nsx1WuY,11221
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=m255Cle3nE_FtAXbbJj_v1aS9ClT6hpDlrUFXTPiqkI,15985
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=IAJaiiCizK4vpPmMQD0yYSB6IIoyy7yU-5JKaiuPb7o,1073
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
@@ -24,29 +24,37 @@ tests/test_base_worker.py,sha256=2EIYcd_3f9O0zB5WiGIQV0Cn9wndLvnEnSfcAE1qWWU,306
24
24
  tests/test_cache.py,sha256=ii0gyr0DrG7ChEs7pmT8hMdSguAOAcCze4bRMiFQxuk,10640
25
25
  tests/test_dataset_worker.py,sha256=gApYz0LArHr1cNn079_fa_BQABF6RVQYuM1Tc4m3NsQ,22089
26
26
  tests/test_element.py,sha256=2G9M15TLxQRmvrWM9Kw2ucnElh4kSv_oF_5FYwwAxTY,13181
27
- tests/test_image.py,sha256=J3jqB5OhcdCpB6n0UnwivxrMlne8YjFLXhq1gBMANrs,26711
27
+ tests/test_image.py,sha256=03E24JVa7TZJfuwQyfVEBe3RAq3R993IMl1AHXRr7zY,25497
28
28
  tests/test_merge.py,sha256=TuOeUS0UCz66DPOQFFhc4NQBxIjZL9f5czi4XnvGrr4,8270
29
29
  tests/test_utils.py,sha256=_WJUPnt-pM_TQ0er4yjPZy-u_LePrHq1lxwk_teky7M,2544
30
30
  tests/test_elements_worker/__init__.py,sha256=Fh4nkbbyJSMv_VtjQxnWrOqTnxXaaWI8S9WU0VrzCHs,179
31
- tests/test_elements_worker/test_classifications.py,sha256=GtVyi9bg4YTd7nyw8u6IjQZYBwFMwoVZdrfSBc5UybU,27780
31
+ tests/test_elements_worker/test_classification.py,sha256=nya7veSPR_O9G41Enodp2-o6AifMBcaSTWJP2vXSSJ4,30133
32
32
  tests/test_elements_worker/test_cli.py,sha256=a23i1pUDbXi23MUtbWwGEcLLrmc_YlrbDgOG3h66wLM,2620
33
- tests/test_elements_worker/test_corpus.py,sha256=OAbwgaQtHmcmPkcAl9Kuceun_BvMasnZvYj4_EdfugY,5483
33
+ tests/test_elements_worker/test_corpus.py,sha256=kscJyM8k1njYJJFGuvliVzn89lWh41mEyDCCawnp3W8,5483
34
34
  tests/test_elements_worker/test_dataset.py,sha256=00IlOZv9YFlZ23rGXyR-HLbKLQxGelZ1Bf9lEZYA0IY,11412
35
- tests/test_elements_worker/test_elements.py,sha256=l5YTfm0CzBTQyZvdOplhhza-gpPSz-8RVix1YUzAwhM,115497
36
- tests/test_elements_worker/test_entities.py,sha256=nrCvkdJdjsyOrbD6R-H8NvxREZxciiR6CGIObXzeg50,36182
35
+ tests/test_elements_worker/test_element.py,sha256=lb5tLjl0jsixX0OWVhBAaKLE9GKkBw79kFHDNGommaQ,12535
36
+ tests/test_elements_worker/test_element_create_multiple.py,sha256=arYFGmxc0517ZUii6k__G_UQQatuNIASTC8MXvUrSwk,21887
37
+ tests/test_elements_worker/test_element_create_single.py,sha256=Fa9zm12J2rQ3VrUe3yIlHAc7Vty_eQYb_YGnNPQB3IE,16697
38
+ tests/test_elements_worker/test_element_list_children.py,sha256=2zH4h663w3EduqpzQr-7bf9zIDzO1x2WxdUYYHsIHkI,31358
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=9Tjr9KA2yo44VFV283q_cs6XbbVguUMDNfCj-DILSJg,29353
41
+ tests/test_elements_worker/test_entity_list_and_check.py,sha256=ENBLaqbXlRUDbHRvQla3080a0HJltrWAPYWNohUA9NU,4992
37
42
  tests/test_elements_worker/test_image.py,sha256=BljMNKgec_9a5bzNzFpYZIvSbuvwsWDfdqLHVJaTa7M,2079
38
43
  tests/test_elements_worker/test_metadata.py,sha256=Xfggy-vxw5DZ3hFKx3sB7OYb2d1tu1RiNK8fvKJIaBs,22294
39
44
  tests/test_elements_worker/test_task.py,sha256=wTUWqN9UhfKmJn3IcFY75EW4I1ulRhisflmY1kmP47s,5574
40
45
  tests/test_elements_worker/test_training.py,sha256=Qxi9EzGr_uKcn2Fh5aE6jNrq1K8QKLiOiSew4upASPs,8721
41
- tests/test_elements_worker/test_transcriptions.py,sha256=iq-nR_st7Q9E_nD7knrKGY57g36J6nYSEzbPk9y-cxY,77061
42
- tests/test_elements_worker/test_worker.py,sha256=VdprIWezB3dJdE8vNOrS71RQugqUysHlveOWTQate-8,10804
46
+ tests/test_elements_worker/test_transcription_create.py,sha256=yznO9B_BVsOR0Z_VY5ZL8gJp0ZPCz_4sPUs5dXtixAg,29281
47
+ tests/test_elements_worker/test_transcription_create_with_elements.py,sha256=tmcyglgssEqMnt1Mdy_u6X1m2wgLWTo_HdWst3GrK2k,33056
48
+ tests/test_elements_worker/test_transcription_list.py,sha256=ikz7HYPCoQWTdTRCd382SB-y-T2BbigPLlIcx5Eow-I,15324
49
+ tests/test_elements_worker/test_version.py,sha256=xqCgcgukTFJzkMgYfQG-8mTbu0o2fdYjWC07FktThfw,2125
50
+ tests/test_elements_worker/test_worker.py,sha256=fnFwkcDb6tx5i7lbelifeHD-BrGz6o5UBEojPCdtuAo,23474
43
51
  worker-demo/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
52
  worker-demo/tests/conftest.py,sha256=XzNMNeg6pmABUAH8jN6eZTlZSFGLYjS3-DTXjiRN6Yc,1002
45
53
  worker-demo/tests/test_worker.py,sha256=3DLd4NRK4bfyatG5P_PK4k9P9tJHx9XQq5_ryFEEFVg,304
46
54
  worker-demo/worker_demo/__init__.py,sha256=2BPomV8ZMNf3YXJgloatKeHQCE6QOkwmsHGkO6MkQuM,125
47
55
  worker-demo/worker_demo/worker.py,sha256=Rt-DjWa5iBP08k58NDZMfeyPuFbtNcbX6nc5jFX7GNo,440
48
- arkindex_base_worker-0.4.0rc3.dist-info/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
49
- arkindex_base_worker-0.4.0rc3.dist-info/METADATA,sha256=eDT7HxTvEz2yg4U_lbzkuigNWFu4JTqaLTnY0fqSCiM,3306
50
- arkindex_base_worker-0.4.0rc3.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
51
- arkindex_base_worker-0.4.0rc3.dist-info/top_level.txt,sha256=58NuslgxQC2vT4DiqZEgO4JqJRrYa2yeNI9QvkbfGQU,40
52
- arkindex_base_worker-0.4.0rc3.dist-info/RECORD,,
56
+ arkindex_base_worker-0.4.0rc5.dist-info/LICENSE,sha256=NVshRi1efwVezMfW7xXYLrdDr2Li1AfwfGOd5WuH1kQ,1063
57
+ arkindex_base_worker-0.4.0rc5.dist-info/METADATA,sha256=EFoMgnh4SUvYV0yIdBSfA7aoaZiTA7kYrJTrH2la3mY,3338
58
+ arkindex_base_worker-0.4.0rc5.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
59
+ arkindex_base_worker-0.4.0rc5.dist-info/top_level.txt,sha256=58NuslgxQC2vT4DiqZEgO4JqJRrYa2yeNI9QvkbfGQU,40
60
+ arkindex_base_worker-0.4.0rc5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
arkindex_worker/cache.py CHANGED
@@ -380,7 +380,7 @@ def unsupported_cache(func):
380
380
  def wrapper(self, *args, **kwargs):
381
381
  results = func(self, *args, **kwargs)
382
382
 
383
- if not (self.is_read_only or self.use_cache):
383
+ if self.use_cache:
384
384
  logger.warning(
385
385
  f"This API helper `{func.__name__}` did not update the cache database"
386
386
  )
@@ -133,8 +133,12 @@ class ElementsWorker(
133
133
  Whether or not WorkerActivity support has been enabled on the DataImport
134
134
  used to run this worker.
135
135
  """
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.
136
+ if self.is_read_only or self.process_mode in [
137
+ ProcessMode.Dataset,
138
+ ProcessMode.Export,
139
+ ]:
140
+ # Worker activities are also disabled when running an ElementsWorker in a Dataset process
141
+ # and when running export processes.
138
142
  return False
139
143
  assert (
140
144
  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
 
@@ -61,3 +61,8 @@ class ProcessMode(Enum):
61
61
  """
62
62
  Dataset processes.
63
63
  """
64
+
65
+ Export = "export"
66
+ """
67
+ Export processes.
68
+ """
@@ -17,6 +17,92 @@ from . import BASE_API_CALLS
17
17
  DELETE_PARAMETER = "DELETE_PARAMETER"
18
18
 
19
19
 
20
+ def test_load_corpus_classes_api_error(responses, mock_elements_worker):
21
+ responses.add(
22
+ responses.GET,
23
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
24
+ status=418,
25
+ )
26
+
27
+ assert not mock_elements_worker.classes
28
+ with pytest.raises(
29
+ Exception, match="Stopping pagination as data will be incomplete"
30
+ ):
31
+ mock_elements_worker.load_corpus_classes()
32
+
33
+ assert len(responses.calls) == len(BASE_API_CALLS) + 5
34
+ assert [
35
+ (call.request.method, call.request.url) for call in responses.calls
36
+ ] == BASE_API_CALLS + [
37
+ # We do 5 retries
38
+ (
39
+ "GET",
40
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
41
+ ),
42
+ (
43
+ "GET",
44
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
45
+ ),
46
+ (
47
+ "GET",
48
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
49
+ ),
50
+ (
51
+ "GET",
52
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
53
+ ),
54
+ (
55
+ "GET",
56
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
57
+ ),
58
+ ]
59
+ assert not mock_elements_worker.classes
60
+
61
+
62
+ def test_load_corpus_classes(responses, mock_elements_worker):
63
+ responses.add(
64
+ responses.GET,
65
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
66
+ status=200,
67
+ json={
68
+ "count": 3,
69
+ "next": None,
70
+ "results": [
71
+ {
72
+ "id": "0000",
73
+ "name": "good",
74
+ },
75
+ {
76
+ "id": "1111",
77
+ "name": "average",
78
+ },
79
+ {
80
+ "id": "2222",
81
+ "name": "bad",
82
+ },
83
+ ],
84
+ },
85
+ )
86
+
87
+ assert not mock_elements_worker.classes
88
+ mock_elements_worker.load_corpus_classes()
89
+
90
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
91
+ assert [
92
+ (call.request.method, call.request.url) for call in responses.calls
93
+ ] == BASE_API_CALLS + [
94
+ (
95
+ "GET",
96
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/classes/",
97
+ ),
98
+ ]
99
+ assert mock_elements_worker.classes == {
100
+ "good": "0000",
101
+ "average": "1111",
102
+ "bad": "2222",
103
+ }
104
+
105
+
20
106
  def test_get_ml_class_id_load_classes(responses, mock_elements_worker):
21
107
  responses.add(
22
108
  responses.GET,
@@ -9,6 +9,37 @@ from tests import CORPUS_ID
9
9
  from tests.test_elements_worker import BASE_API_CALLS
10
10
 
11
11
 
12
+ def test_download_export_not_a_uuid(responses, mock_elements_worker):
13
+ with pytest.raises(ValueError, match="export_id is not a valid uuid."):
14
+ mock_elements_worker.download_export("mon export")
15
+
16
+
17
+ def test_download_export(responses, mock_elements_worker):
18
+ responses.add(
19
+ responses.GET,
20
+ "http://testserver/api/v1/export/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff/",
21
+ status=302,
22
+ body=b"some SQLite export",
23
+ content_type="application/x-sqlite3",
24
+ stream=True,
25
+ )
26
+
27
+ export = mock_elements_worker.download_export(
28
+ "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"
29
+ )
30
+ assert export.name == "/tmp/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"
31
+
32
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
33
+ assert [
34
+ (call.request.method, call.request.url) for call in responses.calls
35
+ ] == BASE_API_CALLS + [
36
+ (
37
+ "GET",
38
+ "http://testserver/api/v1/export/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff/",
39
+ ),
40
+ ]
41
+
42
+
12
43
  def mock_list_exports_call(responses, export_id):
13
44
  responses.add(
14
45
  responses.GET,
@@ -135,34 +166,3 @@ def test_download_latest_export(responses, mock_elements_worker):
135
166
  ("GET", f"http://testserver/api/v1/corpus/{CORPUS_ID}/export/"),
136
167
  ("GET", f"http://testserver/api/v1/export/{export_id}/"),
137
168
  ]
138
-
139
-
140
- def test_download_export_not_a_uuid(responses, mock_elements_worker):
141
- with pytest.raises(ValueError, match="export_id is not a valid uuid."):
142
- mock_elements_worker.download_export("mon export")
143
-
144
-
145
- def test_download_export(responses, mock_elements_worker):
146
- responses.add(
147
- responses.GET,
148
- "http://testserver/api/v1/export/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff/",
149
- status=302,
150
- body=b"some SQLite export",
151
- content_type="application/x-sqlite3",
152
- stream=True,
153
- )
154
-
155
- export = mock_elements_worker.download_export(
156
- "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"
157
- )
158
- assert export.name == "/tmp/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"
159
-
160
- assert len(responses.calls) == len(BASE_API_CALLS) + 1
161
- assert [
162
- (call.request.method, call.request.url) for call in responses.calls
163
- ] == BASE_API_CALLS + [
164
- (
165
- "GET",
166
- "http://testserver/api/v1/export/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff/",
167
- ),
168
- ]