def test_icon_too_small(self): with local_storage.open(get_image_path('mkt_icon_72.png')) as f: errors, upload_hash = check_upload(f, 'icon', 'image/png') ok_(errors) ok_(upload_hash) tmp_img_path = os.path.join(settings.TMP_PATH, 'icon', upload_hash) ok_(private_storage.exists(tmp_img_path))
def test_promo_img_too_small(self): with local_storage.open(get_image_path('preview.jpg')) as f: errors, upload_hash = check_upload(f, 'promo_img', 'image/png') ok_(errors) ok_(upload_hash) tmp_img_path = os.path.join(settings.TMP_PATH, 'promo_img', upload_hash) ok_(os.path.isfile(tmp_img_path))
def test_preview_too_small(self): with local_storage.open(get_image_path('mkt_icon_72.png')) as f: errors, upload_hash = check_upload(f, 'preview', 'image/png') ok_(errors) ok_(upload_hash) tmp_img_path = os.path.join(settings.TMP_PATH, 'preview', upload_hash) ok_(private_storage.exists(tmp_img_path))
def clean_file(self): file_ = self.cleaned_data.get("file", {}) file_obj = parse(file_) errors, hash_ = check_upload(file_obj, self.upload_type, file_["type"]) if errors: raise forms.ValidationError(errors) self.hash_ = hash_ return file_
def test_promo_img_ok(self): with local_storage.open(get_image_path('game_1050.jpg')) as f: errors, upload_hash = check_upload(f, 'promo_img', 'image/png') ok_(not errors) ok_(upload_hash) tmp_img_path = os.path.join(settings.TMP_PATH, 'promo_img', upload_hash) ok_(private_storage.exists(tmp_img_path))
def clean_file(self): file_ = self.cleaned_data.get('file', {}) file_obj = parse(file_) errors, hash_ = check_upload(file_obj, 'preview', file_['type']) if errors: raise forms.ValidationError(errors) self.hash_ = hash_ return file_
def test_icon_ok(self): with local_storage.open(get_image_path('mozilla-sq.png')) as f: errors, upload_hash = check_upload(f, 'icon', 'image/png') ok_(not errors) ok_(upload_hash) tmp_img_path = os.path.join(settings.TMP_PATH, 'icon', upload_hash) ok_(os.path.isfile(tmp_img_path))
def clean_promo_img(self): image = self.cleaned_data[self.upload_type] errors, upload_hash = check_upload(image, self.upload_type, image.content_type) if errors: log.info('Promo img errors: %s' % errors) raise forms.ValidationError(errors) self.upload_hash = upload_hash return image
def clean_file(self): file_ = self.cleaned_data.get('file', {}) try: if not set(['data', 'type']).issubset(set(file_.keys())): raise forms.ValidationError('Type and data are required.') except AttributeError: raise forms.ValidationError('File must be a dictionary.') file_obj = StringIO.StringIO(base64.b64decode(file_['data'])) errors, hash_ = check_upload(file_obj, 'graphic', file_['type']) if errors: raise forms.ValidationError(errors) self.hash_ = hash_ return file_
def clean_file(self): file_ = self.cleaned_data.get('file', {}) try: if not set(['data', 'type']).issubset(set(file_.keys())): raise forms.ValidationError('Type and data are required.') except AttributeError: raise forms.ValidationError('File must be a dictionary.') file_obj = StringIO.StringIO(base64.b64decode(file_['data'])) errors, hash_ = check_upload(file_obj, 'image', file_['type']) if errors: raise forms.ValidationError(errors) self.hash_ = hash_ return file_
def ajax_upload_media(request, upload_type): errors = [] upload_hash = "" if "upload_image" in request.FILES: upload_preview = request.FILES["upload_image"] upload_preview.seek(0) content_type = upload_preview.content_type errors, upload_hash = check_upload(upload_preview, upload_type, content_type) else: errors.append(_("There was an error uploading your preview.")) if errors: upload_hash = "" return {"upload_hash": upload_hash, "errors": errors}
def ajax_upload_media(request, upload_type): errors = [] upload_hash = '' if 'upload_image' in request.FILES: upload_preview = request.FILES['upload_image'] upload_preview.seek(0) content_type = upload_preview.content_type errors, upload_hash = check_upload(upload_preview, upload_type, content_type) else: errors.append(_('There was an error uploading your preview.')) if errors: upload_hash = '' return {'upload_hash': upload_hash, 'errors': errors}
def test_valid(self): with storage.open(self.preview_image()) as f: errors, hash = check_upload(f, 'preview', 'image/png') assert not errors
def test_upload_type_not_recognized(self): with self.assertRaises(ValueError): check_upload([], 'graphic', 'image/jpg')
def test_valid(self): with storage.open(get_image_path('preview.jpg')) as f: errors, hash = check_upload(f, 'preview', 'image/png') assert not errors
def test_not_valid(self): with self.assertRaises(ValueError): check_upload([], 'graphic', 'image/jpg')