Unit test refactoring and improvements #776

Merged
merged 3 commits into from Oct 26, 2016
Prev

fake all PIL operations in tests

commit 2a0d75ec8f4da5bb182756db596228e64f982442 @peterbe peterbe committed Oct 26, 2016
@@ -15,6 +15,7 @@
from pipeline.storage import PipelineCachedStorage
from sorl.thumbnail.kvstores.base import KVStoreBase
+from sorl.thumbnail.engines.base import EngineBase
# Calm down the overly verbose sorl.thumbnail logging
logging.getLogger('sorl.thumbnail.base').setLevel(logging.INFO)
@@ -150,3 +151,38 @@ def _delete_raw(self, *keys):
def _find_keys_raw(self, prefix):
return [x for x in self.cache.keys() if x.startswith(prefix)]
+
+
+class _Image(object):
+ def __init__(self):
+ self.size = (1000, 1000)
+ self.mode = 'RGBA'
+ self.data = '\xa0'
+
+
+class FastSorlEngine(EngineBase):
+
+ def get_image(self, source):
+ return _Image()
+ # return StringIO()
+
+ def get_image_size(self, image):
+ return image.size
+
+ def _colorspace(self, image, colorspace):
+ return image
+
+ def _scale(self, image, width, height):
+ image.size = (width, height)
+ return image
+
+ def _crop(self, image, width, height, x_offset, y_offset):
+ image.size = (width, height)
+ return image
+
+ def _get_raw_data(self, image, *args, **kwargs):
+ return image.data
+
+ def is_valid_image(self, raw_data):
+ # print "RAW_DATA", repr(raw_data)
+ return bool(raw_data)
@@ -1168,7 +1168,7 @@ def test_rendering_additional_links(self):
)
def test_call_info_presence(self):
- event = Event.objects.get(title='Test event')
+ event = self._get_live_event()
event.call_info = 'More info'
event.archive_time = None
event.start_time = timezone.now() + datetime.timedelta(days=1)
@@ -1179,14 +1179,12 @@ def test_call_info_presence(self):
response = self.client.get(url)
eq_(response.status_code, 200)
ok_('More info' in response.content)
-
event.start_time = timezone.now()
event.save()
assert event.is_live()
response = self.client.get(url)
eq_(response.status_code, 200)
ok_('More info' in response.content)
-
event.archive_time = timezone.now()
event.save()
assert not event.is_live() and not event.is_upcoming()
@@ -123,3 +123,5 @@
# at all. In fact, it doesn't even use the LocMemCache.
THUMBNAIL_KVSTORE = 'airmozilla.base.tests.testbase.FastSorlKVStore'
+THUMBNAIL_ENGINE = 'airmozilla.base.tests.testbase.FastSorlEngine'
+