• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python test_utils_.get_image_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: setUp

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


示例17: setUp

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


示例18: _promo_img_uploader

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


示例19: upload_icon

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


示例20: upload_preview

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.app_factory函数代码示例发布时间:2022-05-27
下一篇:
Python tests.user_factory函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap