fixed tests and defaults
authorRodney Ewing <ewing.rj@gmail.com>
Fri, 14 Jun 2013 00:17:33 +0000 (17:17 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Mon, 26 Aug 2013 13:33:29 +0000 (06:33 -0700)
mediagoblin/config_spec.ini
mediagoblin/submit/views.py
mediagoblin/tests/resources.py
mediagoblin/tests/test_mgoblin_app.ini
mediagoblin/tests/test_submission.py
mediagoblin/tests/test_submission/medium.png [new file with mode: 0644]

index acefa5cc1135d79ef9527d9501e5d311826af469..be6132f600588e08a6df0850d454b7ab553e1d2d 100644 (file)
@@ -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. 
index 1a67486b0cea3c0afe5091f3e38bd8deccb95f9c..7382c43dea2901ecea7e528ea399943df97994db 100644 (file)
@@ -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",
index f7b3037d70c1db3894a6ef1704049599311f3ff5..4260df93301cb4b6e8e0bba1a6b7e182b0e4d110 100644 (file)
@@ -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):
index da0dffb95a3bf165707c3903c05e09781151c6c3..a2855d7a806e82ea298f20d4047af14018963a4b 100644 (file)
@@ -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/
index fdc322dc03ac4b1ce64b4f7218c2ddec84f5f2cc..e45ed36b71c686b26f1526ab0446935702f1b075 100644 (file)
@@ -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 (file)
index 0000000..e8b9ca0
Binary files /dev/null and b/mediagoblin/tests/test_submission/medium.png differ