arkindex-base-worker 0.4.0rc2__py3-none-any.whl → 0.4.0rc4__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 (36) hide show
  1. {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/METADATA +15 -14
  2. arkindex_base_worker-0.4.0rc4.dist-info/RECORD +60 -0
  3. {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/WHEEL +1 -1
  4. arkindex_worker/cache.py +1 -1
  5. arkindex_worker/worker/__init__.py +1 -2
  6. arkindex_worker/worker/base.py +1 -1
  7. arkindex_worker/worker/classification.py +1 -1
  8. arkindex_worker/worker/corpus.py +21 -6
  9. arkindex_worker/worker/entity.py +1 -1
  10. arkindex_worker/worker/task.py +1 -2
  11. arkindex_worker/worker/training.py +1 -1
  12. tests/test_dataset_worker.py +1 -1
  13. tests/test_elements_worker/{test_classifications.py → test_classification.py} +87 -1
  14. tests/test_elements_worker/test_corpus.py +32 -1
  15. tests/test_elements_worker/test_dataset.py +1 -1
  16. tests/test_elements_worker/test_element.py +427 -0
  17. tests/test_elements_worker/test_element_create_multiple.py +715 -0
  18. tests/test_elements_worker/test_element_create_single.py +528 -0
  19. tests/test_elements_worker/test_element_list_children.py +969 -0
  20. tests/test_elements_worker/test_element_list_parents.py +530 -0
  21. tests/test_elements_worker/{test_entities.py → test_entity_create.py} +1 -154
  22. tests/test_elements_worker/test_entity_list_and_check.py +160 -0
  23. tests/test_elements_worker/test_image.py +2 -1
  24. tests/test_elements_worker/test_metadata.py +1 -1
  25. tests/test_elements_worker/test_task.py +1 -1
  26. tests/test_elements_worker/test_transcription_create.py +873 -0
  27. tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
  28. tests/test_elements_worker/test_transcription_list.py +450 -0
  29. tests/test_elements_worker/test_version.py +60 -0
  30. tests/test_elements_worker/test_worker.py +526 -89
  31. tests/test_image.py +181 -198
  32. arkindex_base_worker-0.4.0rc2.dist-info/RECORD +0 -52
  33. tests/test_elements_worker/test_elements.py +0 -3704
  34. tests/test_elements_worker/test_transcriptions.py +0 -2252
  35. {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/LICENSE +0 -0
  36. {arkindex_base_worker-0.4.0rc2.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,160 @@
1
+ import pytest
2
+ from responses import matchers
3
+
4
+ from arkindex_worker.models import Transcription
5
+ from arkindex_worker.worker.entity import MissingEntityType
6
+ from tests import CORPUS_ID
7
+
8
+ from . import BASE_API_CALLS
9
+
10
+
11
+ def test_check_required_entity_types(responses, mock_elements_worker):
12
+ # Set one entity type
13
+ mock_elements_worker.entity_types = {"person": "person-entity-type-id"}
14
+
15
+ checked_types = ["person", "new-entity"]
16
+
17
+ # Call to create new entity type
18
+ responses.add(
19
+ responses.POST,
20
+ "http://testserver/api/v1/entity/types/",
21
+ status=200,
22
+ match=[
23
+ matchers.json_params_matcher(
24
+ {
25
+ "name": "new-entity",
26
+ "corpus": CORPUS_ID,
27
+ }
28
+ )
29
+ ],
30
+ json={
31
+ "id": "new-entity-id",
32
+ "corpus": CORPUS_ID,
33
+ "name": "new-entity",
34
+ "color": "ffd1b3",
35
+ },
36
+ )
37
+
38
+ mock_elements_worker.check_required_entity_types(
39
+ entity_types=checked_types,
40
+ )
41
+
42
+ # Make sure the entity_types entry has been updated
43
+ assert mock_elements_worker.entity_types == {
44
+ "person": "person-entity-type-id",
45
+ "new-entity": "new-entity-id",
46
+ }
47
+
48
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
49
+ assert [
50
+ (call.request.method, call.request.url) for call in responses.calls
51
+ ] == BASE_API_CALLS + [
52
+ (
53
+ "POST",
54
+ "http://testserver/api/v1/entity/types/",
55
+ ),
56
+ ]
57
+
58
+
59
+ def test_check_required_entity_types_no_creation_allowed(
60
+ responses, mock_elements_worker
61
+ ):
62
+ # Set one entity type
63
+ mock_elements_worker.entity_types = {"person": "person-entity-type-id"}
64
+
65
+ checked_types = ["person", "new-entity"]
66
+
67
+ with pytest.raises(
68
+ MissingEntityType, match="Entity type `new-entity` was not in the corpus."
69
+ ):
70
+ mock_elements_worker.check_required_entity_types(
71
+ entity_types=checked_types, create_missing=False
72
+ )
73
+
74
+ assert len(responses.calls) == len(BASE_API_CALLS)
75
+ assert [
76
+ (call.request.method, call.request.url) for call in responses.calls
77
+ ] == BASE_API_CALLS
78
+
79
+
80
+ def test_list_transcription_entities_deprecation(fake_dummy_worker):
81
+ transcription = Transcription({"id": "fake_transcription_id"})
82
+ worker_version = "worker_version_id"
83
+ fake_dummy_worker.api_client.add_response(
84
+ "ListTranscriptionEntities",
85
+ id=transcription.id,
86
+ worker_version=worker_version,
87
+ response={"id": "entity_id"},
88
+ )
89
+ with pytest.deprecated_call(
90
+ match="`worker_version` usage is deprecated. Consider using `worker_run` instead."
91
+ ):
92
+ assert fake_dummy_worker.list_transcription_entities(
93
+ transcription, worker_version=worker_version
94
+ ) == {"id": "entity_id"}
95
+
96
+ assert len(fake_dummy_worker.api_client.history) == 1
97
+ assert len(fake_dummy_worker.api_client.responses) == 0
98
+
99
+
100
+ def test_list_transcription_entities(fake_dummy_worker):
101
+ transcription = Transcription({"id": "fake_transcription_id"})
102
+ worker_run = "worker_run_id"
103
+ fake_dummy_worker.api_client.add_response(
104
+ "ListTranscriptionEntities",
105
+ id=transcription.id,
106
+ worker_run=worker_run,
107
+ response={"id": "entity_id"},
108
+ )
109
+ assert fake_dummy_worker.list_transcription_entities(
110
+ transcription, worker_run=worker_run
111
+ ) == {"id": "entity_id"}
112
+
113
+ assert len(fake_dummy_worker.api_client.history) == 1
114
+ assert len(fake_dummy_worker.api_client.responses) == 0
115
+
116
+
117
+ def test_list_corpus_entities(responses, mock_elements_worker):
118
+ responses.add(
119
+ responses.GET,
120
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/entities/",
121
+ json={
122
+ "count": 1,
123
+ "next": None,
124
+ "results": [
125
+ {
126
+ "id": "fake_entity_id",
127
+ }
128
+ ],
129
+ },
130
+ )
131
+
132
+ mock_elements_worker.list_corpus_entities()
133
+
134
+ assert mock_elements_worker.entities == {
135
+ "fake_entity_id": {
136
+ "id": "fake_entity_id",
137
+ }
138
+ }
139
+
140
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
141
+ assert [
142
+ (call.request.method, call.request.url) for call in responses.calls
143
+ ] == BASE_API_CALLS + [
144
+ (
145
+ "GET",
146
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/entities/",
147
+ ),
148
+ ]
149
+
150
+
151
+ @pytest.mark.parametrize("wrong_name", [1234, 12.5])
152
+ def test_list_corpus_entities_wrong_name(mock_elements_worker, wrong_name):
153
+ with pytest.raises(AssertionError, match="name should be of type str"):
154
+ mock_elements_worker.list_corpus_entities(name=wrong_name)
155
+
156
+
157
+ @pytest.mark.parametrize("wrong_parent", [{"id": "element_id"}, 12.5, "blabla"])
158
+ def test_list_corpus_entities_wrong_parent(mock_elements_worker, wrong_parent):
159
+ with pytest.raises(AssertionError, match="parent should be of type Element"):
160
+ mock_elements_worker.list_corpus_entities(parent=wrong_parent)
@@ -1,7 +1,8 @@
1
1
  import json
2
2
 
3
3
  import pytest
4
- from apistar.exceptions import ErrorResponse
4
+
5
+ from arkindex.exceptions import ErrorResponse
5
6
 
6
7
  from . import BASE_API_CALLS
7
8
 
@@ -2,8 +2,8 @@ import json
2
2
  import re
3
3
 
4
4
  import pytest
5
- from apistar.exceptions import ErrorResponse
6
5
 
6
+ from arkindex.exceptions import ErrorResponse
7
7
  from arkindex.mock import MockApiClient
8
8
  from arkindex_worker.cache import CachedElement
9
9
  from arkindex_worker.models import Element
@@ -1,8 +1,8 @@
1
1
  import uuid
2
2
 
3
3
  import pytest
4
- from apistar.exceptions import ErrorResponse
5
4
 
5
+ from arkindex.exceptions import ErrorResponse
6
6
  from arkindex_worker.models import Artifact
7
7
  from tests import FIXTURES_DIR
8
8
  from tests.test_elements_worker import BASE_API_CALLS