This repository was archived by the owner on Sep 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_images.py
More file actions
66 lines (48 loc) · 2.13 KB
/
Copy pathtest_images.py
File metadata and controls
66 lines (48 loc) · 2.13 KB
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
# -*- coding: utf-8 -*-
import os
import unittest
from thumbnails.conf import settings
from thumbnails.images import SourceFile, Thumbnail
from .compat import mock
from .utils import has_installed
class ThumbnailTestCase(unittest.TestCase):
def setUp(self):
self.instance = Thumbnail(['n', 'ame'])
self.instance.size = 200, 400
def test_name(self):
self.assertEqual(self.instance.name, 'n/ame')
def test_path(self):
self.assertTrue(self.instance.path.endswith('thumbnails-cache/n/ame.jpg'))
def test_url(self):
self.assertTrue(self.instance.url.endswith('/n/ame.jpg'))
def test_width(self):
self.assertEqual(self.instance.width, 200)
def test_height(self):
self.assertEqual(self.instance.height, 400)
def test_ratio(self):
self.assertEqual(self.instance.ratio, 0.5)
def test_is_portrait(self):
self.assertTrue(self.instance.is_portrait)
self.instance.size = 400, 200
self.assertFalse(self.instance.is_portrait)
def test_is_landscape(self):
self.assertFalse(self.instance.is_landscape)
self.instance.size = 400, 200
self.assertTrue(self.instance.is_landscape)
@mock.patch('{}.exists'.format(settings.THUMBNAIL_STORAGE_BACKEND))
def test_exists(self, mock_exists):
self.instance = Thumbnail(['name'])
self.assertTrue(self.instance.exists)
mock_exists.assert_called_with(self.instance.path)
class SourceImageTestCase(unittest.TestCase):
FILE_PATH = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
def test_init(self):
self.assertEqual(SourceFile(self.FILE_PATH).file, self.FILE_PATH)
@unittest.skipIf(not has_installed('django'), 'Django not installed')
def test_django_image_files(self):
from django.db.models.fields import files
field = files.FileField()
f = SourceFile(files.FieldFile(field=field, instance=None, name=self.FILE_PATH))
self.assertEqual(f.file, self.FILE_PATH)
f = SourceFile(files.ImageFieldFile(field=field, instance=None, name=self.FILE_PATH))
self.assertEqual(f.file, self.FILE_PATH)