-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_image.py
109 lines (88 loc) · 4.04 KB
/
test_image.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
from pathlib import Path
from shutil import copyfile
from flask import g, url_for
from openatlas import app
from openatlas.display.image_processing import safe_resize_image
from openatlas.display.util import profile_image
from openatlas.models.entity import Entity
from tests.base import TestBaseCase, get_hierarchy, insert
class ImageTest(TestBaseCase):
def test_image(self) -> None:
c = self.client
app.config['IMAGE_SIZE']['tmp'] = '1'
with app.test_request_context():
app.preprocess_request()
place = insert('place', 'Nostromos')
# Resizing through UI insert
with open(Path(app.root_path) / 'static'
/ 'images' / 'layout' / 'logo.png', 'rb') as img:
rv = c.post(
url_for('insert', class_='file', origin_id=place.id),
data={'name': 'OpenAtlas logo', 'file': img},
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_id = files[0].id
rv = c.get(
url_for('set_profile_image', id_=file_id, origin_id=place.id),
follow_redirects=True)
assert b'Remove' in rv.data
rv = c.get(url_for('delete', id_=file_id), follow_redirects=True)
assert b'The entry has been deleted' in rv.data
with app.test_request_context():
app.preprocess_request()
file_pathless = insert('file', 'Pathless_File')
file = insert('file', 'Test_File')
file.link('P2', g.types[get_hierarchy('License').subs[0]])
file_name = f'{file.id}.jpeg'
copyfile(
Path(app.root_path)
/ 'static' / 'images' / 'layout' / 'logo.png',
Path(app.config['UPLOAD_PATH'] / file_name))
file2 = insert('file', 'Test_File2')
file2.link('P2', g.types[get_hierarchy('License').subs[0]])
copyfile(
Path(app.root_path)
/ 'static' / 'images' / 'layout' / 'logo.png',
Path(app.config['UPLOAD_PATH'] / f'{file2.id}.jpeg'))
file_json = insert('file', 'Test')
copyfile(
Path(app.root_path) / 'static' / 'manifest.json',
Path(app.config['UPLOAD_PATH'] / f'{file_json.id}.json'))
safe_resize_image(file2.id, '.png', size="???")
profile_image(file_pathless)
rv = c.get(url_for('view', id_=file_json.id))
assert b'no preview available' in rv.data
rv = c.get(url_for('view', id_=file_pathless.id))
assert b'Missing file' in rv.data
rv = c.get(url_for('index', view='file'))
assert b'Test_File' in rv.data
rv = c.get(url_for('display_file', filename=file_name))
assert b'\xff' in rv.data
c.get(
url_for(
'display_file',
filename=file_name,
size=app.config['IMAGE_SIZE']['thumbnail']))
# assert b'\xff' in rv.data # GitHub struggles with this test
c.get(
url_for('api.display', filename=file_name, image_size='thumbnail'))
# assert b'\xff' in rv.data # GitHub struggles with this test
app.config['IMAGE_SIZE']['tmp'] = '<'
rv = c.get(url_for('view', id_=file.id))
assert b'Test_File' in rv.data
app.config['IMAGE_SIZE']['tmp'] = '1'
rv = c.get(url_for('resize_images'), follow_redirects=True)
assert b'Images were created' in rv.data
rv = c.get(
url_for('admin_delete_orphaned_resized_images'),
follow_redirects=True)
assert b'Resized orphaned images were 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