arkindex-base-worker 0.4.0rc2__tar.gz → 0.4.0rc4__tar.gz

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 (68) hide show
  1. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/PKG-INFO +5 -4
  2. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_base_worker.egg-info/PKG-INFO +5 -4
  3. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_base_worker.egg-info/SOURCES.txt +12 -4
  4. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_base_worker.egg-info/requires.txt +3 -3
  5. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/cache.py +1 -1
  6. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/__init__.py +1 -2
  7. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/base.py +1 -1
  8. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/classification.py +1 -1
  9. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/corpus.py +21 -6
  10. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/entity.py +1 -1
  11. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/task.py +1 -2
  12. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/training.py +1 -1
  13. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/pyproject.toml +5 -5
  14. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_dataset_worker.py +1 -1
  15. arkindex_base_worker-0.4.0rc2/tests/test_elements_worker/test_classifications.py → arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_classification.py +87 -1
  16. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_corpus.py +32 -1
  17. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_dataset.py +1 -1
  18. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_element.py +427 -0
  19. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_element_create_multiple.py +715 -0
  20. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_element_create_single.py +528 -0
  21. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_element_list_children.py +969 -0
  22. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_element_list_parents.py +530 -0
  23. arkindex_base_worker-0.4.0rc2/tests/test_elements_worker/test_entities.py → arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_entity_create.py +1 -154
  24. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_entity_list_and_check.py +160 -0
  25. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_image.py +2 -1
  26. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_metadata.py +1 -1
  27. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_task.py +1 -1
  28. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_transcription_create.py +873 -0
  29. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
  30. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_transcription_list.py +450 -0
  31. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_version.py +60 -0
  32. arkindex_base_worker-0.4.0rc4/tests/test_elements_worker/test_worker.py +751 -0
  33. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_image.py +181 -198
  34. arkindex_base_worker-0.4.0rc2/tests/test_elements_worker/test_elements.py +0 -3704
  35. arkindex_base_worker-0.4.0rc2/tests/test_elements_worker/test_transcriptions.py +0 -2252
  36. arkindex_base_worker-0.4.0rc2/tests/test_elements_worker/test_worker.py +0 -314
  37. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/LICENSE +0 -0
  38. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/README.md +0 -0
  39. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_base_worker.egg-info/dependency_links.txt +0 -0
  40. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_base_worker.egg-info/top_level.txt +0 -0
  41. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/__init__.py +0 -0
  42. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/image.py +0 -0
  43. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/models.py +0 -0
  44. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/utils.py +0 -0
  45. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/dataset.py +0 -0
  46. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/element.py +0 -0
  47. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/image.py +0 -0
  48. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/metadata.py +0 -0
  49. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/process.py +0 -0
  50. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/transcription.py +0 -0
  51. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/arkindex_worker/worker/version.py +0 -0
  52. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/hooks/pre_gen_project.py +0 -0
  53. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/setup.cfg +0 -0
  54. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/__init__.py +0 -0
  55. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/conftest.py +0 -0
  56. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_base_worker.py +0 -0
  57. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_cache.py +0 -0
  58. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_element.py +0 -0
  59. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/__init__.py +0 -0
  60. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_cli.py +0 -0
  61. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_elements_worker/test_training.py +0 -0
  62. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_merge.py +0 -0
  63. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/tests/test_utils.py +0 -0
  64. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/worker-demo/tests/__init__.py +0 -0
  65. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/worker-demo/tests/conftest.py +0 -0
  66. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/worker-demo/tests/test_worker.py +0 -0
  67. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/worker-demo/worker_demo/__init__.py +0 -0
  68. {arkindex_base_worker-0.4.0rc2 → arkindex_base_worker-0.4.0rc4}/worker-demo/worker_demo/worker.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arkindex-base-worker
3
- Version: 0.4.0rc2
3
+ Version: 0.4.0rc4
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,6 +37,7 @@ 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
@@ -44,13 +45,13 @@ Requires-Dist: humanize==4.10.0
44
45
  Requires-Dist: peewee~=3.17
45
46
  Requires-Dist: Pillow==10.4.0
46
47
  Requires-Dist: python-gnupg==0.5.2
47
- Requires-Dist: shapely==2.0.5
48
- Requires-Dist: teklia-toolbox==0.1.5
48
+ Requires-Dist: shapely==2.0.6
49
+ Requires-Dist: teklia-toolbox==0.1.7b1
49
50
  Requires-Dist: zstandard==0.22.0
50
51
  Provides-Extra: docs
51
52
  Requires-Dist: black==24.4.2; extra == "docs"
52
53
  Requires-Dist: mkdocs-material==9.5.33; extra == "docs"
53
- Requires-Dist: mkdocstrings-python==1.10.8; extra == "docs"
54
+ Requires-Dist: mkdocstrings-python==1.11.1; extra == "docs"
54
55
  Provides-Extra: tests
55
56
  Requires-Dist: pytest==8.3.2; extra == "tests"
56
57
  Requires-Dist: pytest-mock==3.14.0; extra == "tests"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arkindex-base-worker
3
- Version: 0.4.0rc2
3
+ Version: 0.4.0rc4
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,6 +37,7 @@ 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
@@ -44,13 +45,13 @@ Requires-Dist: humanize==4.10.0
44
45
  Requires-Dist: peewee~=3.17
45
46
  Requires-Dist: Pillow==10.4.0
46
47
  Requires-Dist: python-gnupg==0.5.2
47
- Requires-Dist: shapely==2.0.5
48
- Requires-Dist: teklia-toolbox==0.1.5
48
+ Requires-Dist: shapely==2.0.6
49
+ Requires-Dist: teklia-toolbox==0.1.7b1
49
50
  Requires-Dist: zstandard==0.22.0
50
51
  Provides-Extra: docs
51
52
  Requires-Dist: black==24.4.2; extra == "docs"
52
53
  Requires-Dist: mkdocs-material==9.5.33; extra == "docs"
53
- Requires-Dist: mkdocstrings-python==1.10.8; extra == "docs"
54
+ Requires-Dist: mkdocstrings-python==1.11.1; extra == "docs"
54
55
  Provides-Extra: tests
55
56
  Requires-Dist: pytest==8.3.2; extra == "tests"
56
57
  Requires-Dist: pytest-mock==3.14.0; extra == "tests"
@@ -36,17 +36,25 @@ tests/test_image.py
36
36
  tests/test_merge.py
37
37
  tests/test_utils.py
38
38
  tests/test_elements_worker/__init__.py
39
- tests/test_elements_worker/test_classifications.py
39
+ tests/test_elements_worker/test_classification.py
40
40
  tests/test_elements_worker/test_cli.py
41
41
  tests/test_elements_worker/test_corpus.py
42
42
  tests/test_elements_worker/test_dataset.py
43
- tests/test_elements_worker/test_elements.py
44
- tests/test_elements_worker/test_entities.py
43
+ tests/test_elements_worker/test_element.py
44
+ tests/test_elements_worker/test_element_create_multiple.py
45
+ tests/test_elements_worker/test_element_create_single.py
46
+ tests/test_elements_worker/test_element_list_children.py
47
+ tests/test_elements_worker/test_element_list_parents.py
48
+ tests/test_elements_worker/test_entity_create.py
49
+ tests/test_elements_worker/test_entity_list_and_check.py
45
50
  tests/test_elements_worker/test_image.py
46
51
  tests/test_elements_worker/test_metadata.py
47
52
  tests/test_elements_worker/test_task.py
48
53
  tests/test_elements_worker/test_training.py
49
- tests/test_elements_worker/test_transcriptions.py
54
+ tests/test_elements_worker/test_transcription_create.py
55
+ tests/test_elements_worker/test_transcription_create_with_elements.py
56
+ tests/test_elements_worker/test_transcription_list.py
57
+ tests/test_elements_worker/test_version.py
50
58
  tests/test_elements_worker/test_worker.py
51
59
  worker-demo/tests/__init__.py
52
60
  worker-demo/tests/conftest.py
@@ -2,14 +2,14 @@ humanize==4.10.0
2
2
  peewee~=3.17
3
3
  Pillow==10.4.0
4
4
  python-gnupg==0.5.2
5
- shapely==2.0.5
6
- teklia-toolbox==0.1.5
5
+ shapely==2.0.6
6
+ teklia-toolbox==0.1.7b1
7
7
  zstandard==0.22.0
8
8
 
9
9
  [docs]
10
10
  black==24.4.2
11
11
  mkdocs-material==9.5.33
12
- mkdocstrings-python==1.10.8
12
+ mkdocstrings-python==1.11.1
13
13
 
14
14
  [tests]
15
15
  pytest==8.3.2
@@ -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
  )
@@ -10,8 +10,7 @@ from collections.abc import Iterable
10
10
  from itertools import chain
11
11
  from pathlib import Path
12
12
 
13
- from apistar.exceptions import ErrorResponse
14
-
13
+ from arkindex.exceptions import ErrorResponse
15
14
  from arkindex_worker import logger
16
15
  from arkindex_worker.cache import CachedElement
17
16
  from arkindex_worker.models import Dataset, Element, Set
@@ -12,9 +12,9 @@ from tempfile import mkdtemp
12
12
 
13
13
  import gnupg
14
14
  import yaml
15
- from apistar.exceptions import ErrorResponse
16
15
 
17
16
  from arkindex import options_from_env
17
+ from arkindex.exceptions import ErrorResponse
18
18
  from arkindex_worker import logger
19
19
  from arkindex_worker.cache import (
20
20
  check_version,
@@ -2,9 +2,9 @@
2
2
  ElementsWorker methods for classifications and ML classes.
3
3
  """
4
4
 
5
- from apistar.exceptions import ErrorResponse
6
5
  from peewee import IntegrityError
7
6
 
7
+ from arkindex.exceptions import ErrorResponse
8
8
  from arkindex_worker import logger
9
9
  from arkindex_worker.cache import CachedClassification, CachedElement
10
10
  from arkindex_worker.models import Element
@@ -5,6 +5,7 @@ BaseWorker methods for corpora.
5
5
  from enum import Enum
6
6
  from operator import itemgetter
7
7
  from tempfile import _TemporaryFileWrapper
8
+ from uuid import UUID
8
9
 
9
10
  from arkindex_worker import logger
10
11
 
@@ -36,6 +37,25 @@ class CorpusExportState(Enum):
36
37
 
37
38
 
38
39
  class CorpusMixin:
40
+ def download_export(self, export_id: str) -> _TemporaryFileWrapper:
41
+ """
42
+ Download an export.
43
+
44
+ :param export_id: UUID of the export to download
45
+ :returns: The downloaded export stored in a temporary file.
46
+ """
47
+ try:
48
+ UUID(export_id)
49
+ except ValueError as e:
50
+ raise ValueError("export_id is not a valid uuid.") from e
51
+
52
+ logger.info(f"Downloading export ({export_id})...")
53
+ export: _TemporaryFileWrapper = self.api_client.request(
54
+ "DownloadExport", id=export_id
55
+ )
56
+ logger.info(f"Downloaded export ({export_id}) @ `{export.name}`")
57
+ return export
58
+
39
59
  def download_latest_export(self) -> _TemporaryFileWrapper:
40
60
  """
41
61
  Download the latest export in `done` state of the current corpus.
@@ -62,10 +82,5 @@ class CorpusMixin:
62
82
 
63
83
  # Download latest export
64
84
  export_id: str = exports[0]["id"]
65
- logger.info(f"Downloading export ({export_id})...")
66
- export: _TemporaryFileWrapper = self.api_client.request(
67
- "DownloadExport", id=export_id
68
- )
69
- logger.info(f"Downloaded export ({export_id}) @ `{export.name}`")
70
85
 
71
- return export
86
+ return self.download_export(export_id)
@@ -302,7 +302,7 @@ class EntityMixin:
302
302
 
303
303
  created_entities = [
304
304
  created_entity
305
- for batch in make_batches(entities, "entities", batch_size)
305
+ for batch in make_batches(entities, "entity", batch_size)
306
306
  for created_entity in self.api_client.request(
307
307
  "CreateTranscriptionEntities",
308
308
  id=transcription.id,
@@ -5,8 +5,7 @@ BaseWorker methods for tasks.
5
5
  import uuid
6
6
  from collections.abc import Iterator
7
7
 
8
- from apistar.compat import DownloadedFile
9
-
8
+ from arkindex.compat import DownloadedFile
10
9
  from arkindex_worker.models import Artifact
11
10
 
12
11
 
@@ -9,8 +9,8 @@ from typing import NewType
9
9
  from uuid import UUID
10
10
 
11
11
  import requests
12
- from apistar.exceptions import ErrorResponse
13
12
 
13
+ from arkindex.exceptions import ErrorResponse
14
14
  from arkindex_worker import logger
15
15
  from arkindex_worker.utils import close_delete_file, create_tar_zst_archive
16
16
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "arkindex-base-worker"
7
- version = "0.4.0rc2"
7
+ version = "0.4.0rc4"
8
8
  description = "Base Worker to easily build Arkindex ML workflows"
9
9
  license = { file = "LICENSE" }
10
10
  dependencies = [
@@ -12,8 +12,8 @@ dependencies = [
12
12
  "peewee~=3.17",
13
13
  "Pillow==10.4.0",
14
14
  "python-gnupg==0.5.2",
15
- "shapely==2.0.5",
16
- "teklia-toolbox==0.1.5",
15
+ "shapely==2.0.6",
16
+ "teklia-toolbox==0.1.7b1",
17
17
  "zstandard==0.22.0",
18
18
  ]
19
19
  authors = [
@@ -32,6 +32,7 @@ classifiers = [
32
32
  "Programming Language :: Python :: 3 :: Only",
33
33
  "Programming Language :: Python :: 3.10",
34
34
  "Programming Language :: Python :: 3.11",
35
+ "Programming Language :: Python :: 3.12",
35
36
  ]
36
37
 
37
38
  [project.urls]
@@ -45,7 +46,7 @@ Authors = "https://teklia.com"
45
46
  docs = [
46
47
  "black==24.4.2",
47
48
  "mkdocs-material==9.5.33",
48
- "mkdocstrings-python==1.10.8",
49
+ "mkdocstrings-python==1.11.1",
49
50
  ]
50
51
  tests = [
51
52
  "pytest==8.3.2",
@@ -95,7 +96,6 @@ select = [
95
96
  known-first-party = ["arkindex", "arkindex_common", "arkindex_worker", "teklia_toolbox"]
96
97
  known-third-party = [
97
98
  "PIL",
98
- "apistar",
99
99
  "gnupg",
100
100
  "peewee",
101
101
  "playhouse",
@@ -3,8 +3,8 @@ import uuid
3
3
  from argparse import ArgumentTypeError
4
4
 
5
5
  import pytest
6
- from apistar.exceptions import ErrorResponse
7
6
 
7
+ from arkindex.exceptions import ErrorResponse
8
8
  from arkindex_worker.models import Dataset, Set
9
9
  from arkindex_worker.worker.dataset import (
10
10
  DatasetState,
@@ -3,8 +3,8 @@ import re
3
3
  from uuid import UUID
4
4
 
5
5
  import pytest
6
- from apistar.exceptions import ErrorResponse
7
6
 
7
+ from arkindex.exceptions import ErrorResponse
8
8
  from arkindex_worker.cache import CachedClassification, CachedElement
9
9
  from arkindex_worker.models import Element
10
10
  from arkindex_worker.utils import DEFAULT_BATCH_SIZE
@@ -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,
@@ -2,13 +2,44 @@ import re
2
2
  import uuid
3
3
 
4
4
  import pytest
5
- from apistar.exceptions import ErrorResponse
6
5
 
6
+ from arkindex.exceptions import ErrorResponse
7
7
  from arkindex_worker.worker.corpus import CorpusExportState
8
8
  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,
@@ -2,8 +2,8 @@ import json
2
2
  import logging
3
3
 
4
4
  import pytest
5
- from apistar.exceptions import ErrorResponse
6
5
 
6
+ from arkindex.exceptions import ErrorResponse
7
7
  from arkindex_worker.models import Dataset, Element, Set
8
8
  from arkindex_worker.worker.dataset import DatasetState
9
9
  from tests import PROCESS_ID