-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_api.py
829 lines (759 loc) · 33.1 KB
/
test_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
import json
from pathlib import Path
from typing import Any
from flask import url_for
from openatlas import app
from openatlas.api.resources.api_entity import ApiEntity
from tests.base import ApiTestCase
class Api(ApiTestCase):
def test_api(self) -> None:
c = self.client
logo_path = Path(app.root_path) / 'static' / 'images' / 'layout'
with open(logo_path / 'logo.png', 'rb') as img:
c.post(
url_for('insert', class_='file'),
data={
'name': 'OpenAtlas logo',
'file': img,
'creator': 'Max',
'license_holder': 'Moritz',
'public': True},
follow_redirects=True)
with app.test_request_context():
app.preprocess_request()
for entity in ApiEntity.get_by_cidoc_classes(['all']):
match entity.name:
case 'Location of Shire':
location = entity
case 'Shire':
place = entity
case 'Boundary Mark':
boundary_mark = entity
case 'Travel to Mordor':
event = entity
case 'Economical':
relation_sub = entity
case 'Austria':
unit_node = entity
case 'Frodo':
actor = entity
case 'Sam':
actor2 = entity
case 'Home of Baggins':
feature = entity
case 'Location of Home of Baggins':
feature_location = entity
case 'Sûza':
alias = entity
case 'Height':
height = entity
case 'Weight':
weight_ = entity
case 'Change of Property':
change_of_property = entity
case 'File not public':
file_not_public = entity
case 'File without license':
file_without_licences = entity
case 'File without file':
file_without_file = entity
case 'OpenAtlas logo':
file = entity
case 'Public domain':
open_license = entity
file.link('P2', open_license)
# Test Swagger UI
if app.config['OPENAPI_INSTANCE_FILE'].exists():
app.config['OPENAPI_INSTANCE_FILE'].unlink()
rv: Any = c.get(url_for('flasgger.apidocs'))
assert b'Flasgger' in rv.data
with app.config['OPENAPI_INSTANCE_FILE'].open(mode='r+') as f:
data = json.load(f)
data['servers'][0]['description'] = 'Wrong description'
f.seek(0)
json.dump(data, f)
f.truncate()
rv = c.get(url_for('flasgger.apidocs'))
assert b'Flasgger' in rv.data
with app.config['OPENAPI_INSTANCE_FILE'].open(mode='r+') as f:
data = json.load(f)
data['info']['version'] = '9.9.9'
f.seek(0)
json.dump(data, f)
f.truncate()
rv = c.get(url_for('flasgger.apidocs'))
assert b'Flasgger' in rv.data
# ---Content Endpoints---
rv = c.get(url_for('api_04.classes')).get_json()
assert self.get_classes(rv)
rv = c.get(url_for('api_04.class_mapping', locale='de')).get_json()
assert self.get_class_mapping(rv, 'de')
rv = c.get(url_for('api_04.class_mapping', locale='ca', download=True))
assert self.get_class_mapping(rv.get_json(), 'ca')
rv = c.get(url_for('api_04.properties', locale='de')).get_json()
assert rv['P2']['nameInverse'] == 'ist Typus von'
assert rv['P2']['name']
assert rv['P2']['nameInverse']
assert rv['P2']['i18n']
assert rv['P2']['i18nInverse']
assert rv['P2']['code']
rv = c.get(url_for('api_04.properties', locale='fr', download=True))
assert rv.get_json()['P2']['name'] == 'a pour type'
rv = c.get(url_for('api_04.backend_details')).get_json()
assert rv['version'] == app.config['VERSION']
rv = c.get(url_for('api_04.backend_details', download=True)).get_json()
assert rv['version'] == app.config['VERSION']
rv = c.get(url_for('api_04.system_class_count')).get_json()
assert rv['person']
rv = c.get(
url_for('api_04.system_class_count', type_id=boundary_mark.id))
assert rv.get_json()['place']
rv = c.get(url_for('api.licensed_file_overview', file_id=file.id))
assert rv.get_json()[str(file.id)]['license'] == 'Public domain'
rv = c.get(url_for('api.licensed_file_overview'))
assert len(rv.get_json().keys()) == 5
rv = c.get(
url_for(
'api_04.network_visualisation',
exclude_system_classes='type'))
rv = rv.get_json()
assert len(rv['results']) == 65
rv = c.get(
url_for(
'api_04.network_visualisation',
linked_to_ids=boundary_mark.id))
rv = rv.get_json()
assert len(rv['results']) == 3
rv = c.get(url_for('api_04.network_visualisation', download=True))
rv = rv.get_json()
assert len(rv['results']) == 154
for rv in [
c.get(url_for('api_04.geometric_entities')),
c.get(url_for('api_04.geometric_entities', download=True))]:
rv = rv.get_json()
assert rv['features'][0]['geometry']['coordinates']
assert rv['features'][0]['properties']['id']
assert rv['features'][0]['properties']['objectDescription']
assert rv['features'][0]['properties']['objectId']
assert rv['features'][0]['properties']['objectName']
assert rv['features'][0]['properties']['shapeType']
rv = c.get(url_for('api_04.export_database', format_='xml'))
assert b'Shire' in rv.data
assert 'application/xml' in rv.headers.get('Content-Type')
rv = c.get(url_for('api_04.export_database', format_='json'))
assert b'Shire' in rv.data
assert 'application/json' in rv.headers.get('Content-Type')
rv = c.get(url_for('api_04.export_database', format_='csv'))
assert b'Shire' in rv.data
assert 'application/zip' in rv.headers.get('Content-Type')
# ---Entity Endpoints---
# Test Entity
rv = c.get(url_for('api_04.entity', id_=place.id, download=True))
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()['features'][0]
assert rv['@id']
assert rv['type'] == 'Feature'
assert rv['crmClass'] == 'crm:E18 Physical Thing'
assert rv['systemClass'] == 'place'
assert rv['properties']['title'] == 'Shire'
desc = rv['descriptions'][0]
assert desc['value'] == 'The Shire was the homeland of the hobbits.'
timespan = rv['when']['timespans'][0]
assert timespan['start']['earliest'] == '2018-01-31T00:00:00'
assert timespan['start']['latest'] == '2018-03-01T00:00:00'
assert timespan['end']['earliest'] == '2019-01-31T00:00:00'
assert timespan['end']['latest'] == '2019-03-01T00:00:00'
assert rv['types'][0]['identifier']
assert rv['types'][0]['label'] == 'Boundary Mark'
assert rv['relations'][1]['label'] == 'Height'
assert rv['relations'][1]['relationDescription'] == '23.0'
assert rv['relations'][0]['relationTo']
assert rv['relations'][0]['relationType'] == 'crm:P2 has type'
assert rv['relations'][0]['relationSystemClass'] == 'type'
assert rv['names'][0]['alias'] == 'Sûza'
links = rv['links'][0]
assert links['type'] == 'closeMatch'
assert links['identifier'] == 'https://www.geonames.org/2761369'
assert links['referenceSystem'] == 'GeoNames'
assert rv['geometry']['type'] == 'GeometryCollection'
assert rv['geometry']['geometries'][1]['coordinates'] \
== [16.37069611, 48.208571233]
assert rv['depictions'][0]['@id']
assert rv['depictions'][0]['title'] == 'Picture with a License'
assert rv['depictions'][0]['license'] == 'Public domain'
assert rv['depictions'][0]['url']
rv = c.get(
url_for('api_04.entity', id_=place.id, format='lpx', locale='de'))
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()['features'][0]
assert rv['relations'][1]['label'] == 'Height'
assert rv['relations'][1]['relationDescription'] == '23.0'
assert rv['relations'][0]['relationTo']
assert rv['relations'][0]['relationType'] == 'crm:P2_has_type'
assert rv['relations'][0]['relationTypeLabel'] == 'hat den Typus'
geojson_checklist = [
'@id', 'systemClass', 'name', 'description', 'begin_earliest',
'begin_latest', 'begin_comment', 'end_earliest', 'end_latest',
'end_comment', 'types']
# Test entity in GeoJSON format
rv = c.get(url_for('api_04.entity', id_=place.id, format='geojson'))
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()['features'][0]
assert rv['geometry']['type']
assert rv['geometry']['coordinates']
for key in geojson_checklist:
assert rv['properties'][key]
rv = c.get(url_for('api_04.entity', id_=place.id, format='geojson-v2'))
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()['features'][0]
assert rv['geometry']['type']
assert rv['geometry']['geometries'][0]['coordinates']
for key in geojson_checklist:
assert rv['properties'][key]
# Test entity in Linked Open Usable Data
rv = c.get(url_for('api_04.entity', id_=place.id, format='loud'))
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()
assert rv['type'] == 'PhysicalThing'
assert rv['_label'] == 'Shire'
assert rv['content'] == 'The Shire was the homeland of the hobbits.'
assert rv['timespan']['begin_of_the_begin'] == '2018-01-31T00:00:00'
assert rv['identified_by'][0]['_label'] == 'Sûza'
assert rv['classified_as'][0]['_label'] == 'Boundary Mark'
assert (rv['former_or_current_location'][0]['_label']
== 'Location of Shire')
assert (rv['former_or_current_location'][0]['defined_by']
== 'POLYGON((28.9389559878606 41.0290525580955,'
'28.9409293485759 41.0273124142771,28.941969652866 '
'41.0284940983463,28.9399641177912 41.0297647897435'
',28.9389559878606 41.0290525580955))')
# Test Entity export and RDFS
for rv in [
c.get(url_for('api_04.entity', id_=place.id, export='csv')),
c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
export='csv'))]:
assert b'Shire' in rv.data
assert 'text/csv' in rv.headers.get('Content-Type')
for rv in [
c.get(
url_for('api_04.entity', id_=place.id, export='csvNetwork')),
c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
export='csvNetwork'))]:
assert b'Shire' in rv.data
assert 'application/zip' in rv.headers.get('Content-Type')
rv = c.get(
url_for(
'api_04.linked_entities_by_properties_recursive',
id_=place.id,
properties='P46'))
rv = rv.get_json()
names = [place.name, feature.name, 'Bar']
for item in rv['results']:
assert item['features'][0]['properties']['title'] in names
rv = c.get(
url_for(
'api_04.linked_entities_by_properties_recursive',
id_=place.id,
properties='all'))
rv = rv.get_json()
assert rv['results'][0]['features'][0]['properties']
# Test Entities endpoints
rv = c.get(url_for('api_04.entity_presentation_view', id_=place.id))
rv = rv.get_json()
assert rv['id'] == place.id
assert rv['systemClass'] == place.class_.name
assert rv['title'] == place.name
assert rv['description'] == place.description
assert rv['geometries']
assert rv['when']['start']['earliest'] == "2018-01-31T00:00:00"
assert rv['types'][0]['id'] == boundary_mark.id
assert rv['externalReferenceSystems'][0]['type'] == "closeMatch"
assert rv['files'][0]['title'] == 'Picture with a License'
assert rv['relations']['feature']
assert rv['relations']['person']
rv = c.get(url_for('api_04.entity_presentation_view', id_=actor.id))
rv = rv.get_json()
assert rv['id'] == actor.id
assert rv['title'] == actor.name
assert rv['relations']['activity']
for rv in [
c.get(url_for('api_04.cidoc_class', class_='E21')),
c.get(
url_for(
'api_04.view_class',
class_='place',
sort='desc',
column='id',
relation_type='P2',
type_id=boundary_mark.id)),
c.get(
url_for(
'api_04.view_class',
class_='place',
sort='desc',
column='begin_from',
relation_type='P2',
type_id=boundary_mark.id)),
c.get(url_for('api_04.latest', limit=2)),
c.get(url_for('api_04.system_class', class_='artifact')),
c.get(url_for('api_04.entities_linked_to_entity', id_=event.id)),
c.get(url_for('api_04.type_entities', id_=boundary_mark.id)),
c.get(url_for('api_04.type_entities', id_=relation_sub.id)),
c.get(url_for('api_04.type_entities_all', id_=unit_node.id)),
c.get(url_for('api_04.type_entities_all', id_=relation_sub.id)),
c.get(
url_for(
'api_04.query',
entities=location.id,
classes='E18',
codes='artifact',
sort='desc',
column='cidoc_class',
system_classes='person',
download=True,
last=actor.id)),
c.get(
url_for(
'api_04.query',
entities=location.id,
classes='E18',
codes='artifact',
system_classes='person',
linked_entities=place.id,
sort='desc',
column='system_class',
download=True,
actor=place.id))]:
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()
assert rv['results'][0]['features'][0]['@id']
assert rv['pagination']['entities']
assert rv['pagination']['entitiesPerPage']
assert rv['pagination']['index']
assert rv['pagination']['totalPages']
# Test Entities with show=none
rv = c.get(url_for('api_04.cidoc_class', class_='E21', show='none'))
rv = rv.get_json()['results'][0]['features'][0]
assert not rv['geometry']
assert not rv.get('depictions')
assert not rv.get('links')
assert not rv.get('types')
# Test if Query returns enough entities
rv = c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
limit=0,
first=actor2.id)).get_json()
assert rv['pagination']['entities'] == 8
# Test page parameter
rv = c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
limit=1,
page=7)).get_json()
properties = rv['results'][0]['features'][0]['properties']
assert properties['title'] == place.name
assert len(rv['results']) == 1
# Test Entities count
rv = c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
count=True))
assert rv.get_json() == 8
rv = c.get(url_for('api_04.geometric_entities', count=True))
assert rv.get_json() == 6
# Test entities with GeoJSON Format
for rv in [
c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
format='geojson')),
c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
format='geojson-v2'))]:
rv = rv.get_json()['results'][0]['features'][0]
assert rv['properties']['@id']
assert rv['properties']['systemClass']
# Test entities with Linked Open Usable Data Format
rv = c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes=['E18', 'E53'],
view_classes='artifact',
system_classes=['person', 'type'],
format='loud',
limit=0))
rv = rv.get_json()['results'][0]
assert rv['type'] == 'Type'
assert rv['_label'] == 'Abbot'
# ---Type Endpoints---
for rv in [
c.get(url_for('api_04.type_overview')),
c.get(url_for('api_04.type_overview', download=True))]:
assert 'Austria' in str(rv.get_json())
for rv in [
c.get(url_for('api_04.type_by_view_class')),
c.get(url_for('api_04.type_by_view_class', download=True))]:
assert 'Boundary Mark' in str(rv.get_json())
rv = c.get(url_for('api_04.type_tree'))
assert rv.get_json()['typeTree']
rv = c.get(url_for('api_04.type_tree', download=True))
assert rv.get_json()['typeTree']
rv = c.get(url_for('api_04.type_tree', count=True))
assert rv.get_json() > 0
# ---Test search---
search_string_constructor = [
(0, [{
"entityAliases": [{
"operator": "equal",
"values": ["Sûza"],
"logicalOperator": "and"}],
"typeID": [{
"operator": "equal",
"values": [1121212],
"logicalOperator": "and"}]}, {
"valueTypeID": [{
"operator": "lesserThanEqual",
"values": [(height.id, 1.0), (weight_.id, 1.0)],
"logicalOperator": "and"}]}, {
"entityAliases": [{
"operator": "greaterThan",
"values": ["Sûza"]}],
"typeID": [{"operator": "equal", "values": [1121212]}]}]),
(1, [{
"endFrom": [{
"operator": "greaterThan",
"values": ["2013-02-01"],
"logicalOperator": "and"}]}]),
(1, [{
"endTo": [{
"operator": "greaterThanEqual",
"values": ["2019-03-01"],
"logicalOperator": "and"}]}, ]),
(2, [{
"beginFrom": [{
"operator": "lesserThan",
"values": ["2020-01-01"],
"logicalOperator": "and"}]}]),
(2, [{
"beginTo": [{
"operator": "lesserThanEqual",
"values": ["2018-03-01"],
"logicalOperator": "and"}]}]),
(1, [{
"valueTypeID": [{
"operator": "greaterThanEqual",
"values": [(height.id, 23.0)],
"logicalOperator": "or"}]}]),
(2, [{
"valueTypeID": [{
"operator": "equal",
"values": [(height.id, 23.0)]}]}, {
"valueTypeID": [{
"operator": "greaterThanEqual",
"values": [(height.id, 23.0)]}]}, {
"typeName": [{
"operator": "equal",
"values": ["Boundary Mark", "Height"],
"logicalOperator": "and"}]}, {
"entityAliases": [{
"operator": "like",
"values": ["S"]}]}, {
"typeName": [{
"operator": "like",
"values": ["Oun", "mark"],
"logicalOperator": "and"}]}, {
"entityDescription": [{
"operator": "equal",
"values": [
"the shirE Was the Homeland of the hobbits.",
"homeland"]}]}, {
"valueTypeID": [{
"operator": "greaterThanEqual",
"values": [(height.id, 23.0), (weight_.id, 999.0)],
"logicalOperator": "and"}]}]),
(4, [{
"entityCidocClass": [{
"operator": "equal",
"values": ["E21"],
"logicalOperator": "and"}]}, {
"entitySystemClass": [{
"operator": "equal",
"values": ["person"],
"logicalOperator": "and"}]}, {
"typeIDWithSubs": [{
"operator": "equal",
"values": [boundary_mark.id, height.id]}]}, {
"typeIDWithSubs": [{
"operator": "equal",
"values": [boundary_mark.id],
"logicalOperator": "and"}]}, {
"typeID": [{
"operator": "equal",
"values": [boundary_mark.id, height.id]}]}]),
(5, [{"entityName": [{"operator": "like", "values": ["Fr"]}]}]),
(6, [{
"typeIDWithSubs": [{
"operator": "equal",
"values": [boundary_mark.id, height.id,
change_of_property.id]}]}, {
"entityDescription": [{
"operator": "like",
"values": ["FrOdO", "sam"]}]}]),
(9, [{
"relationToID": [{
"operator": "equal",
"values": [place.id]}]}]),
(161, [{
"typeIDWithSubs": [{
"operator": "notEqual",
"values": [boundary_mark.id],
"logicalOperator": "and"}]}]),
(163, [{
"typeName": [{
"operator": "notEqual",
"values": ["Boundary Mark", "Height"],
"logicalOperator": "and"}]}, {
"entityID": [{
"operator": "notEqual",
"values": [place.id],
"logicalOperator": "and"}]}, {
"entityAliases": [{
"operator": "notEqual",
"values": ["Sûza"],
"logicalOperator": "and"}]}, {
"entityName": [{
"operator": "notEqual",
"values": ["Mordor"]}]}])]
for count, search_string in search_string_constructor:
rv = c.get(
url_for(
'api_04.query',
system_classes='all',
search=search_string))
assert rv.get_json()['pagination']['entities'] == count
for rv in [
c.get(
url_for('api_04.subunits', id_=feature.id, centroid='false')),
c.get(
url_for('api_04.subunits', id_=place.id, download=True))]:
assert 'application/json' in rv.headers.get('Content-Type')
rv = rv.get_json()[str(place.id)]
for item in rv:
if item['id'] == place.id:
assert item['id'] == place.id
assert item['openatlasClassName'] == "place"
assert item['children'] == [feature.id]
item = item['properties']
assert item['name'] == place.name
assert item['description'] == place.description
assert item['aliases'] == [alias.name]
assert item['externalReferences']
assert item['timespan']
assert item['standardType']
assert item['files']
assert item['types']
rv = c.get(url_for('api_04.subunits', id_=place.id, count=True))
assert b'3' in rv.data
for rv in [
c.get(url_for('api_04.subunits', id_=place.id, format='xml')),
c.get(
url_for(
'api_04.subunits',
id_=place.id,
format='xml',
download=True))]:
assert b'Shire' in rv.data
# Test centroid
for id_ in [feature.id, feature_location.id]:
for format_ in ['lp', 'geojson', 'geojson-v2']:
rv = c.get(
url_for(
'api_04.entity',
id_=id_,
format=format_,
centroid='true'))
assert b'(autogenerated)' in rv.data
assert 'application/json' in rv.headers.get('Content-Type')
rv = c.get(
url_for('api_04.subunits', id_=place.id, centroid='true'))
assert b'(autogenerated)' in rv.data
assert 'application/json' in rv.headers.get('Content-Type')
rv = c.get(
url_for(
'api_04.view_class',
class_='all',
centroid='true',
limit=0))
assert b'(autogenerated)' in rv.data
assert 'application/json' in rv.headers.get('Content-Type')
rv = c.get(
url_for(
'api_04.display',
filename=f'{file.id}',
image_size='table'))
self.assertTrue(rv.headers['Content-Type'].startswith('image'))
# Test Error Handling
for rv in [
c.get(url_for('api_04.entity', id_=233423424)),
c.get(url_for('api_04.cidoc_class', class_='E18', last=1231))]:
rv = rv.get_json()
assert 'Entity does not exist' in rv['title']
rv = c.get(url_for('api_04.subunits', id_=actor.id))
assert 'ID is not a valid place' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.query',
entities=location.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
sort='desc',
column='id',
download=True,
last=place.id))
assert 'ID is last entity' in rv.get_json()['title']
rv = c.get(url_for('api_04.system_class', class_='Wrong'))
assert 'Invalid system_classes value' in rv.get_json()['title']
rv = c.get(url_for('api_04.query'))
assert 'No query parameters given' in rv.get_json()['title']
rv = c.get(url_for('api_04.cidoc_class', class_='e99999999'))
assert 'Invalid cidoc_classes value' in rv.get_json()['title']
rv = c.get(url_for('api_04.view_class', class_='Invalid'))
assert 'Invalid view_classes value' in rv.get_json()['title']
rv = c.get(url_for('api_04.latest', limit='99999999'))
assert 'Invalid limit value' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search='{"typeID":[{"operator":"equal",'
'"values":["Boundary Mark", "Height", "Dimension"],'
'"logicalOperator":"and"}]}'))
assert 'Invalid search value' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search='{"typeID":[{"operator":"like",'
'"values":["Boundary Mark", "Height", "Dimension"],'
'"logicalOperator":"and"}]}'))
assert 'Operator not supported' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search={
"All": [{
"operator": "notEqual",
"values": ["Boundary Mark", "Height"]}]}))
assert 'Invalid search category' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search={"typeName": [{"operator": "notEqual", "values": []}]}))
assert 'No search value' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search={
"beginFrom": [{
"operator": "notEqual",
"values": ["Help"]}]}))
assert 'Invalid search values' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search={
"beginFrom": [{
"operator": "notEqual",
"values": ["800-1-1", "Help"]}]}))
assert 'Invalid search values' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search='"beginFrom":[{"operator":"lesserThan",'
'"values":["2000-01-01"],'
'"logicalOperator":"or"}]}'))
assert 'Invalid search syntax' in rv.get_json()['title']
rv = c.get(url_for('api_04.type_entities', id_=1234))
assert 'Entity is not a type' in rv.get_json()['title']
rv = c.get(url_for('api_04.type_entities_all', id_=1234))
assert 'Entity is not a type' in rv.get_json()['title']
rv = c.get(url_for('api_04.system_class_count', type_id=999))
assert 'Entity is not a type' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search={
"typeName": [{
"operator": "notEqualT",
"values": ["Boundary Mark", "Height"],
"logicalOperator": "and"}]}))
assert 'Invalid compare operator' in rv.get_json()['title']
rv = c.get(
url_for(
'api_04.view_class',
class_='place',
search={
"typeName": [{
"operator": "notEqual",
"values": ["Boundary Mark", "Height"],
"logicalOperator": "xor"}]}))
assert 'Invalid logical operator' in rv.get_json()['title']
rv = c.get(
url_for('api_04.display', filename=f'{file_without_licences.id}'))
assert 'No license' in rv.get_json()['title']
rv = c.get(
url_for('api_04.display', filename=f'{file_without_file.id}'))
assert 'File not found' in rv.get_json()['title']
rv = c.get(url_for('api_04.iiif_manifest', version=2, id_=place.id))
assert 'File not found' in rv.get_json()['title']
rv = c.get(url_for('api_04.iiif_sequence', version=2, id_=place.id))
assert 'File not found' in rv.get_json()['title']
rv = c.get(url_for('api_04.display', filename=f'{file_not_public.id}'))
assert 'Not public' in rv.get_json()['title']
assert b'Endpoint not found' in c.get('/api/entity2').data
c.get(url_for('logout'))
app.config['ALLOWED_IPS'] = []
rv = c.get(url_for('api_04.view_class', class_='place'))
assert 'Access denied' in rv.get_json()['title']