当前位置: 首页>>代码示例>>Python>>正文


Python test_utils_.get_image_path函数代码示例

本文整理汇总了Python中mkt.site.tests.test_utils_.get_image_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_path函数的具体用法?Python get_image_path怎么用?Python get_image_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_image_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _uploader

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)
开发者ID:j-barron,项目名称:zamboni,代码行数:34,代码来源:test_tasks.py

示例2: test_preview_modified

 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
开发者ID:ujdhesa,项目名称:zamboni,代码行数:8,代码来源:test_forms.py

示例3: test_icon_ok

    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))
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:9,代码来源:test_utils_.py

示例4: test_promo_img_too_small

    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))
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:9,代码来源:test_utils_.py

示例5: test_promo_img_ok

    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))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:9,代码来源:test_utils_.py

示例6: test_preview_too_small

    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))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:9,代码来源:test_utils_.py

示例7: test_preview_size

 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]})
开发者ID:clouserw,项目名称:zamboni,代码行数:10,代码来源:test_forms.py

示例8: test_ok

    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)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:test_forms.py

示例9: test_preview_size

 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]})
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:test_forms.py

示例10: setUp

 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}
开发者ID:Jobava,项目名称:zamboni,代码行数:11,代码来源:test_views_api.py

示例11: get_image

    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
开发者ID:j-barron,项目名称:zamboni,代码行数:11,代码来源:test_tasks.py

示例12: test_preview_size

 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]})
开发者ID:ayushagrawal288,项目名称:zamboni,代码行数:12,代码来源:test_forms.py

示例13: get_image

    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
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:12,代码来源:test_tasks.py

示例14: get_image

    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
开发者ID:Jobava,项目名称:zamboni,代码行数:13,代码来源:test_tasks.py

示例15: test_preview_size

 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]})
开发者ID:shahbaz17,项目名称:zamboni,代码行数:13,代码来源:test_forms.py


注:本文中的mkt.site.tests.test_utils_.get_image_path函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。