本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'
示例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)
示例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))
示例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())
示例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))
示例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)
示例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'}]))
示例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')
示例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()
示例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()
示例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'
)
示例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))
示例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))
示例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[:] = []
示例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',
))