From 4601c30c2e80734cf3a18472c2e29a7f920b9604 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 31 Dec 2011 22:57:08 +0100 Subject: [PATCH] Fixed submission error handling and broken tests - Fixed broken test_auth test - Fixed error handling on submission, it now raises the exception if it is not explicitly relevant to file submission. --- mediagoblin/media_types/__init__.py | 2 +- mediagoblin/submit/views.py | 12 +++++++++--- mediagoblin/tests/test_auth.py | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py index 7b9bf0d7..e7eb1dde 100644 --- a/mediagoblin/media_types/__init__.py +++ b/mediagoblin/media_types/__init__.py @@ -73,7 +73,7 @@ def get_media_type_and_manager(filename): # Get the file extension ext = os.path.splitext(filename)[1].lower() else: - raise Exception( + raise InvalidFileType( _(u'Could not extract any file extension from "{filename}"').format( filename=filename)) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 443d0e52..60693bd6 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -31,7 +31,8 @@ from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.processing import mark_entry_failed, ProcessMedia from mediagoblin.messages import add_message, SUCCESS -from mediagoblin.media_types import get_media_type_and_manager, InvalidFileType +from mediagoblin.media_types import get_media_type_and_manager, \ + InvalidFileType, FileTypeNotSupported @require_active_login @@ -133,8 +134,13 @@ def submit_start(request): This section is intended to catch exceptions raised in mediagobling.media_types ''' - submit_form.file.errors.append( - e) + + if isinstance(e, InvalidFileType) or \ + isinstance(e, FileTypeNotSupported): + submit_form.file.errors.append( + e) + else: + raise return render_to_response( request, diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 9b0dea66..e54ffa5a 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -233,9 +233,9 @@ def test_register_views(test_app): ## Did we redirect to the proper page? Use the right template? assert_equal( urlparse.urlsplit(response.location)[2], - '/auth/forgot_password/email_sent/') + '/auth/login/') assert template.TEMPLATE_TEST_CONTEXT.has_key( - 'mediagoblin/auth/fp_email_sent.html') + 'mediagoblin/auth/login.html') ## Make sure link to change password is sent by email assert len(mail.EMAIL_TEST_INBOX) == 1 -- 2.25.1