Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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))
Exemplo n.º 4
0
    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_
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    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_
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
    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_
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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_
Exemplo n.º 13
0
    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_
Exemplo n.º 14
0
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}
Exemplo n.º 15
0
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}
Exemplo n.º 16
0
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}
Exemplo n.º 17
0
 def test_valid(self):
     with storage.open(self.preview_image()) as f:
         errors, hash = check_upload(f, 'preview', 'image/png')
         assert not errors
Exemplo n.º 18
0
 def test_upload_type_not_recognized(self):
     with self.assertRaises(ValueError):
         check_upload([], 'graphic', 'image/jpg')
Exemplo n.º 19
0
 def test_upload_type_not_recognized(self):
     with self.assertRaises(ValueError):
         check_upload([], 'graphic', 'image/jpg')
Exemplo n.º 20
0
 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
Exemplo n.º 21
0
 def test_not_valid(self):
     with self.assertRaises(ValueError):
         check_upload([], 'graphic', 'image/jpg')