-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_file.py
325 lines (258 loc) · 11 KB
/
test_file.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
from pathlib import Path
from typing import Any
from flask import g, url_for
from openatlas import app
from openatlas.models.entity import Entity
from tests.base import TestBaseCase, get_hierarchy, insert
class FileTest(TestBaseCase):
def test_file(self) -> None:
c = self.client
with app.test_request_context():
app.preprocess_request()
place = insert('place', 'File keeper')
reference = insert('edition', 'Ancient Books', 'Really!')
license_type = get_hierarchy('License')
logo = Path(
app.root_path) / 'static' / 'images' / 'layout' / 'logo.png'
with open(logo, 'rb') as img_1, open(logo, 'rb') as img_2:
rv: Any = c.post(
url_for('insert', class_='file', origin_id=place.id),
data={
'name': 'OpenAtlas logo',
'public': True,
'file': [img_1, img_2]},
follow_redirects=True)
assert b'An entry has been created' in rv.data
with app.test_request_context():
app.preprocess_request()
files = Entity.get_by_class('file')
file_without_creator_id = files[0].id
rv = c.get(url_for('view', id_=file_without_creator_id))
assert b'but license is missing ' in rv.data
with open(logo, 'rb') as img:
rv = c.post(
url_for('insert', class_='file', origin_id=reference.id),
data={
'name': 'OpenAtlas logo',
'file': img,
'public': True,
str(license_type.id): license_type.subs[0]},
follow_redirects=True)
assert b'An entry has been created' in rv.data
with open(logo, 'rb') as img:
data = {
'name': 'IIIF File',
'file': img,
'creator': 'Max',
'license_holder': 'Moritz',
'public': True}
rv = c.post(url_for('insert', class_='file'), data=data)
iiif_id = rv.location.split('/')[-1]
license_ = []
for type_ in g.types.values():
if type_.name == 'Public domain':
license_ = type_
break
with app.test_request_context():
app.preprocess_request()
files = Entity.get_by_class('file')
iiif_file = Entity.get_by_id(iiif_id)
iiif_file.link('P2', license_)
rv = c.get(url_for('update', id_=iiif_id))
assert b'License' in rv.data
rv = c.post(
url_for('insert', class_='external_reference', origin_id=iiif_id),
data={'name': 'https://openatlas.eu'},
follow_redirects=True)
assert b'page' in rv.data
rv = c.get(
url_for('delete_iiif_file', id_=iiif_id),
follow_redirects=True)
assert b'IIIF file deleted' in rv.data
rv = c.get(url_for('convert_iiif_files'), follow_redirects=True)
assert b'All image files are converted' in rv.data
rv = c.get(url_for('delete_iiif_files'), follow_redirects=True)
assert b'IIIF files are deleted' in rv.data
filename = f'{iiif_id}.png'
with c.get(url_for('display_logo', filename=filename)):
pass
with c.get(url_for('download', filename=filename)):
pass
rv = c.get(url_for('logo'), data={'file': iiif_id})
assert b'OpenAtlas logo' in rv.data
rv = c.get(url_for('logo', id_=iiif_id), follow_redirects=True)
assert b'remove custom logo' in rv.data
rv = c.get(
url_for('logo_remove', action='remove_logo'),
follow_redirects=True)
assert b'Logo' in rv.data
with open(Path(app.root_path) / 'views' / 'index.py', 'rb') \
as invalid_file:
rv = c.post(
url_for('insert', class_='file', origin_id=place.id),
data={'name': 'Invalid file', 'file': invalid_file},
follow_redirects=True)
assert b'File type not allowed' in rv.data
rv = c.get(
url_for('remove_profile_image', entity_id=place.id),
follow_redirects=True)
assert b'Unset' not in rv.data
rv = c.post(
url_for('reference_add', id_=reference.id, view='file'),
data={'file': iiif_id, 'page': '777'},
follow_redirects=True)
assert b'777' in rv.data
rv = c.post(
url_for('update', id_=iiif_id),
data={'name': 'Updated file'},
follow_redirects=True)
assert b'Changes have been saved' in rv.data
rv = c.get(url_for('file_add', id_=iiif_id, view='actor'))
assert b'link actor' in rv.data
rv = c.post(
url_for('file_add', id_=iiif_id, view='actor'),
data={'checkbox_values': [place.id]},
follow_redirects=True)
assert b'File keeper' in rv.data
rv = c.get(url_for('update', id_=place.id))
assert b'File keeper' in rv.data
rv = c.post(
url_for('entity_add_file', id_=get_hierarchy('Sex').subs[0]),
data={'checkbox_values': str([iiif_id])},
follow_redirects=True)
assert b'Updated file' in rv.data
rv = c.get(url_for('view', id_=iiif_id))
assert b'enable IIIF view' in rv.data
rv = c.get(
url_for('make_iiif_available', id_=iiif_id),
follow_redirects=True)
assert b'IIIF converted' in rv.data
rv = c.get(url_for('view', id_=iiif_id))
assert b'View in IIIF' in rv.data
rv = c.get(url_for('view', id_=place.id))
assert b'view all IIIF images' in rv.data
with app.test_request_context():
app.preprocess_request()
license_url = insert("external_reference", "http://this.url/")
license_url.link('P67', license_)
iiif_file = Entity.get_by_id(iiif_id)
iiif_file.link('P2', license_)
rv = c.get(
url_for(
'api.iiif_manifest',
id_=iiif_id,
version=g.settings['iiif_version']))
rv = rv.get_json()
assert bool(rv['label'] == 'Updated file')
rv = c.get(url_for('api.iiif_sequence', id_=iiif_id))
assert bool(str(iiif_id) in rv.get_json()['@id'])
rv = c.get(url_for('api.iiif_image', id_=iiif_id))
assert bool(str(iiif_id) in rv.get_json()['@id'])
rv = c.get(url_for('api.iiif_canvas', id_=iiif_id))
assert bool(str(iiif_id) in rv.get_json()['@id'])
with app.test_request_context():
app.preprocess_request()
files[0].link('P2', g.types[get_hierarchy('License').subs[0]])
rv = c.get(url_for('api.licensed_file_overview'))
assert bool(len(rv.get_json().keys()) == 4)
rv = c.get(url_for('api.licensed_file_overview', download=True))
assert bool(len(rv.get_json().keys()) == 4)
rv = c.get(url_for('api.licensed_file_overview', file_id=iiif_id))
assert bool(len(rv.get_json().keys()) == 1)
rv = c.get(url_for('view_iiif', id_=place.id))
assert b'Mirador' in rv.data
rv = c.get(url_for('view', id_=place.id))
assert b'/full/!100,100/0/default.jpg' in rv.data
rv = c.get(url_for('view', id_=place.id))
assert b'Logo' in rv.data
rv = c.get(url_for('annotation_image_insert', id_=iiif_id))
assert b'annotate' in rv.data
rv = c.post(
url_for('annotation_image_insert', id_=iiif_id),
data={
'coordinate': '1.5,1.6,1.4,9.6,8.6,9.6,8.6,1.6',
'text': 'An interesting annotation',
'entity': place.id},
follow_redirects=True)
assert b'An interesting annotation' in rv.data
rv = c.get(url_for('view_iiif', id_=iiif_id))
assert b'Mirador' in rv.data
rv = c.get(
url_for(
'api.iiif_manifest',
id_=iiif_id,
version=g.settings['iiif_version'],
url="https://openatlas.eu"))
assert b'openatlas.eu' in rv.data
rv = c.get(
url_for(
'api.iiif_manifest',
id_=iiif_id,
version=g.settings['iiif_version'],
url="https://openatlaseu"))
assert b'URL not valid' in rv.data
rv = c.get(url_for('annotation_image_update', id_=1))
assert b'An interesting annotation' in rv.data
rv = c.get(
url_for(
'api.iiif_annotation_list',
image_id=iiif_id,
url="https://openatlas.eu"))
json = rv.get_json()
assert bool(str(iiif_id) in json['@id'])
annotation_id = json['resources'][0]['@id'].rsplit('/', 1)[-1]
rv = c.get(
url_for(
'api.iiif_annotation',
annotation_id=annotation_id.replace('.json', '')))
assert bool(annotation_id in rv.get_json()['@id'])
with app.test_request_context():
app.preprocess_request()
iiif_file.delete_links(['P67'])
rv = c.get(url_for('orphans'))
assert b'File keeper' in rv.data
rv = c.get(
url_for(
'admin_annotation_relink',
image_id=iiif_id,
entity_id=place.id),
follow_redirects=True)
assert b'Entities relinked' in rv.data
with app.test_request_context():
app.preprocess_request()
iiif_file.delete_links(['P67'])
rv = c.get(
url_for(
'admin_annotation_remove_entity',
annotation_id=1,
entity_id=place.id),
follow_redirects=True)
assert b'Entity removed from annotation' in rv.data
rv = c.post(
url_for('annotation_image_update', id_=1),
data={'text': 'A boring annotation'},
follow_redirects=True)
assert b'A boring annotation' in rv.data
rv = c.get(
url_for('annotation_image_delete', id_=1),
follow_redirects=True)
assert b'Annotation deleted' in rv.data
c.post(
url_for('annotation_image_insert', id_=iiif_id),
data={
'coordinate': '1.5,1.6,1.4,9.6,8.6,9.6,8.6,1.6',
'text': 'An interesting annotation',
'entity': place.id})
with app.test_request_context():
app.preprocess_request()
iiif_file.delete_links(['P67'])
rv = c.get(
url_for('admin_annotation_delete', id_=2),
follow_redirects=True)
assert b'Annotation deleted' in rv.data
with app.test_request_context():
app.preprocess_request()
files = Entity.get_by_class('file')
for file in files:
rv = c.get(url_for('delete', id_=file.id), follow_redirects=True)
assert b'The entry has been deleted' in rv.data