arkindex-base-worker 0.3.7rc9__py3-none-any.whl → 0.4.0__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 (54) hide show
  1. {arkindex_base_worker-0.3.7rc9.dist-info → arkindex_base_worker-0.4.0.dist-info}/METADATA +16 -20
  2. arkindex_base_worker-0.4.0.dist-info/RECORD +61 -0
  3. {arkindex_base_worker-0.3.7rc9.dist-info → arkindex_base_worker-0.4.0.dist-info}/WHEEL +1 -1
  4. arkindex_worker/cache.py +1 -1
  5. arkindex_worker/image.py +120 -1
  6. arkindex_worker/models.py +6 -0
  7. arkindex_worker/utils.py +85 -4
  8. arkindex_worker/worker/__init__.py +68 -162
  9. arkindex_worker/worker/base.py +39 -34
  10. arkindex_worker/worker/classification.py +34 -18
  11. arkindex_worker/worker/corpus.py +86 -0
  12. arkindex_worker/worker/dataset.py +71 -1
  13. arkindex_worker/worker/element.py +352 -91
  14. arkindex_worker/worker/entity.py +11 -11
  15. arkindex_worker/worker/image.py +21 -0
  16. arkindex_worker/worker/metadata.py +19 -9
  17. arkindex_worker/worker/process.py +92 -0
  18. arkindex_worker/worker/task.py +5 -4
  19. arkindex_worker/worker/training.py +25 -10
  20. arkindex_worker/worker/transcription.py +89 -68
  21. arkindex_worker/worker/version.py +3 -1
  22. tests/__init__.py +8 -0
  23. tests/conftest.py +36 -52
  24. tests/test_base_worker.py +212 -12
  25. tests/test_dataset_worker.py +21 -45
  26. tests/test_elements_worker/{test_classifications.py → test_classification.py} +216 -100
  27. tests/test_elements_worker/test_cli.py +3 -11
  28. tests/test_elements_worker/test_corpus.py +168 -0
  29. tests/test_elements_worker/test_dataset.py +7 -12
  30. tests/test_elements_worker/test_element.py +427 -0
  31. tests/test_elements_worker/test_element_create_multiple.py +715 -0
  32. tests/test_elements_worker/test_element_create_single.py +528 -0
  33. tests/test_elements_worker/test_element_list_children.py +969 -0
  34. tests/test_elements_worker/test_element_list_parents.py +530 -0
  35. tests/test_elements_worker/{test_entities.py → test_entity_create.py} +37 -195
  36. tests/test_elements_worker/test_entity_list_and_check.py +160 -0
  37. tests/test_elements_worker/test_image.py +66 -0
  38. tests/test_elements_worker/test_metadata.py +230 -139
  39. tests/test_elements_worker/test_process.py +89 -0
  40. tests/test_elements_worker/test_task.py +8 -18
  41. tests/test_elements_worker/test_training.py +17 -8
  42. tests/test_elements_worker/test_transcription_create.py +873 -0
  43. tests/test_elements_worker/test_transcription_create_with_elements.py +951 -0
  44. tests/test_elements_worker/test_transcription_list.py +450 -0
  45. tests/test_elements_worker/test_version.py +60 -0
  46. tests/test_elements_worker/test_worker.py +563 -279
  47. tests/test_image.py +432 -209
  48. tests/test_merge.py +1 -2
  49. tests/test_utils.py +66 -3
  50. arkindex_base_worker-0.3.7rc9.dist-info/RECORD +0 -47
  51. tests/test_elements_worker/test_elements.py +0 -2713
  52. tests/test_elements_worker/test_transcriptions.py +0 -2119
  53. {arkindex_base_worker-0.3.7rc9.dist-info → arkindex_base_worker-0.4.0.dist-info}/LICENSE +0 -0
  54. {arkindex_base_worker-0.3.7rc9.dist-info → arkindex_base_worker-0.4.0.dist-info}/top_level.txt +0 -0
@@ -3,9 +3,9 @@ import re
3
3
  from uuid import UUID
4
4
 
5
5
  import pytest
6
- from apistar.exceptions import ErrorResponse
7
6
  from responses import matchers
8
7
 
8
+ from arkindex.exceptions import ErrorResponse
9
9
  from arkindex_worker.cache import (
10
10
  CachedElement,
11
11
  CachedEntity,
@@ -13,8 +13,8 @@ from arkindex_worker.cache import (
13
13
  CachedTranscriptionEntity,
14
14
  )
15
15
  from arkindex_worker.models import Transcription
16
- from arkindex_worker.worker.entity import MissingEntityType
17
16
  from arkindex_worker.worker.transcription import TextOrientation
17
+ from tests import CORPUS_ID
18
18
 
19
19
  from . import BASE_API_CALLS
20
20
 
@@ -90,7 +90,7 @@ def test_create_entity_api_error(responses, mock_elements_worker):
90
90
  responses.add(
91
91
  responses.POST,
92
92
  "http://testserver/api/v1/entity/",
93
- status=500,
93
+ status=418,
94
94
  )
95
95
 
96
96
  with pytest.raises(ErrorResponse):
@@ -99,17 +99,10 @@ def test_create_entity_api_error(responses, mock_elements_worker):
99
99
  type="person",
100
100
  )
101
101
 
102
- assert len(responses.calls) == len(BASE_API_CALLS) + 5
102
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
103
103
  assert [
104
104
  (call.request.method, call.request.url) for call in responses.calls
105
- ] == BASE_API_CALLS + [
106
- # We retry 5 times the API call
107
- ("POST", "http://testserver/api/v1/entity/"),
108
- ("POST", "http://testserver/api/v1/entity/"),
109
- ("POST", "http://testserver/api/v1/entity/"),
110
- ("POST", "http://testserver/api/v1/entity/"),
111
- ("POST", "http://testserver/api/v1/entity/"),
112
- ]
105
+ ] == BASE_API_CALLS + [("POST", "http://testserver/api/v1/entity/")]
113
106
 
114
107
 
115
108
  def test_create_entity(responses, mock_elements_worker):
@@ -139,7 +132,7 @@ def test_create_entity(responses, mock_elements_worker):
139
132
  "type_id": "person-entity-type-id",
140
133
  "metas": {},
141
134
  "validated": None,
142
- "corpus": "11111111-1111-1111-1111-111111111111",
135
+ "corpus": CORPUS_ID,
143
136
  "worker_run_id": "56785678-5678-5678-5678-567856785678",
144
137
  }
145
138
  assert entity_id == "12345678-1234-1234-1234-123456789123"
@@ -152,7 +145,7 @@ def test_create_entity_missing_type(responses, mock_elements_worker):
152
145
  # Call to list entity types
153
146
  responses.add(
154
147
  responses.GET,
155
- "http://testserver/api/v1/corpus/11111111-1111-1111-1111-111111111111/entity-types/",
148
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/entity-types/",
156
149
  status=200,
157
150
  json={
158
151
  "count": 1,
@@ -177,7 +170,7 @@ def test_create_entity_missing_type(responses, mock_elements_worker):
177
170
  ] == BASE_API_CALLS + [
178
171
  (
179
172
  "GET",
180
- "http://testserver/api/v1/corpus/11111111-1111-1111-1111-111111111111/entity-types/",
173
+ f"http://testserver/api/v1/corpus/{CORPUS_ID}/entity-types/",
181
174
  ),
182
175
  ]
183
176
 
@@ -209,7 +202,7 @@ def test_create_entity_with_cache(responses, mock_elements_worker_with_cache):
209
202
  "type_id": "person-entity-type-id",
210
203
  "metas": {},
211
204
  "validated": None,
212
- "corpus": "11111111-1111-1111-1111-111111111111",
205
+ "corpus": CORPUS_ID,
213
206
  "worker_run_id": "56785678-5678-5678-5678-567856785678",
214
207
  }
215
208
  assert entity_id == "12345678-1234-1234-1234-123456789123"
@@ -387,7 +380,7 @@ def test_create_transcription_entity_api_error(responses, mock_elements_worker):
387
380
  responses.add(
388
381
  responses.POST,
389
382
  "http://testserver/api/v1/transcription/11111111-1111-1111-1111-111111111111/entity/",
390
- status=500,
383
+ status=418,
391
384
  )
392
385
 
393
386
  with pytest.raises(ErrorResponse):
@@ -403,31 +396,14 @@ def test_create_transcription_entity_api_error(responses, mock_elements_worker):
403
396
  length=10,
404
397
  )
405
398
 
406
- assert len(responses.calls) == len(BASE_API_CALLS) + 5
399
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
407
400
  assert [
408
401
  (call.request.method, call.request.url) for call in responses.calls
409
402
  ] == BASE_API_CALLS + [
410
- # We retry 5 times the API call
411
- (
412
- "POST",
413
- "http://testserver/api/v1/transcription/11111111-1111-1111-1111-111111111111/entity/",
414
- ),
415
403
  (
416
404
  "POST",
417
405
  "http://testserver/api/v1/transcription/11111111-1111-1111-1111-111111111111/entity/",
418
- ),
419
- (
420
- "POST",
421
- "http://testserver/api/v1/transcription/11111111-1111-1111-1111-111111111111/entity/",
422
- ),
423
- (
424
- "POST",
425
- "http://testserver/api/v1/transcription/11111111-1111-1111-1111-111111111111/entity/",
426
- ),
427
- (
428
- "POST",
429
- "http://testserver/api/v1/transcription/11111111-1111-1111-1111-111111111111/entity/",
430
- ),
406
+ )
431
407
  ]
432
408
 
433
409
 
@@ -708,159 +684,6 @@ def test_create_transcription_entity_with_confidence_with_cache(
708
684
  ]
709
685
 
710
686
 
711
- def test_list_transcription_entities_deprecation(fake_dummy_worker):
712
- transcription = Transcription({"id": "fake_transcription_id"})
713
- worker_version = "worker_version_id"
714
- fake_dummy_worker.api_client.add_response(
715
- "ListTranscriptionEntities",
716
- id=transcription.id,
717
- worker_version=worker_version,
718
- response={"id": "entity_id"},
719
- )
720
- with pytest.deprecated_call(
721
- match="`worker_version` usage is deprecated. Consider using `worker_run` instead."
722
- ):
723
- assert fake_dummy_worker.list_transcription_entities(
724
- transcription, worker_version=worker_version
725
- ) == {"id": "entity_id"}
726
-
727
- assert len(fake_dummy_worker.api_client.history) == 1
728
- assert len(fake_dummy_worker.api_client.responses) == 0
729
-
730
-
731
- def test_list_transcription_entities(fake_dummy_worker):
732
- transcription = Transcription({"id": "fake_transcription_id"})
733
- worker_run = "worker_run_id"
734
- fake_dummy_worker.api_client.add_response(
735
- "ListTranscriptionEntities",
736
- id=transcription.id,
737
- worker_run=worker_run,
738
- response={"id": "entity_id"},
739
- )
740
- assert fake_dummy_worker.list_transcription_entities(
741
- transcription, worker_run=worker_run
742
- ) == {"id": "entity_id"}
743
-
744
- assert len(fake_dummy_worker.api_client.history) == 1
745
- assert len(fake_dummy_worker.api_client.responses) == 0
746
-
747
-
748
- def test_list_corpus_entities(responses, mock_elements_worker):
749
- corpus_id = "11111111-1111-1111-1111-111111111111"
750
- responses.add(
751
- responses.GET,
752
- f"http://testserver/api/v1/corpus/{corpus_id}/entities/",
753
- json={
754
- "count": 1,
755
- "next": None,
756
- "results": [
757
- {
758
- "id": "fake_entity_id",
759
- }
760
- ],
761
- },
762
- )
763
-
764
- mock_elements_worker.list_corpus_entities()
765
-
766
- assert mock_elements_worker.entities == {
767
- "fake_entity_id": {
768
- "id": "fake_entity_id",
769
- }
770
- }
771
-
772
- assert len(responses.calls) == len(BASE_API_CALLS) + 1
773
- assert [
774
- (call.request.method, call.request.url) for call in responses.calls
775
- ] == BASE_API_CALLS + [
776
- (
777
- "GET",
778
- f"http://testserver/api/v1/corpus/{corpus_id}/entities/",
779
- ),
780
- ]
781
-
782
-
783
- @pytest.mark.parametrize("wrong_name", [1234, 12.5])
784
- def test_list_corpus_entities_wrong_name(mock_elements_worker, wrong_name):
785
- with pytest.raises(AssertionError, match="name should be of type str"):
786
- mock_elements_worker.list_corpus_entities(name=wrong_name)
787
-
788
-
789
- @pytest.mark.parametrize("wrong_parent", [{"id": "element_id"}, 12.5, "blabla"])
790
- def test_list_corpus_entities_wrong_parent(mock_elements_worker, wrong_parent):
791
- with pytest.raises(AssertionError, match="parent should be of type Element"):
792
- mock_elements_worker.list_corpus_entities(parent=wrong_parent)
793
-
794
-
795
- def test_check_required_entity_types(responses, mock_elements_worker):
796
- # Set one entity type
797
- mock_elements_worker.entity_types = {"person": "person-entity-type-id"}
798
-
799
- checked_types = ["person", "new-entity"]
800
-
801
- # Call to create new entity type
802
- responses.add(
803
- responses.POST,
804
- "http://testserver/api/v1/entity/types/",
805
- status=200,
806
- match=[
807
- matchers.json_params_matcher(
808
- {
809
- "name": "new-entity",
810
- "corpus": "11111111-1111-1111-1111-111111111111",
811
- }
812
- )
813
- ],
814
- json={
815
- "id": "new-entity-id",
816
- "corpus": "11111111-1111-1111-1111-111111111111",
817
- "name": "new-entity",
818
- "color": "ffd1b3",
819
- },
820
- )
821
-
822
- mock_elements_worker.check_required_entity_types(
823
- entity_types=checked_types,
824
- )
825
-
826
- # Make sure the entity_types entry has been updated
827
- assert mock_elements_worker.entity_types == {
828
- "person": "person-entity-type-id",
829
- "new-entity": "new-entity-id",
830
- }
831
-
832
- assert len(responses.calls) == len(BASE_API_CALLS) + 1
833
- assert [
834
- (call.request.method, call.request.url) for call in responses.calls
835
- ] == BASE_API_CALLS + [
836
- (
837
- "POST",
838
- "http://testserver/api/v1/entity/types/",
839
- ),
840
- ]
841
-
842
-
843
- def test_check_required_entity_types_no_creation_allowed(
844
- responses, mock_elements_worker
845
- ):
846
- # Set one entity type
847
- mock_elements_worker.entity_types = {"person": "person-entity-type-id"}
848
-
849
- checked_types = ["person", "new-entity"]
850
-
851
- with pytest.raises(
852
- MissingEntityType, match="Entity type `new-entity` was not in the corpus."
853
- ):
854
- mock_elements_worker.check_required_entity_types(
855
- entity_types=checked_types, create_missing=False
856
- )
857
-
858
- assert len(responses.calls) == len(BASE_API_CALLS)
859
- assert [
860
- (call.request.method, call.request.url) for call in responses.calls
861
- ] == BASE_API_CALLS
862
-
863
-
864
687
  @pytest.mark.parametrize("transcription", [None, "not a transcription", 1])
865
688
  def test_create_transcription_entities_wrong_transcription(
866
689
  mock_elements_worker, transcription
@@ -1014,6 +837,7 @@ def test_create_transcription_entities_wrong_entity(
1014
837
 
1015
838
  def test_create_transcription_entities(responses, mock_elements_worker):
1016
839
  transcription = Transcription(id="transcription-id")
840
+
1017
841
  # Call to Transcription entities creation in bulk
1018
842
  responses.add(
1019
843
  responses.POST,
@@ -1030,7 +854,14 @@ def test_create_transcription_entities(responses, mock_elements_worker):
1030
854
  "offset": 0,
1031
855
  "length": 6,
1032
856
  "confidence": 1.0,
1033
- }
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
+ },
1034
865
  ],
1035
866
  }
1036
867
  )
@@ -1039,8 +870,12 @@ def test_create_transcription_entities(responses, mock_elements_worker):
1039
870
  "entities": [
1040
871
  {
1041
872
  "transcription_entity_id": "transc-entity-id",
1042
- "entity_id": "entity-id",
1043
- }
873
+ "entity_id": "entity-id1",
874
+ },
875
+ {
876
+ "transcription_entity_id": "transc-entity-id",
877
+ "entity_id": "entity-id2",
878
+ },
1044
879
  ]
1045
880
  },
1046
881
  )
@@ -1058,11 +893,18 @@ def test_create_transcription_entities(responses, mock_elements_worker):
1058
893
  "offset": 0,
1059
894
  "length": 6,
1060
895
  "confidence": 1.0,
1061
- }
896
+ },
897
+ {
898
+ "name": "Team Rocket",
899
+ "type_id": "22222222-2222-2222-2222-222222222222",
900
+ "offset": 7,
901
+ "length": 11,
902
+ "confidence": 1.0,
903
+ },
1062
904
  ],
1063
905
  )
1064
906
 
1065
- assert len(created_objects) == 1
907
+ assert len(created_objects) == 2
1066
908
 
1067
909
  assert len(responses.calls) == len(BASE_API_CALLS) + 1
1068
910
  assert [
@@ -1071,5 +913,5 @@ def test_create_transcription_entities(responses, mock_elements_worker):
1071
913
  (
1072
914
  "POST",
1073
915
  "http://testserver/api/v1/transcription/transcription-id/entities/bulk/",
1074
- ),
916
+ )
1075
917
  ]
@@ -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)
@@ -0,0 +1,66 @@
1
+ import json
2
+
3
+ import pytest
4
+
5
+ from arkindex.exceptions import ErrorResponse
6
+
7
+ from . import BASE_API_CALLS
8
+
9
+
10
+ @pytest.mark.parametrize(
11
+ ("data", "error_message"),
12
+ [
13
+ (None, "url shouldn't be null and should be of type str"),
14
+ (1234, "url shouldn't be null and should be of type str"),
15
+ ],
16
+ )
17
+ def test_create_iiif_url_wrong_data(data, error_message, mock_elements_worker):
18
+ with pytest.raises(AssertionError, match=error_message):
19
+ mock_elements_worker.create_iiif_url(url=data)
20
+
21
+
22
+ def test_create_iiif_url_api_error(responses, mock_elements_worker):
23
+ responses.add(
24
+ responses.POST,
25
+ "http://testserver/api/v1/image/iiif/url/",
26
+ status=418,
27
+ )
28
+
29
+ with pytest.raises(ErrorResponse):
30
+ mock_elements_worker.create_iiif_url("http://url/to/my/image")
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 + [("POST", "http://testserver/api/v1/image/iiif/url/")]
36
+
37
+
38
+ def test_create_iiif_url(responses, mock_elements_worker):
39
+ responses.add(
40
+ responses.POST,
41
+ "http://testserver/api/v1/image/iiif/url/",
42
+ status=201,
43
+ json={
44
+ "id": "cafecafe-cafe-cafe-cafe-cafecafecafe",
45
+ "url": "http://url/to/my/image",
46
+ "status": "checked",
47
+ "server": {
48
+ "id": 5,
49
+ "display_name": "My server",
50
+ "url": "http://url/to/my",
51
+ "max_width": 42,
52
+ "max_height": 42,
53
+ },
54
+ },
55
+ )
56
+
57
+ image = mock_elements_worker.create_iiif_url("http://url/to/my/image")
58
+
59
+ assert len(responses.calls) == len(BASE_API_CALLS) + 1
60
+ assert [
61
+ (call.request.method, call.request.url) for call in responses.calls
62
+ ] == BASE_API_CALLS + [("POST", "http://testserver/api/v1/image/iiif/url/")]
63
+ assert json.loads(responses.calls[-1].request.body) == {
64
+ "url": "http://url/to/my/image"
65
+ }
66
+ assert image.id == "cafecafe-cafe-cafe-cafe-cafecafecafe"