From: Chris Moylan Date: Wed, 6 Jul 2011 02:42:41 +0000 (-0500) Subject: finished basic submission testing X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ad35dd490cc0e82acea852befd25126c0dcb61ad;p=mediagoblin.git finished basic submission testing --- diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 4489692e..20c187e7 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import urlparse +from os import getcwd from nose.tools import assert_equal @@ -23,11 +24,12 @@ from mediagoblin.tests.tools import setup_fresh_app, get_test_app from mediagoblin import mg_globals from mediagoblin import util -IMAGE_ROOT = 'mediagoblin/tests/test_submission' +IMAGE_ROOT = getcwd() + '/mediagoblin/tests/test_submission/' GOOD_JPG = 'good.jpg' GOOD_PNG = 'good.png' -EVIL_JPG = '' -EVIL_PNG = '' +EVIL_FILE = 'evil' +EVIL_JPG = 'evil.jpg' +EVIL_PNG = 'evil.png' # TODO: @@ -45,6 +47,8 @@ class TestSubmission: test_user = mg_globals.database.User() test_user['username'] = u'chris' test_user['email'] = u'chris@example.com' + test_user['email_verified'] = True + test_user['status'] = u'active' test_user['pw_hash'] = auth_lib.bcrypt_gen_password_hash('toast') test_user.save() @@ -54,10 +58,25 @@ class TestSubmission: 'password': 'toast'}) def test_missing_fields(self): - # Test missing title - # Test missing description (if it's required) - # Test missing file - pass + # Test blank form + # --------------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', {}) + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html'] + form = context['submit_form'] + assert form.file.errors == [u'You must provide a file.'] + + # Test blank file + # --------------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', { + 'title': 'test title'}) + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html'] + form = context['submit_form'] + assert form.file.errors == [u'You must provide a file.'] + def test_normal_uploads(self): # FYI: @@ -67,15 +86,78 @@ class TestSubmission: # read from disk. # Test JPG + # -------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', { + 'title': 'Normal upload 1' + }, upload_files=[( + 'file', IMAGE_ROOT + GOOD_JPG)]) + + # User should be redirected + response.follow() + assert_equal( + urlparse.urlsplit(response.location)[2], + '/submit/success/') + assert util.TEMPLATE_TEST_CONTEXT.has_key( + 'mediagoblin/submit/success.html') + # Test PNG - # Test additional supported formats + # -------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', { + 'title': 'Normal upload 2' + }, upload_files=[( + 'file', IMAGE_ROOT + GOOD_PNG)]) + + response.follow() + assert_equal( + urlparse.urlsplit(response.location)[2], + '/submit/success/') + assert util.TEMPLATE_TEST_CONTEXT.has_key( + 'mediagoblin/submit/success.html') + + # TODO: Test additional supported formats - #resp = self.test_app.get('/') - #print resp - pass def test_malicious_uploads(self): + # Test non-suppoerted file with non-supported extension + # ----------------------------------------------------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', { + 'title': 'Malicious Upload 2' + }, upload_files=[( + 'file', IMAGE_ROOT + EVIL_FILE)]) + + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html'] + form = context['submit_form'] + assert form.file.errors == ['The file doesn\'t seem to be an image!'] + # Test non-supported file with .jpg extension + # ------------------------------------------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', { + 'title': 'Malicious Upload 2' + }, upload_files=[( + 'file', IMAGE_ROOT + EVIL_JPG)]) + + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html'] + form = context['submit_form'] + assert form.file.errors == ['The file doesn\'t seem to be an image!'] + # Test non-supported file with .png extension - pass + # ------------------------------------------- + util.clear_test_template_context() + response = self.test_app.post( + '/submit/', { + 'title': 'Malicious Upload 3' + }, upload_files=[( + 'file', IMAGE_ROOT + EVIL_PNG)]) + + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html'] + form = context['submit_form'] + assert form.file.errors == ['The file doesn\'t seem to be an image!'] diff --git a/mediagoblin/tests/test_submission/evil b/mediagoblin/tests/test_submission/evil new file mode 100755 index 00000000..775da664 Binary files /dev/null and b/mediagoblin/tests/test_submission/evil differ diff --git a/mediagoblin/tests/test_submission/evil.jpg b/mediagoblin/tests/test_submission/evil.jpg new file mode 100755 index 00000000..775da664 Binary files /dev/null and b/mediagoblin/tests/test_submission/evil.jpg differ diff --git a/mediagoblin/tests/test_submission/evil.png b/mediagoblin/tests/test_submission/evil.png new file mode 100755 index 00000000..775da664 Binary files /dev/null and b/mediagoblin/tests/test_submission/evil.png differ diff --git a/mediagoblin/tests/test_submission/good.jpg b/mediagoblin/tests/test_submission/good.jpg new file mode 100644 index 00000000..936458e9 Binary files /dev/null and b/mediagoblin/tests/test_submission/good.jpg differ diff --git a/mediagoblin/tests/test_submission/good.png b/mediagoblin/tests/test_submission/good.png new file mode 100644 index 00000000..c1eadf9c Binary files /dev/null and b/mediagoblin/tests/test_submission/good.png differ