From: Rodney Ewing Date: Fri, 14 Jun 2013 00:17:33 +0000 (-0700) Subject: fixed tests and defaults X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=001a50a85085a9cd6c713a7934f16c9b69b8760b;p=mediagoblin.git fixed tests and defaults --- diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index acefa5cc..be6132f6 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -76,7 +76,7 @@ plugin_web_path = string(default="/plugin_static/") plugin_linked_assets_dir = string(default="%(here)s/user_dev/plugin_static/") # Default user upload limit (in Mb) -#upload_limit = integer(default=500) +upload_limit = integer(default=None) [jinja2] # Jinja2 supports more directives than the minimum required by mediagoblin. diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1a67486b..7382c43d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -107,9 +107,7 @@ def submit_start(request): # Check if user is over upload limit if upload_limit and (user.uploaded + file_size) >= upload_limit: - messages.add_message( - request, - messages.WARNING, + submit_form.file.errors.append( _('Sorry, uploading this file will put you over your' ' upload limit.')) return redirect(request, "mediagoblin.submit.start", diff --git a/mediagoblin/tests/resources.py b/mediagoblin/tests/resources.py index f7b3037d..4260df93 100644 --- a/mediagoblin/tests/resources.py +++ b/mediagoblin/tests/resources.py @@ -29,6 +29,7 @@ EVIL_JPG = resource('evil.jpg') EVIL_PNG = resource('evil.png') BIG_BLUE = resource('bigblue.png') GOOD_PDF = resource('good.pdf') +MED_PNG = resource('medium.png') def resource_exif(f): diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini index da0dffb9..a2855d7a 100644 --- a/mediagoblin/tests/test_mgoblin_app.ini +++ b/mediagoblin/tests/test_mgoblin_app.ini @@ -13,6 +13,8 @@ tags_max_length = 50 # So we can start to test attachments: allow_attachments = True +upload_limit = 500 + [storage:publicstore] base_dir = %(here)s/user_dev/media/public base_url = /mgoblin_media/ diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index fdc322dc..e45ed36b 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -31,7 +31,7 @@ from mediagoblin.media_types.image import ImageMediaManager from mediagoblin.media_types.pdf.processing import check_prerequisites as pdf_check_prerequisites from .resources import GOOD_JPG, GOOD_PNG, EVIL_FILE, EVIL_JPG, EVIL_PNG, \ - BIG_BLUE, GOOD_PDF, GPS_JPG + BIG_BLUE, GOOD_PDF, GPS_JPG, MED_PNG GOOD_TAG_STRING = u'yin,yang' BAD_TAG_STRING = unicode('rage,' + 'f' * 26 + 'u' * 26) @@ -154,29 +154,63 @@ class TestSubmission: def test_default_upload_limits(self): self.user_upload_limits(uploaded=500) + # User uploaded should be 500 + assert self.test_user.uploaded == 500 + response, context = self.do_post({'title': u'Normal upload 4'}, do_follow=True, **self.upload_data(GOOD_JPG)) self.check_url(response, '/u/{0}/'.format(self.test_user.username)) assert 'mediagoblin/user_pages/user.html' in context + # Reload user + self.test_user = User.query.filter_by( + username=self.test_user.username + ).first() + + # Shouldn't have uploaded + assert self.test_user.uploaded == 500 + def test_user_upload_limit(self): self.user_upload_limits(uploaded=25, upload_limit=25) + # User uploaded should be 25 + assert self.test_user.uploaded == 25 + response, context = self.do_post({'title': u'Normal upload 4'}, do_follow=True, **self.upload_data(GOOD_JPG)) self.check_url(response, '/u/{0}/'.format(self.test_user.username)) assert 'mediagoblin/user_pages/user.html' in context + # Reload user + self.test_user = User.query.filter_by( + username=self.test_user.username + ).first() + + # Shouldn't have uploaded + assert self.test_user.uploaded == 25 + def test_user_under_limit(self): self.user_upload_limits(uploaded=499) - response, context = self.do_post({'title': u'Normal upload 4'}, - do_follow=True, - **self.upload_data(GOOD_JPG)) - self.check_url(response, '/u/{0}/'.format(self.test_user.username)) - assert 'mediagoblin/user_pages/user.html' in context + # User uploaded should be 499 + assert self.test_user.uploaded == 499 + + response, context = self.do_post({'title': u'Normal upload 6'}, + do_follow=False, + **self.upload_data(MED_PNG)) + form = context['mediagoblin/submit/start.html']['submit_form'] + assert form.file.errors == [u'Sorry, uploading this file will put you' + ' over your upload limit.'] + + # Reload user + self.test_user = User.query.filter_by( + username=self.test_user.username + ).first() + + # Shouldn't have uploaded + assert self.test_user.uploaded == 499 def check_media(self, request, find_data, count=None): media = MediaEntry.query.filter_by(**find_data) diff --git a/mediagoblin/tests/test_submission/medium.png b/mediagoblin/tests/test_submission/medium.png new file mode 100644 index 00000000..e8b9ca00 Binary files /dev/null and b/mediagoblin/tests/test_submission/medium.png differ