Esempio n. 1
0
 def test_too_small_not_ok(self):
     with local_storage.open(get_image_path('mkt_icon_72.png')) as f:
         img_file = SimpleUploadedFile('mkt_icon_72.png',
                                       f.read(),
                                       content_type='image/png')
         form = PromoImgForm({}, {'promo_img': img_file})
         ok_(not form.is_valid())
Esempio n. 2
0
 def test_animated_not_ok(self):
     with local_storage.open(get_image_path('animated.gif')) as f:
         img_file = SimpleUploadedFile('animated.gif',
                                       f.read(),
                                       content_type='image/gif')
         form = PromoImgForm({}, {'promo_img': img_file})
         ok_(not form.is_valid())
Esempio n. 3
0
def _uploader(resize_size, final_size):
    img = get_image_path('mozilla.png')
    original_size = (339, 128)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.ADDON_ICONS_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.png',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        shutil.copyfile(img, src.name)
        # Sanity check.
        with storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_icon(src.name, dest_name, resize_size, locally=True)
        eq_(val, {'icon_hash': 'bb362450'})
        with storage.open('%s-%s.png' % (dest_name, rsize)) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (
                fsize[1], dest_image.size[1]))

        if os.path.exists(dest_image.filename):
            os.remove(dest_image.filename)
        assert not os.path.exists(dest_image.filename)

    assert not os.path.exists(src.name)
Esempio n. 4
0
 def test_preview_modified(self, update_mock):
     name = 'transparent.png'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     shutil.copyfile(get_image_path(name), os.path.join(self.dest, name))
     assert form.is_valid(), form.errors
     form.save(self.addon)
     assert update_mock.called
Esempio n. 5
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))
Esempio n. 6
0
 def test_preview_modified(self, update_mock):
     name = 'transparent.png'
     form = forms.PreviewForm({'upload_hash': name,
                               'position': 1})
     shutil.copyfile(get_image_path(name), os.path.join(self.dest, name))
     assert form.is_valid(), form.errors
     form.save(self.addon)
     assert update_mock.called
Esempio n. 7
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))
Esempio 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))
Esempio n. 9
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))
Esempio n. 10
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))
Esempio n. 11
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))
Esempio n. 12
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     copy_stored_file(
         get_image_path(name), os.path.join(self.dest, name),
         src_storage=local_storage, dst_storage=private_storage)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
Esempio n. 13
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
Esempio n. 14
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
Esempio n. 15
0
    def test_ok(self):
        app = mkt.site.tests.app_factory()

        with local_storage.open(get_image_path('game_1050.jpg')) as f:
            img_file = SimpleUploadedFile('game_1050.jpg', f.read(),
                                          content_type='image/jpg')
            form = PromoImgForm({}, {'promo_img': img_file})

            ok_(form.is_valid())
            form.save(app)
Esempio n. 16
0
 def setUp(self):
     super(TestPreviewHandler, self).setUp()
     self.app = Webapp.objects.get(pk=337141)
     self.user = UserProfile.objects.get(pk=2519)
     AddonUser.objects.create(user=self.user, addon=self.app)
     self.file = base64.b64encode(
         open(get_image_path('preview.jpg'), 'r').read())
     self.list_url = reverse('app-preview',
                             kwargs={'pk': self.app.pk})
     self.good = {'file': {'data': self.file, 'type': 'image/jpg'},
                  'position': 1}
Esempio n. 17
0
    def test_ok(self):
        app = mkt.site.tests.app_factory()

        with local_storage.open(get_image_path('game_1050.jpg')) as f:
            img_file = SimpleUploadedFile('game_1050.jpg',
                                          f.read(),
                                          content_type='image/jpg')
            form = PromoImgForm({}, {'promo_img': img_file})

            ok_(form.is_valid())
            form.save(app)
Esempio n. 18
0
 def setUp(self):
     super(TestPreviewHandler, self).setUp()
     self.app = Webapp.objects.get(pk=337141)
     self.user = UserProfile.objects.get(pk=2519)
     AddonUser.objects.create(user=self.user, addon=self.app)
     self.file = base64.b64encode(
         open(get_image_path('preview.jpg'), 'r').read())
     self.list_url = reverse('app-preview',
                             kwargs={'pk': self.app.pk})
     self.good = {'file': {'data': self.file, 'type': 'image/jpg'},
                  'position': 1}
Esempio n. 19
0
    def get_image(self, filename):
        """Copy image to tmp and return tmp path.

        We do this because the task `resize_preview` removes the src file when
        finished.

        """
        src = get_image_path(filename)
        dst = os.path.join(settings.TMP_PATH, 'preview', filename)
        shutil.copy(src, dst)
        return dst
Esempio n. 20
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     with private_storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     # Since the task is a post-request-task and we are outside the normal
     # request-response cycle, manually send the tasks.
     post_request_task._send_tasks()
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
Esempio n. 21
0
    def get_image(self, filename):
        """Copy image to tmp and return tmp path.

        We do this because the task `resize_preview` removes the src file when
        finished.

        """
        src = get_image_path(filename)
        dst = os.path.join(settings.TMP_PATH, 'preview', filename)
        copy_stored_file(
            src, dst, src_storage=local_storage, dst_storage=private_storage)
        return dst
Esempio n. 22
0
    def get_image(self, filename):
        """Copy image to tmp and return tmp path.

        We do this because the task `resize_preview` removes the src file when
        finished.

        """
        src = get_image_path(filename)
        dst = os.path.join(settings.TMP_PATH, 'preview', filename)
        with open(src) as local_f:
            with storage.open(dst, 'w') as remote_f:
                shutil.copyfileobj(local_f, remote_f)
        return dst
Esempio n. 23
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     copy_stored_file(get_image_path(name),
                      os.path.join(self.dest, name),
                      src_storage=local_storage,
                      dst_storage=private_storage)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes, {
         u'image': [250, 297],
         u'thumbnail': [100, 119]
     })
Esempio n. 24
0
 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     copy_stored_file(
         get_image_path(name), os.path.join(self.dest, name),
         src_storage=local_storage, dst_storage=private_storage)
     assert form.is_valid(), form.errors
     form.save(self.webapp)
     # Since the task is a post-request-task and we are outside the normal
     # request-response cycle, manually send the tasks.
     post_request_task._send_tasks()
     eq_(self.webapp.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
Esempio n. 25
0
    def get_image(self, filename):
        """Copy image to tmp and return tmp path.

        We do this because the task `resize_preview` removes the src file when
        finished.

        """
        src = get_image_path(filename)
        dst = os.path.join(settings.TMP_PATH, 'preview', filename)
        with open(src) as local_f:
            with private_storage.open(dst, 'w') as remote_f:
                shutil.copyfileobj(local_f, remote_f)
        return dst
Esempio n. 26
0
    def setUp(self):
        img = get_image_path('mozilla.png')
        self.src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix=".png",
                                               delete=False)
        shutil.copyfile(img, self.src.name)

        patcher = mock.patch('subprocess.Popen')
        self.mock_popen = patcher.start()
        attrs = {
            'returncode': 0,
            'communicate.return_value': ('ouput', 'error')
        }
        self.mock_popen.return_value.configure_mock(**attrs)
        self.addCleanup(patcher.stop)
Esempio n. 27
0
 def setUp(self):
     self.img_path = tempfile.mktemp()
     copy_stored_file(get_image_path('mozilla.png'),
                      self.img_path,
                      src_storage=local_storage,
                      dest_storage=public_storage)
     patcher = mock.patch('subprocess.Popen')
     self.mock_popen = patcher.start()
     attrs = {
         'returncode': 0,
         'communicate.return_value': ('ouput', 'error')
     }
     self.mock_popen.return_value.configure_mock(**attrs)
     self.addCleanup(patcher.stop)
Esempio n. 28
0
 def setUp(self):
     self.img_path = tempfile.mktemp()
     copy_stored_file(get_image_path('mozilla.png'),
                      self.img_path,
                      src_storage=local_storage,
                      dest_storage=public_storage)
     patcher = mock.patch('subprocess.Popen')
     self.mock_popen = patcher.start()
     attrs = {
         'returncode': 0,
         'communicate.return_value': ('ouput', 'error')
     }
     self.mock_popen.return_value.configure_mock(**attrs)
     self.addCleanup(patcher.stop)
Esempio n. 29
0
def _promo_img_uploader(resize_size, final_size):
    img = get_image_path('game_1050.jpg')
    original_size = (1050, 591)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.WEBAPP_PROMO_IMG_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b',
                                          suffix='.jpg',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        copy_stored_file(img,
                         src.name,
                         src_storage=local_storage,
                         dest_storage=private_storage)
        # Sanity check.
        with private_storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_promo_imgs(src.name, dest_name, resize_size)
        eq_(val, {'promo_img_hash': '215dd2a2'})
        dest_img_name = '%s-%s.png' % (dest_name, rsize)
        with public_storage.open(dest_img_name) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (fsize[1], dest_image.size[1]))

        if public_storage.exists(dest_img_name):
            public_storage.delete(dest_img_name)
        assert not public_storage.exists(dest_img_name)

    assert not private_storage.exists(src.name)
Esempio n. 30
0
def _promo_img_uploader(resize_size, final_size):
    img = get_image_path('game_1050.jpg')
    original_size = (1050, 591)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.WEBAPP_PROMO_IMG_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.jpg',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        copy_stored_file(img, src.name, src_storage=local_storage,
                         dest_storage=private_storage)
        # Sanity check.
        with private_storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_promo_imgs(src.name, dest_name, resize_size)
        eq_(val, {'promo_img_hash': '215dd2a2'})
        dest_img_name = '%s-%s.png' % (dest_name, rsize)
        with public_storage.open(dest_img_name) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (
                fsize[1], dest_image.size[1]))

        if public_storage.exists(dest_img_name):
            public_storage.delete(dest_img_name)
        assert not public_storage.exists(dest_img_name)

    assert not private_storage.exists(src.name)
Esempio n. 31
0
 def test_animated_not_ok(self):
     with local_storage.open(get_image_path('animated.gif')) as f:
         img_file = SimpleUploadedFile('animated.gif', f.read(),
                                       content_type='image/gif')
         form = PromoImgForm({}, {'promo_img': img_file})
         ok_(not form.is_valid())
Esempio n. 32
0
 def upload_icon(self, image_file=None):
     if not image_file:
         image_file = get_image_path('mozilla-sq.png')
     return self._upload_image(self.webapp.get_dev_url('upload_icon'),
                               image_file=image_file)
Esempio n. 33
0
 def upload_preview(self, image_file=None):
     if not image_file:
         image_file = get_image_path('preview.jpg')
     return self._upload_image(self.webapp.get_dev_url('upload_preview'),
                               image_file=image_file)
 def test_packaged_detail(self):
     data = open(get_image_path('animated.png'), 'rb')
     self.client.post(self.packaged_upload, {'upload': data})
     upload = FileUpload.objects.get(name='animated.png')
     self.detail_view(self.packaged_detail, upload)
Esempio n. 35
0
import mkt
import mkt.site.tests
from lib.video import dummy, ffmpeg, get_library, totem
from lib.video.tasks import resize_video
from mkt.developers.models import UserLog
from mkt.site.fixtures import fixture
from mkt.site.tests.test_utils_ import get_image_path
from mkt.users.models import UserProfile
from mkt.webapps.models import Preview, Webapp


files = {
    'good': os.path.join(os.path.dirname(__file__),
                         'fixtures/disco-truncated.webm'),
    'bad': get_image_path('mozilla.png'),
}

older_output = """
Input #0, matroska,webm, from 'lib/video/fixtures/disco-truncated.webm':
  Duration: 00:00:10.00, start: 0.000000, bitrate: 298 kb/s
    Stream #0:0(eng): Video: vp8, yuv420p, 640x360, SAR 1:1 DAR 16:9,
    Stream #0:1(eng): Audio: vorbis, 44100 Hz, stereo, s16 (default)
"""

other_output = """
Input #0, matroska, from 'disco-truncated.webm':
  Metadata:
    doctype         : webm
"""
Esempio n. 36
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
Esempio n. 37
0
 def setUp(self):
     img = get_image_path('mozilla.png')
     self.src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix=".png",
                                            delete=False)
     shutil.copyfile(img, self.src.name)
Esempio n. 38
0
import mkt.site.tests
from lib.video import dummy, ffmpeg, get_library, totem
from lib.video.tasks import resize_video
from mkt.developers.models import UserLog
from mkt.site.fixtures import fixture
from mkt.site.storage_utils import (copy_stored_file, local_storage,
                                    private_storage)
from mkt.site.tests.test_utils_ import get_image_path
from mkt.users.models import UserProfile
from mkt.webapps.models import Preview, Webapp


files = {
    'good': os.path.join(os.path.dirname(__file__),
                         'fixtures/disco-truncated.webm'),
    'bad': get_image_path('mozilla.png'),
}

older_output = """
Input #0, matroska,webm, from 'lib/video/fixtures/disco-truncated.webm':
  Duration: 00:00:10.00, start: 0.000000, bitrate: 298 kb/s
    Stream #0:0(eng): Video: vp8, yuv420p, 640x360, SAR 1:1 DAR 16:9,
    Stream #0:1(eng): Audio: vorbis, 44100 Hz, stereo, s16 (default)
"""

other_output = """
Input #0, matroska, from 'disco-truncated.webm':
  Metadata:
    doctype         : webm
"""
Esempio n. 39
0
 def upload_preview(self, image_file=None):
     if not image_file:
         image_file = get_image_path('preview.jpg')
     return self._upload_image(self.webapp.get_dev_url('upload_preview'),
                               image_file=image_file)
Esempio n. 40
0
 def upload_icon(self, image_file=None):
     if not image_file:
         image_file = get_image_path('mozilla-sq.png')
     return self._upload_image(self.webapp.get_dev_url('upload_icon'),
                               image_file=image_file)
Esempio n. 41
0
 def test_too_small_not_ok(self):
     with local_storage.open(get_image_path('mkt_icon_72.png')) as f:
         img_file = SimpleUploadedFile('mkt_icon_72.png', f.read(),
                                       content_type='image/png')
         form = PromoImgForm({}, {'promo_img': img_file})
         ok_(not form.is_valid())
Esempio n. 42
0
 def test_packaged_detail(self):
     data = open(get_image_path('animated.png'), 'rb')
     self.client.post(self.packaged_upload, {'upload': data})
     upload = FileUpload.objects.get(name='animated.png')
     self.detail_view(self.packaged_detail, upload)