本文整理汇总了Python中wagtail.images.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_compare_imagechooserblock
def test_compare_imagechooserblock(self):
image_model = get_image_model()
test_image_1 = image_model.objects.create(
title="Test image 1",
file=get_test_image_file(),
)
test_image_2 = image_model.objects.create(
title="Test image 2",
file=get_test_image_file(),
)
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('image', test_image_1, '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('image', test_image_2, '1'),
])),
)
result = comparison.htmldiff()
self.assertIn('<div class="preview-image deletion">', result)
self.assertIn('alt="Test image 1"', result)
self.assertIn('<div class="preview-image addition">', result)
self.assertIn('alt="Test image 2"', result)
self.assertIsInstance(result, SafeText)
self.assertTrue(comparison.has_changed())
示例2: test_footer_importable
def test_footer_importable(self):
content = constants.ARTICLE_PAGE_RESPONSE
content_copy = dict(content)
# Validate Assumptions
# The images have already been imported
# The record keeper has mapped the relationship
foreign_image_id = content["image"]["id"]
image = Image.objects.create(
title=content["image"]["title"],
file=get_test_image_file(),
)
foreign_social_media_image_id = content["social_media_image"]["id"]
social_media_image = Image.objects.create(
title=content["social_media_image"]["title"],
file=get_test_image_file(),
)
record_keeper = importers.RecordKeeper()
record_keeper.record_image_relation(foreign_image_id, image.id)
record_keeper.record_image_relation(
foreign_social_media_image_id, social_media_image.id)
class_ = FooterPage
page = FooterPage.create_page(
content_copy, class_, record_keeper=record_keeper)
self.check_article_and_footer_fields(page, content, record_keeper)
示例3: setUp
def setUp(self):
self.mk_main()
self.main = Main.objects.all().first()
self.factory = RequestFactory()
self.language_setting = Languages.objects.create(
site_id=self.main.get_site().pk)
self.english = SiteLanguageRelation.objects.create(
language_setting=self.language_setting,
locale='en',
is_active=True)
# LanguageRelation.objects.create(
# page=main, language=self.english)
self.french = SiteLanguageRelation.objects.create(
language_setting=self.language_setting,
locale='fr',
is_active=True)
# LanguageRelation.objects.create(
# page=self, language=self.french)
# Create an image for running tests on
self.image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
self.yourmind = self.mk_section(
self.section_index, title='Your mind')
self.yourmind_sub = self.mk_section(
self.yourmind, title='Your mind subsection')
self.mk_main2()
self.main2 = Main.objects.all().last()
self.language_setting2 = Languages.objects.create(
site_id=self.main2.get_site().pk)
self.english2 = SiteLanguageRelation.objects.create(
language_setting=self.language_setting2,
locale='en',
is_active=True)
self.spanish = SiteLanguageRelation.objects.create(
language_setting=self.language_setting2,
locale='es',
is_active=True)
# Create an image for running tests on
self.image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
self.image2 = Image.objects.create(
title="Test image 2",
file=get_test_image_file(),
)
self.yourmind2 = self.mk_section(
self.section_index2, title='Your mind')
self.yourmind_sub2 = self.mk_section(
self.yourmind2, title='Your mind subsection')
示例4: setUpTestData
def setUpTestData(cls):
image_model = get_image_model()
cls.test_image_1 = image_model.objects.create(
title="Test image 1",
file=get_test_image_file(),
)
cls.test_image_2 = image_model.objects.create(
title="Test image 2",
file=get_test_image_file(),
)
示例5: test_banner_importable
def test_banner_importable(self):
content = constants.BANNER_PAGE_RESPONSE
content_copy = dict(content)
# Validate Assumptions
# The images have already been imported
# The record keeper has mapped the relationship
foreign_image_id = content["banner"]["id"]
image = Image.objects.create(
title=content["banner"]["title"],
file=get_test_image_file(),
)
record_keeper = importers.RecordKeeper()
record_keeper.record_image_relation(foreign_image_id, image.id)
class_ = BannerPage
page = BannerPage.create_page(
content_copy, class_, record_keeper=record_keeper)
self.assertEqual(page.title, content["title"])
self.assertEqual(page.external_link, content["external_link"])
# check that banner link has been created
self.assertEqual(
(record_keeper.foreign_to_foreign_map["banner_link_page"]
[content["id"]]),
content["banner_link_page"]["id"])
# check that banner image has been attached
self.assertTrue(page.banner)
self.assertEqual(page.banner, image)
self.assertEqual(page.banner.title, content["banner"]["title"])
示例6: 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())
示例7: 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'
示例8: 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))
示例9: test_uploaded_avatar
def test_uploaded_avatar(self):
user_profile = UserProfile.get_for_user(self.test_user)
user_profile.avatar = get_test_image_file(filename='custom-avatar.png')
user_profile.save()
url = avatar_url(self.test_user)
self.assertIn('custom-avatar', url)
示例10: test_invalid_length
def test_invalid_length(self):
fil = Filter(spec='width-400|bgcolor-1234')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
self.assertRaises(ValueError, fil.run, image, BytesIO())
示例11: 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))
示例12: test_6_digit_hex
def test_6_digit_hex(self):
fil = Filter(spec='width-400|bgcolor-ffffff')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
out = fil.run(image, BytesIO())
self.assertFalse(out.has_alpha())
示例13: test_get_replica_image_returns_none
def test_get_replica_image_returns_none(self):
Image.objects.create(
title='local image',
file=get_test_image_file(),
)
self.importer.get_image_details()
replica_image = self.importer.get_replica_image('wrong_hash')
self.assertTrue(replica_image is None)
示例14: 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')
示例15: test_original_has_alpha
def test_original_has_alpha(self):
# Checks that the test image we're using has alpha
fil = Filter(spec='width-400')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
out = fil.run(image, BytesIO())
self.assertTrue(out.has_alpha())