本文整理汇总了Python中wagtail.images.tests.utils.get_test_image_file方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get_test_image_file方法的具体用法?Python utils.get_test_image_file怎么用?Python utils.get_test_image_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.images.tests.utils
的用法示例。
在下文中一共展示了utils.get_test_image_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def setUp(self):
super().setUp()
self.site = Site.objects.get()
self.organisation = TestOrganisation.objects.create(
site=self.site,
name='Test organisation',
phone_number='555-1234',
email='org@example.com',
twitter_handle='org',
facebook_url='http://facebook.com/org',
)
root_page = self.site.root_page
self.image = Image.objects.create(title='Test image', file=get_test_image_file())
self.person = root_page.add_child(instance=PersonPage(
title='Alex Citizen',
bio='Alex did some things',
date_of_birth=datetime.date(1970, 1, 1),
photo=self.image,
))
示例2: test_thumbnail
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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'])
示例3: setUp
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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': 'rich_text', 'value': '<p>Привет, Микола</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"><p>Rich text</p></div>',
'<div class="block-rich_text"><p>Привет, Микола</p></div>',
'<div class="block-image">{}</div>'.format(img_tag),
'<div class="block-text">Hello, World!</div>',
])
示例4: test_api_v2_single_image
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def test_api_v2_single_image(self):
response = self.client.get('/apps/cms/api/v2/images/')
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 0)
self.assertEqual(response_dict['items'], [])
expected_title = "Test image"
image = Image.objects.create(
title=expected_title,
file=get_test_image_file(),
)
response = self.client.get('/apps/cms/api/v2/images/')
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 1)
returned_title = response_dict['items'][0]['title']
self.assertEqual(expected_title, returned_title)
示例5: test_api_v2_single_document
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def test_api_v2_single_document(self):
response = self.client.get('/apps/cms/api/v2/documents/')
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 0)
self.assertEqual(response_dict['items'], [])
expected_title = "Test document"
image = Document.objects.create(
title=expected_title,
file=get_test_image_file(),
)
response = self.client.get('/apps/cms/api/v2/documents/')
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 1)
returned_title = response_dict['items'][0]['title']
self.assertEqual(expected_title, returned_title)
示例6: setUp
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def setUp(self):
self.site = Site.objects.first()
self.site.site_name = 'Example site'
self.site.save()
self.factory = RequestFactory()
self.request = self.factory.get('/test/')
self.request.site = self.site
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',
))
self.test_model = TestModel.objects.create()
示例7: setUp
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def setUp(self):
super().setUp()
self.image = Image.objects.create(title='Test image', file=get_test_image_file())
示例8: test_uploaded_avatar
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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)
示例9: test_compare_imagechooserblock
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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, SafeString)
self.assertTrue(comparison.has_changed())
示例10: setUpTestData
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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(),
)
示例11: setUpTestData
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def setUpTestData(cls):
# Create an image for running tests on
cls.image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
示例12: test_rendition_file_deleted_oncommit
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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')
filename = rendition.file.name
self.assertTrue(rendition.file.storage.exists(filename))
rendition.delete()
self.assertTrue(rendition.file.storage.exists(filename))
self.assertFalse(rendition.file.storage.exists(filename))
示例13: test_document_file_deleted_oncommit
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def test_document_file_deleted_oncommit(self):
with transaction.atomic():
document = get_document_model().objects.create(title="Test Image", file=get_test_image_file())
filename = document.file.name
self.assertTrue(document.file.storage.exists(filename))
document.delete()
self.assertTrue(document.file.storage.exists(filename))
self.assertFalse(document.file.storage.exists(filename))
示例14: setUp
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
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()
示例15: test_can_search_documents
# 需要导入模块: from wagtail.images.tests import utils [as 别名]
# 或者: from wagtail.images.tests.utils import get_test_image_file [as 别名]
def test_can_search_documents(self):
image = Document.objects.create(
title="OpenStax",
file=get_test_image_file(),
)
response = self.client.get('/apps/cms/api/v2/documents/?search=OpenStax')
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 1)