forked from jazzband/sorl-thumbnail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
589 lines (521 loc) · 22.7 KB
/
tests.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
#coding=utf-8
import logging
import operator
import os
import re
import shutil
from PIL import Image
from django.core.files.storage import default_storage
from django.template.loader import render_to_string
from django.test.client import Client
from django.utils import unittest
from os.path import join as pjoin
from sorl.thumbnail import default, get_thumbnail, delete
from sorl.thumbnail.conf import settings
from sorl.thumbnail.engines.pil_engine import Engine as PILEngine
from sorl.thumbnail.helpers import get_module_class, ThumbnailError
from sorl.thumbnail.images import ImageFile
from sorl.thumbnail.log import ThumbnailLogHandler
from sorl.thumbnail.parsers import parse_crop, parse_geometry
from sorl.thumbnail.templatetags.thumbnail import margin
from subprocess import Popen, PIPE
from thumbnail_tests.models import Item
from thumbnail_tests.storage import slog
handler = ThumbnailLogHandler()
handler.setLevel(logging.ERROR)
logging.getLogger('sorl.thumbnail').addHandler(handler)
class StorageTestCase(unittest.TestCase):
def setUp(self):
name = 'org.jpg'
os.makedirs(settings.MEDIA_ROOT)
fn = pjoin(settings.MEDIA_ROOT, name)
Image.new('L', (100, 100)).save(fn)
self.im = ImageFile(name)
def test_a_new(self):
slog.start_log()
get_thumbnail(self.im, '50x50')
log = slog.stop_log()
actions = [
'exists: test/cache/20/c7/20c7ceda51cd4d26f8f4f375cf9dddf3.jpg', # first see if the file exists
'open: org.jpg', # open the original for thumbnailing
'save: test/cache/20/c7/20c7ceda51cd4d26f8f4f375cf9dddf3.jpg', # save the file
'get_available_name: test/cache/20/c7/20c7ceda51cd4d26f8f4f375cf9dddf3.jpg', # cehck for filename
'exists: test/cache/20/c7/20c7ceda51cd4d26f8f4f375cf9dddf3.jpg', # called by get_available_name
]
self.assertEqual(log, actions)
def test_b_cached(self):
slog.start_log()
get_thumbnail(self.im, '50x50')
log = slog.stop_log()
self.assertEqual(log, []) # now this should all be in cache
def test_c_safe_methods(self):
slog.start_log()
im = default.kvstore.get(self.im)
im.url, im.x, im.y
log = slog.stop_log()
self.assertEqual(log, [])
def tearDown(self):
shutil.rmtree(settings.MEDIA_ROOT)
class ParsersTestCase(unittest.TestCase):
def testAliasCrop(self):
crop = parse_crop('center', (500, 500), (400, 400))
self.assertEqual(crop, (50, 50))
crop = parse_crop('right', (500, 500), (400, 400))
self.assertEqual(crop, (100, 50))
def testPercentCrop(self):
crop = parse_crop('50% 0%', (500, 500), (400, 400))
self.assertEqual(crop, (50, 0))
crop = parse_crop('10% 80%', (500, 500), (400, 400))
self.assertEqual(crop, (10, 80))
def testPxCrop(self):
crop = parse_crop('200px 33px', (500, 500), (400, 400))
self.assertEqual(crop, (100, 33))
def testBadCrop(self):
self.assertRaises(ThumbnailError, parse_crop, '-200px', (500, 500), (400, 400))
def testGeometry(self):
g = parse_geometry('222x30')
self.assertEqual(g, (222, 30))
g = parse_geometry('222')
self.assertEqual(g, (222, None))
g = parse_geometry('x999')
self.assertEqual(g, (None, 999))
class SimpleTestCaseBase(unittest.TestCase):
def setUp(self):
self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()
if not os.path.exists(settings.MEDIA_ROOT):
os.makedirs(settings.MEDIA_ROOT)
dims = [
(500, 500),
(100, 100),
(200, 100),
]
for dim in dims:
name = '%sx%s.jpg' % dim
fn = pjoin(settings.MEDIA_ROOT, name)
im = Image.new('L', dim)
im.save(fn)
Item.objects.get_or_create(image=name)
def tearDown(self):
shutil.rmtree(settings.MEDIA_ROOT)
class SimpleTestCase(SimpleTestCaseBase):
def testSimple(self):
item = Item.objects.get(image='500x500.jpg')
t = self.backend.get_thumbnail(item.image, '400x300', crop='center')
self.assertEqual(t.x, 400)
self.assertEqual(t.y, 300)
t = self.backend.get_thumbnail(item.image, '1200x900', crop='13% 89%')
self.assertEqual(t.x, 1200)
self.assertEqual(t.y, 900)
def testUpscale(self):
item = Item.objects.get(image='100x100.jpg')
t = self.backend.get_thumbnail(item.image, '400x300', upscale=False)
self.assertEqual(t.x, 100)
self.assertEqual(t.y, 100)
t = self.backend.get_thumbnail(item.image, '400x300', upscale=True)
self.assertEqual(t.x, 300)
self.assertEqual(t.y, 300)
def testUpscaleCrop(self):
item = Item.objects.get(image='200x100.jpg')
t = self.backend.get_thumbnail(item.image, '400x300', crop='center', upscale=False)
self.assertEqual(t.x, 200)
self.assertEqual(t.y, 100)
t = self.backend.get_thumbnail(item.image, '400x300', crop='center', upscale=True)
self.assertEqual(t.x, 400)
self.assertEqual(t.y, 300)
def testKVStore(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
self.kvstore.delete_thumbnails(im)
th1 = self.backend.get_thumbnail(im, '50')
th2 = self.backend.get_thumbnail(im, 'x50')
th3 = self.backend.get_thumbnail(im, '20x20')
self.assertEqual(
set([th1.key, th2.key, th3.key]),
set(self.kvstore._get(im.key, identity='thumbnails'))
)
self.kvstore.delete_thumbnails(im)
self.assertEqual(
None,
self.kvstore._get(im.key, identity='thumbnails')
)
def testIsPortrait(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
th = self.backend.get_thumbnail(im, '50x200', crop='center')
self.assertEqual(th.is_portrait(), True)
th = self.backend.get_thumbnail(im, '500x2', crop='center')
self.assertEqual(th.is_portrait(), False)
def testMargin(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
self.assertEqual(margin(im, '1000x1000'), '250px 250px 250px 250px')
self.assertEqual(margin(im, '800x1000'), '250px 150px 250px 150px')
self.assertEqual(margin(im, '500x500'), '0px 0px 0px 0px')
self.assertEqual(margin(im, '500x501'), '0px 0px 1px 0px')
self.assertEqual(margin(im, '503x500'), '0px 2px 0px 1px')
self.assertEqual(margin(im, '300x300'), '-100px -100px -100px -100px')
def testKVStoreGetSet(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
self.kvstore.delete(im)
self.assertEqual(self.kvstore.get(im), None)
self.kvstore.set(im)
self.assertEqual(im.size, [500, 500])
def test_cleanup1(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
self.kvstore.delete_thumbnails(im)
th = self.backend.get_thumbnail(im, '3x3')
self.assertEqual(th.exists(), True)
th.delete()
self.assertEqual(th.exists(), False)
self.assertEqual(self.kvstore.get(th).x, 3)
self.assertEqual(self.kvstore.get(th).y, 3)
self.kvstore.cleanup()
self.assertEqual(self.kvstore.get(th), None)
self.kvstore.delete(im)
def test_cleanup2(self):
self.kvstore.clear()
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
th3 = self.backend.get_thumbnail(im, '27x27')
th4 = self.backend.get_thumbnail(im, '81x81')
def keys_test(x, y, z):
self.assertEqual(x, len(list(self.kvstore._find_keys(identity='image'))))
self.assertEqual(y, len(list(self.kvstore._find_keys(identity='thumbnails'))))
self.assertEqual(z, len(self.kvstore._get(im.key, identity='thumbnails') or []))
keys_test(3, 1, 2)
th3.delete()
keys_test(3, 1, 2)
self.kvstore.cleanup()
keys_test(2, 1, 1)
th4.delete()
keys_test(2, 1, 1)
self.kvstore.cleanup()
keys_test(1, 0, 0)
self.kvstore.clear()
keys_test(0, 0, 0)
def test_storage_serialize(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
self.assertEqual(im.serialize_storage(), 'thumbnail_tests.storage.TestStorage')
self.assertEqual(
ImageFile('http://www.image.jpg').serialize_storage(),
'sorl.thumbnail.images.UrlStorage',
)
self.assertEqual(
ImageFile('http://www.image.jpg', default.storage).serialize_storage(),
'thumbnail_tests.storage.TestStorage',
)
self.assertEqual(
ImageFile('getit', default_storage).serialize_storage(),
'thumbnail_tests.storage.TestStorage',
)
def test_quality(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
th = self.backend.get_thumbnail(im, '100x100', quality=50)
p1 = Popen(['identify', '-verbose', th.storage.path(th.name)], stdout=PIPE)
p2 = Popen(['grep', '-c', 'Quality: 50'], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0].strip()
self.assertEqual(output, '1')
def test_image_file_deserialize(self):
im = ImageFile(Item.objects.get(image='500x500.jpg').image)
default.kvstore.set(im)
self.assertEqual(
default.kvstore.get(im).serialize_storage(),
'thumbnail_tests.storage.TestStorage',
)
im = ImageFile('http://www.aino.se/media/i/logo.png')
default.kvstore.set(im)
self.assertEqual(
default.kvstore.get(im).serialize_storage(),
'sorl.thumbnail.images.UrlStorage',
)
def test_abspath(self):
item = Item.objects.get(image='500x500.jpg')
image = ImageFile(item.image.path)
val = render_to_string('thumbnail20.html', {
'image': image,
}).strip()
im = self.backend.get_thumbnail(image, '32x32', crop='center')
self.assertEqual('<img src="%s">' % im.url, val)
def test_new_tag_style(self):
item = Item.objects.get(image='500x500.jpg')
image = ImageFile(item.image.path)
val = render_to_string('thumbnail20a.html', {
'image': image,
}).strip()
im = self.backend.get_thumbnail(image, '32x32', crop='center')
self.assertEqual('<img src="%s">' % im.url, val)
class TemplateTestCaseA(SimpleTestCaseBase):
def testModel(self):
item = Item.objects.get(image='500x500.jpg')
val = render_to_string('thumbnail1.html', {
'item': item,
}).strip()
self.assertEqual(val, u'<img style="margin:0px 0px 0px 0px" width="200" height="100">')
val = render_to_string('thumbnail2.html', {
'item': item,
}).strip()
self.assertEqual(val, u'<img style="margin:0px 50px 0px 50px" width="100" height="100">')
def test_nested(self):
item = Item.objects.get(image='500x500.jpg')
val = render_to_string('thumbnail6.html', {
'item': item,
}).strip()
self.assertEqual(val, ('<a href="/media/test/cache/ac/78/ac78a0326054e1d795cba4016ee54966.jpg">'
'<img src="/media/test/cache/4b/44/4b44d2d5f5cf0a35a1450873c88e28b7.jpg" width="400" height="400">'
'</a>'))
def test_serialization_options(self):
item = Item.objects.get(image='500x500.jpg')
for j in xrange(0, 20):
# we could be lucky...
val0 = render_to_string('thumbnail7.html', {
'item': item,
}).strip()
val1 = render_to_string('thumbnail7a.html', {
'item': item,
}).strip()
self.assertEqual(val0, val1)
def test_options(self):
item = Item.objects.get(image='500x500.jpg')
options = {
'crop': "center",
'upscale': True,
'quality': 77,
}
val0 = render_to_string('thumbnail8.html', {
'item': item,
'options': options,
}).strip()
val1 = render_to_string('thumbnail8a.html', {
'item': item,
}).strip()
self.assertEqual(val0, val1)
def test_progressive(self):
im = Item.objects.get(image='500x500.jpg').image
th = self.backend.get_thumbnail(im, '100x100', progressive=True)
path = pjoin(settings.MEDIA_ROOT, th.name)
p = Popen(['identify', '-verbose', path], stdout=PIPE)
p.wait()
m = re.search('Interlace: JPEG', p.stdout.read())
self.assertEqual(bool(m), True)
def test_nonprogressive(self):
im = Item.objects.get(image='500x500.jpg').image
th = self.backend.get_thumbnail(im, '100x100', progressive=False)
path = pjoin(settings.MEDIA_ROOT, th.name)
p = Popen(['identify', '-verbose', path], stdout=PIPE)
p.wait()
m = re.search('Interlace: None', p.stdout.read())
self.assertEqual(bool(m), True)
def test_orientation(self):
data_dir = pjoin(settings.MEDIA_ROOT, 'data')
shutil.copytree(settings.DATA_ROOT, data_dir)
ref = Image.open(pjoin(data_dir, '1_topleft.jpg'))
top = ref.getpixel((14, 7))
left = ref.getpixel((7, 14))
engine = PILEngine()
def epsilon(x, y):
if isinstance(x, (tuple, list)):
x = sum(x) / len(x)
if isinstance(y, (tuple, list)):
y = sum(y) / len(y)
return abs(x - y)
for name in sorted(os.listdir(data_dir)):
th = self.backend.get_thumbnail('data/%s' % name, '30x30')
im = engine.get_image(th)
self.assertLess(epsilon(top, im.getpixel((14, 7))), 10)
self.assertLess(epsilon(left, im.getpixel((7, 14))), 10)
exif = im._getexif()
if exif:
self.assertEqual(exif.get(0x0112), 1)
class TemplateTestCaseB(unittest.TestCase):
def tearDown(self):
try:
shutil.rmtree(settings.MEDIA_ROOT)
except Exception:
pass
def testUrl(self):
val = render_to_string('thumbnail3.html', {}).strip()
self.assertEqual(val, '<img style="margin:0px 0px 0px 0px" width="20" height="20">')
def testPortrait(self):
val = render_to_string('thumbnail4.html', {
'source': 'http://www.aino.se/media/i/logo.png',
'dims': 'x666',
}).strip()
self.assertEqual(val, '<img src="/media/test/cache/bd/5d/bd5db73239bfd68473481b6701a8167d.jpg" width="1985" height="666" class="landscape">')
def testEmpty(self):
val = render_to_string('thumbnail5.html', {}).strip()
self.assertEqual(val, '<p>empty</p>')
class TemplateTestCaseClient(unittest.TestCase):
def setUp(self):
self.org_settings = {}
params = {
'THUMBNAIL_DEBUG': False,
}
for k, v in params.iteritems():
self.org_settings[k] = getattr(settings, k)
setattr(settings, k, v)
def testEmptyError(self):
client = Client()
response = client.get('/thumbnail9.html')
self.assertEqual(response.content.strip(), '<p>empty</p>')
from django.core.mail import outbox
self.assertEqual(outbox[0].subject, '[sorl-thumbnail] ERROR: /thumbnail9.html')
end = outbox[0].body.split('\n\n')[-2][-20:-1]
self.assertEqual(end, 'tests/media/invalid')
def tearDown(self):
for k, v in self.org_settings.iteritems():
setattr(settings, k, v)
class CropTestCase(unittest.TestCase):
def setUp(self):
self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
self.engine = get_module_class(settings.THUMBNAIL_ENGINE)()
self.kvstore = get_module_class(settings.THUMBNAIL_KVSTORE)()
if not os.path.exists(settings.MEDIA_ROOT):
os.makedirs(settings.MEDIA_ROOT)
# portrait
name = 'portrait.jpg'
fn = pjoin(settings.MEDIA_ROOT, name)
im = Image.new('L', (100, 200))
im.paste(255, (0, 0, 100, 100))
im.save(fn)
self.portrait = ImageFile(Item.objects.get_or_create(image=name)[0].image)
self.kvstore.delete(self.portrait)
# landscape
name = 'landscape.jpg'
fn = pjoin(settings.MEDIA_ROOT, name)
im = Image.new('L', (200, 100))
im.paste(255, (0, 0, 100, 100))
im.save(fn)
self.landscape = ImageFile(Item.objects.get_or_create(image=name)[0].image)
self.kvstore.delete(self.landscape)
def testPortraitCrop(self):
def mean_pixel(x, y):
values = im.getpixel((x, y))
if not isinstance(values, (tuple, list)):
values = [values]
return reduce(operator.add, values) / len(values)
for crop in ('center', '88% 50%', '50px'):
th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
engine = PILEngine()
im = engine.get_image(th)
self.assertEqual(mean_pixel(50,0), 255)
self.assertEqual(mean_pixel(50,45), 255)
self.assertEqual(250 < mean_pixel(50,49) <= 255, True)
self.assertEqual(mean_pixel(50,55), 0)
self.assertEqual(mean_pixel(50,99), 0)
for crop in ('top', '0%', '0px'):
th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
engine = PILEngine()
im = engine.get_image(th)
for x in xrange(0, 99, 10):
for y in xrange(0, 99, 10):
self.assertEqual(250 < mean_pixel(x, y) <= 255, True)
for crop in ('bottom', '100%', '100px'):
th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
engine = PILEngine()
im = engine.get_image(th)
for x in xrange(0, 99, 10):
for y in xrange(0, 99, 10):
self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
def testLandscapeCrop(self):
def mean_pixel(x, y):
values = im.getpixel((x, y))
if not isinstance(values, (tuple, list)):
values = [values]
return reduce(operator.add, values) / len(values)
for crop in ('center', '50% 200%', '50px 700px'):
th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
engine = PILEngine()
im = engine.get_image(th)
self.assertEqual(mean_pixel(0, 50), 255)
self.assertEqual(mean_pixel(45, 50), 255)
self.assertEqual(250 < mean_pixel(49, 50) <= 255, True)
self.assertEqual(mean_pixel(55, 50), 0)
self.assertEqual(mean_pixel(99, 50), 0)
for crop in ('left', '0%', '0px'):
th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
engine = PILEngine()
im = engine.get_image(th)
for x in xrange(0, 99, 10):
for y in xrange(0, 99, 10):
self.assertEqual(250 < mean_pixel(x, y) <= 255, True)
for crop in ('right', '100%', '100px'):
th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
engine = PILEngine()
im = engine.get_image(th)
for x in xrange(0, 99, 10):
for y in xrange(0, 99, 10):
self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
def tearDown(self):
shutil.rmtree(settings.MEDIA_ROOT)
class DummyTestCase(unittest.TestCase):
def setUp(self):
self.backend = get_module_class(settings.THUMBNAIL_BACKEND)()
self.org_settings = {}
params = {
'THUMBNAIL_DUMMY': True,
}
for k, v in params.iteritems():
self.org_settings[k] = getattr(settings, k)
setattr(settings, k, v)
def test_dummy_tags(self):
val = render_to_string('thumbnaild1.html', {
'anything': 'AINO',
}).strip()
self.assertEqual(val, '<img style="margin:auto" width="200" height="100">')
val = render_to_string('thumbnaild2.html', {
'anything': None,
}).strip()
self.assertEqual(val, '<img src="http://dummyimage.com/300x200" width="300" height="200"><p>NOT</p>')
val = render_to_string('thumbnaild3.html', {
}).strip()
self.assertEqual(val, '<img src="http://dummyimage.com/600x400" width="600" height="400">')
def tearDown(self):
for k, v in self.org_settings.iteritems():
setattr(settings, k, v)
class ModelTestCase(SimpleTestCaseBase):
def test_field1(self):
self.kvstore.clear()
item = Item.objects.get(image='100x100.jpg')
im = ImageFile(item.image)
self.assertEqual(None, self.kvstore.get(im))
self.backend.get_thumbnail(im, '27x27')
self.backend.get_thumbnail(im, '81x81')
self.assertNotEqual(None, self.kvstore.get(im))
self.assertEqual(3, len(list(self.kvstore._find_keys(identity='image'))))
self.assertEqual(1, len(list(self.kvstore._find_keys(identity='thumbnails'))))
class BackendTest(SimpleTestCaseBase):
def test_delete(self):
im1 = Item.objects.get(image='100x100.jpg').image
im2 = Item.objects.get(image='500x500.jpg').image
default.kvstore.get_or_set(ImageFile(im1))
# exists in kvstore and in storage
self.assertTrue(bool(default.kvstore.get(ImageFile(im1))))
self.assertTrue(ImageFile(im1).exists())
# delete
delete(im1)
self.assertFalse(bool(default.kvstore.get(ImageFile(im1))))
self.assertFalse(ImageFile(im1).exists())
default.kvstore.get_or_set(ImageFile(im2))
# exists in kvstore and in storage
self.assertTrue(bool(default.kvstore.get(ImageFile(im2))))
self.assertTrue(ImageFile(im2).exists())
# delete
delete(im2, delete_file=False)
self.assertFalse(bool(default.kvstore.get(ImageFile(im2))))
self.assertTrue(ImageFile(im2).exists())
class TestInputCase(unittest.TestCase):
def setUp(self):
if not os.path.exists(settings.MEDIA_ROOT):
os.makedirs(settings.MEDIA_ROOT)
self.name = u'åäö.jpg'
fn = pjoin(settings.MEDIA_ROOT, self.name)
im = Image.new('L', (666, 666))
im.save(fn)
def test_nonascii(self):
# also test the get_thumbnail shortcut
th = get_thumbnail(self.name, '200x200')
self.assertEqual(
th.url,
'/media/test/cache/8a/17/8a17eff95c6ecf46f82d0807d93631e9.jpg'
)
def tearDown(self):
shutil.rmtree(settings.MEDIA_ROOT)