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)
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)