Add tests for image processing. Check filenames and image sizes.

This test helps verify that bug #261 is actually fixed.

In order to test that all the processed images are smaller, I needed to add
an image that's bigger than processing.MEDIUM_SIZE, hence bigblue.png.
This commit is contained in:
Brett Smith 2012-03-20 23:59:28 -04:00
parent e75d4a0dd5
commit 6573573dd1
2 changed files with 24 additions and 0 deletions

View File

@ -15,7 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import urlparse import urlparse
import os
import re import re
import time
from nose.tools import assert_equal, assert_true, assert_false from nose.tools import assert_equal, assert_true, assert_false
from pkg_resources import resource_filename from pkg_resources import resource_filename
@ -23,6 +25,7 @@ from pkg_resources import resource_filename
from mediagoblin.tests.tools import setup_fresh_app, get_test_app, \ from mediagoblin.tests.tools import setup_fresh_app, get_test_app, \
fixture_add_user fixture_add_user
from mediagoblin import mg_globals from mediagoblin import mg_globals
from mediagoblin.processing import create_pub_filepath
from mediagoblin.tools import template, common from mediagoblin.tools import template, common
def resource(filename): def resource(filename):
@ -33,6 +36,7 @@ GOOD_PNG = resource('good.png')
EVIL_FILE = resource('evil') EVIL_FILE = resource('evil')
EVIL_JPG = resource('evil.jpg') EVIL_JPG = resource('evil.jpg')
EVIL_PNG = resource('evil.png') EVIL_PNG = resource('evil.png')
BIG_BLUE = resource('bigblue.png')
GOOD_TAG_STRING = 'yin,yang' GOOD_TAG_STRING = 'yin,yang'
BAD_TAG_STRING = 'rage,' + 'f' * 26 + 'u' * 26 BAD_TAG_STRING = 'rage,' + 'f' * 26 + 'u' * 26
@ -192,3 +196,23 @@ class TestSubmission:
# Test non-supported file with .png extension # Test non-supported file with .png extension
# ------------------------------------------- # -------------------------------------------
self.check_false_image('Malicious Upload 3', EVIL_PNG) self.check_false_image('Malicious Upload 3', EVIL_PNG)
def test_processing(self):
data = {'title': 'Big Blue'}
response, request = self.do_post(data, *REQUEST_CONTEXT, do_follow=True,
**self.upload_data(BIG_BLUE))
media = self.check_media(request, data, 1)
last_size = 1024 ** 3 # Needs to be larger than bigblue.png
for key, basename in (('original', 'bigblue.png'),
('medium', 'bigblue.medium.png'),
('thumb', 'bigblue.thumbnail.png')):
# Does the processed image have a good filename?
filename = resource_filename(
'mediagoblin.tests',
os.path.join('test_user_dev/media/public',
*media['media_files'].get(key, [])))
assert_true(filename.endswith('_' + basename))
# Is it smaller than the last processed image we looked at?
size = os.stat(filename).st_size
assert_true(last_size > size)
last_size = size

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB