arkindex-base-worker 0.4.0rc3__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.
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/METADATA +15 -14
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/RECORD +21 -13
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/WHEEL +1 -1
- arkindex_worker/cache.py +1 -1
- tests/test_elements_worker/{test_classifications.py → test_classification.py} +86 -0
- tests/test_elements_worker/test_corpus.py +31 -31
- tests/test_elements_worker/test_element.py +427 -0
- tests/test_elements_worker/test_element_create_multiple.py +715 -0
- tests/test_elements_worker/test_element_create_single.py +528 -0
- tests/test_elements_worker/test_element_list_children.py +969 -0
- tests/test_elements_worker/test_element_list_parents.py +530 -0
- tests/test_elements_worker/{test_entities.py → test_entity_create.py} +0 -153
- tests/test_elements_worker/test_entity_list_and_check.py +160 -0
- tests/test_elements_worker/test_transcription_create.py +873 -0
- tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
- tests/test_elements_worker/test_transcription_list.py +450 -0
- tests/test_elements_worker/test_version.py +60 -0
- tests/test_elements_worker/test_worker.py +525 -88
- tests/test_image.py +181 -198
- tests/test_elements_worker/test_elements.py +0 -3704
- tests/test_elements_worker/test_transcriptions.py +0 -2252
- {arkindex_base_worker-0.4.0rc3.dist-info → arkindex_base_worker-0.4.0rc4.dist-info}/LICENSE +0 -0
- {arkindex_base_worker-0.4.0rc3.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)
|