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

Python utils.get_test_image_file函数代码示例

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

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



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

示例1: test_lazy_load_queryset_bulk

    def test_lazy_load_queryset_bulk(self):
        """
        Ensure that lazy loading StreamField works when gotten as part of a
        queryset list
        """
        file_obj = get_test_image_file()
        image_1 = Image.objects.create(title='Test image 1', file=file_obj)
        image_3 = Image.objects.create(title='Test image 3', file=file_obj)

        with_image = StreamModel.objects.create(body=json.dumps([
            {'type': 'image', 'value': image_1.pk},
            {'type': 'image', 'value': None},
            {'type': 'image', 'value': image_3.pk},
            {'type': 'text', 'value': 'foo'}]))

        with self.assertNumQueries(1):
            instance = StreamModel.objects.get(pk=with_image.pk)

        # Prefetch all image blocks
        with self.assertNumQueries(1):
            instance.body[0]

        # 1. Further image block access should not execute any db lookups
        # 2. The blank block '1' should be None.
        # 3. The values should be in the original order.
        with self.assertNumQueries(0):
            assert instance.body[0].value.title == 'Test image 1'
            assert instance.body[1].value is None
            assert instance.body[2].value.title == 'Test image 3'
开发者ID:kapito,项目名称:wagtail,代码行数:29,代码来源:test_streamfield.py


示例2: test_runs_operations_without_env_argument

    def test_runs_operations_without_env_argument(self):
        # The "env" argument was added in Wagtail 1.5. This tests that
        # image operations written for 1.4 will still work

        run_mock = Mock()

        def run(willow, image):
            run_mock(willow, image)

        self.operation_instance.run = run

        fil = Filter(spec='operation1|operation2')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        with warnings.catch_warnings(record=True) as ws:
            warnings.simplefilter('always')

            fil.run(image, BytesIO())

            self.assertEqual(len(ws), 2)
            self.assertIs(ws[0].category, RemovedInWagtail19Warning)

        self.assertEqual(run_mock.call_count, 2)
开发者ID:chrxr,项目名称:wagtail,代码行数:26,代码来源:test_image_operations.py


示例3: test_image_file_deleted_oncommit

 def test_image_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
         self.assertTrue(image.file.storage.exists(image.file.name))
     self.assertFalse(image.file.storage.exists(image.file.name))
开发者ID:timorieber,项目名称:wagtail,代码行数:7,代码来源:test_signal_handlers.py


示例4: test_invalid

 def test_invalid(self):
     fil = Filter(spec='width-400|format-foo')
     image = Image.objects.create(
         title="Test image",
         file=get_test_image_file(),
     )
     self.assertRaises(InvalidFilterSpecError, fil.run, image, BytesIO())
开发者ID:didorothy,项目名称:wagtail,代码行数:7,代码来源:test_image_operations.py


示例5: test_rendition_file_deleted_oncommit

 def test_rendition_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         rendition = image.get_rendition('original')
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
         rendition.delete()
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
     self.assertFalse(rendition.file.storage.exists(rendition.file.name))
开发者ID:timorieber,项目名称:wagtail,代码行数:8,代码来源:test_signal_handlers.py


示例6: test_runs_operations

    def test_runs_operations(self):
        self.operation_instance.run = Mock()

        fil = Filter(spec="operation1|operation2")
        image = Image.objects.create(title="Test image", file=get_test_image_file())
        fil.run(image, BytesIO())

        self.assertEqual(self.operation_instance.run.call_count, 2)
开发者ID:thrawny,项目名称:wagtail,代码行数:8,代码来源:test_image_operations.py


示例7: setUp

 def setUp(self):
     self.image = Image.objects.create(
         title='Test image',
         file=get_test_image_file())
     self.with_image = StreamModel.objects.create(body=json.dumps([
         {'type': 'image', 'value': self.image.pk},
         {'type': 'text', 'value': 'foo'}]))
     self.no_image = StreamModel.objects.create(body=json.dumps([
         {'type': 'text', 'value': 'foo'}]))
开发者ID:asmaps,项目名称:wagtail,代码行数:9,代码来源:test_streamfield.py


示例8: test_gif

    def test_gif(self):
        fil = Filter(spec='width-400|format-gif')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )
        out = fil.run(image, BytesIO())

        self.assertEqual(out.format_name, 'gif')
开发者ID:didorothy,项目名称:wagtail,代码行数:9,代码来源:test_image_operations.py


示例9: create_resource

    def create_resource(self):
        thumb = CFGOVImage.objects.create(
            title='test resource thumbnail',
            file=get_test_image_file()
        )

        resource = Resource(title='Test Resource')
        resource.thumbnail = thumb
        resource.save()
开发者ID:cfpb,项目名称:cfgov-refresh,代码行数:9,代码来源:test_organisms.py


示例10: setUp

    def setUp(self):
        self.login()

        img = Image.objects.create(
            title="LOTR cover",
            file=get_test_image_file(),
        )
        book = Book.objects.get(title="The Lord of the Rings")
        book.cover_image = img
        book.save()
开发者ID:kapito,项目名称:wagtail,代码行数:10,代码来源:test_simple_modeladmin.py


示例11: test_s3_files_use_secure_urls

    def test_s3_files_use_secure_urls(self):
        image_file = get_test_image_file(filename='test.png')

        Image = get_image_model()
        image = Image(file=image_file)

        self.assertEqual(
            image.file.url,
            'https://s3.amazonaws.com/test_s3_bucket/root/test.png'
        )
开发者ID:contolini,项目名称:cfgov-refresh,代码行数:10,代码来源:test_s3utils.py


示例12: test_custom_image_signal_handlers

    def test_custom_image_signal_handlers(self):
        #: Sadly signal receivers only get connected when starting django.
        #: We will re-attach them here to mimic the django startup behavior
        #: and get the signals connected to our custom model..
        signal_handlers.register_signal_handlers()

        image = get_image_model().objects.create(title="Test CustomImage", file=get_test_image_file())
        image_path = image.file.path
        image.delete()

        self.assertFalse(os.path.exists(image_path))
开发者ID:didorothy,项目名称:wagtail,代码行数:11,代码来源:test_signal_handlers.py


示例13: test_image_file_deleted

 def test_image_file_deleted(self):
     '''
         this test duplicates `test_image_file_deleted_oncommit` for
         django 1.8 support and can be removed once django 1.8 is no longer
         supported
     '''
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
     self.assertFalse(image.file.storage.exists(image.file.name))
开发者ID:timorieber,项目名称:wagtail,代码行数:11,代码来源:test_signal_handlers.py


示例14: setUp

    def setUp(self):
        self.document = Document(title="Test document")
        self.document.file.save(
            'example.txt',
            ContentFile("A boring example document")
        )
        self.image = CFGOVImage.objects.create(
            title='test',
            file=get_test_image_file()
        )

        CACHE_PURGED_URLS[:] = []
开发者ID:higs4281,项目名称:cfgov-refresh,代码行数:12,代码来源:test_caching.py


示例15: setUp

    def setUp(self):
        self.site = Site.objects.first()
        self.site.site_name = 'Example site'
        self.site.save()

        self.image = Image.objects.create(
            title='Test Image',
            file=get_test_image_file(),
        )
        self.page = self.site.root_page.add_child(instance=TestPage(
            title='Test Page',
            search_image=self.image,
            search_description='Some test content description',
        ))
开发者ID:takeflight,项目名称:wagtail-metadata,代码行数:14,代码来源:test_mixin.py


示例16: setUp

    def setUp(self):
        self.document = Document(title="Test document")
        self.document_without_file = Document(title="Document without file")
        self.document.file.save(
            'example.txt',
            ContentFile("A boring example document")
        )
        self.image = CFGOVImage.objects.create(
            title='test',
            file=get_test_image_file()
        )
        self.rendition = self.image.get_rendition('original')

        CACHE_PURGED_URLS[:] = []
开发者ID:cfpb,项目名称:cfgov-refresh,代码行数:14,代码来源:test_caching.py


示例17: test_runs_operations

    def test_runs_operations(self):
        run_mock = Mock()

        def run(willow, image, env):
            run_mock(willow, image, env)

        self.operation_instance.run = run

        fil = Filter(spec='operation1|operation2')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )
        fil.run(image, BytesIO())

        self.assertEqual(run_mock.call_count, 2)
开发者ID:didorothy,项目名称:wagtail,代码行数:16,代码来源:test_image_operations.py


示例18: setUp

    def setUp(self):
        self.image = Image.objects.create(
            title='Test image',
            file=get_test_image_file())

        self.instance = StreamModel.objects.create(body=json.dumps([
            {'type': 'rich_text', 'value': '<p>Rich text</p>'},
            {'type': 'image', 'value': self.image.pk},
            {'type': 'text', 'value': 'Hello, World!'}]))

        img_tag = self.image.get_rendition('original').img_tag()
        self.expected = ''.join([
            '<div class="block-rich_text"><div class="rich-text"><p>Rich text</p></div></div>',
            '<div class="block-image">{}</div>'.format(img_tag),
            '<div class="block-text">Hello, World!</div>',
        ])
开发者ID:AdamBolfik,项目名称:wagtail,代码行数:16,代码来源:test_streamfield.py


示例19: test_thumbnail

    def test_thumbnail(self):
        # Add a new image with source file
        image = get_image_model().objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        response = self.get_response(image.id)
        content = json.loads(response.content.decode('UTF-8'))

        self.assertIn('thumbnail', content)
        self.assertEqual(content['thumbnail']['width'], 165)
        self.assertEqual(content['thumbnail']['height'], 123)
        self.assertTrue(content['thumbnail']['url'].startswith('/media/images/test'))

        # Check that source_image_error didn't appear
        self.assertNotIn('source_image_error', content['meta'])
开发者ID:didorothy,项目名称:wagtail,代码行数:17,代码来源:test_images.py


示例20: check_template_meta_image_url

    def check_template_meta_image_url(self, expected_root):
        """Template meta tags should use an absolute image URL."""
        image_file = get_test_image_file(filename='foo.png')
        image = mommy.make(CFGOVImage, file=image_file)
        page = LearnPage(social_sharing_image=image)
        response = page.serve(page.dummy_request())
        response.render()

        rendition_url = image.get_rendition('original').url

        self.assertContains(
            response,
            (
                '<meta property="og:image" content='
                '"{}{}">'.format(expected_root, rendition_url)
            ),
            html=True
        )
开发者ID:OrlandoSoto,项目名称:cfgov-refresh,代码行数:18,代码来源:test_meta_image.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.generate_signature函数代码示例发布时间:2022-05-26
下一篇:
Python rect.Rect类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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