From 6573573dd1650a73fe058df43dfb5770217b2afa Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Tue, 20 Mar 2012 23:59:28 -0400 Subject: [PATCH] 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. --- mediagoblin/tests/test_submission.py | 24 ++++++++++++++++++ mediagoblin/tests/test_submission/bigblue.png | Bin 0 -> 3142 bytes 2 files changed, 24 insertions(+) create mode 100644 mediagoblin/tests/test_submission/bigblue.png diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 36a0debb..8e30d9a2 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -15,7 +15,9 @@ # along with this program. If not, see . import urlparse +import os import re +import time from nose.tools import assert_equal, assert_true, assert_false 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, \ fixture_add_user from mediagoblin import mg_globals +from mediagoblin.processing import create_pub_filepath from mediagoblin.tools import template, common def resource(filename): @@ -33,6 +36,7 @@ GOOD_PNG = resource('good.png') EVIL_FILE = resource('evil') EVIL_JPG = resource('evil.jpg') EVIL_PNG = resource('evil.png') +BIG_BLUE = resource('bigblue.png') GOOD_TAG_STRING = 'yin,yang' BAD_TAG_STRING = 'rage,' + 'f' * 26 + 'u' * 26 @@ -192,3 +196,23 @@ class TestSubmission: # Test non-supported file with .png extension # ------------------------------------------- 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 diff --git a/mediagoblin/tests/test_submission/bigblue.png b/mediagoblin/tests/test_submission/bigblue.png new file mode 100644 index 0000000000000000000000000000000000000000..2b2c2a447e2c5a3d23a5c70152b1f9d3e5eb1805 GIT binary patch literal 3142 zcmeAS@N?(olHy`uVBq!ia0y~yU{(NO4kn;Th|olPAjMc5&&^HED`9XhN=+wt5ey7$+zbrOtPBYo7#MiOz}y1~j0_SwU@l3DKzaz8gro>+I~MD(D}p)^<|gVW zg4qsrIFg%?tV2=+vmF?0AW?#fkU|8c6}w5KDgs3sL6eXb0b>@);YiluP=pk=xDy4b zijcwKAq5*qE0UX#OhQtG6t+agH*y33(;#+} zP!y?-=3QvgL5cyQA{;4jX%d&TiEyNRLR49elut(UF5yxDDN&5(T|^Czz4Roi941Q9 zXx@d_;7A#KH1EQyd8BMfld>A6N*(Ze_rp=9HgUEk8G065fNgvRPgg&ebxsLQ08%&~ A{r~^~ literal 0 HcmV?d00001 -- 2.25.1