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)
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())
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')
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(), )
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())
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))
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'
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())
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"])
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)
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))
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())
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)
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')
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()
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'}])) self.nonjson_body = StreamModel.objects.create(body="<h1>hello world</h1>")
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())
def mocked_fetch_and_create_image(url, image_title): image = Image.objects.create( title=image_title, file=get_test_image_file(), ) context = { "file_url": url, "foreign_title": image_title, } return (image, context)
def test_get_replica_image_returns_match(self): local_image = Image.objects.create( title='local image', file=get_test_image_file(), ) local_image_hash = get_image_hash(local_image) self.assertEqual(Image.objects.count(), 1) self.importer.get_image_details() replica_image = self.importer.get_replica_image(local_image_hash) self.assertEqual(replica_image, local_image)
def test_get_image_details(self): local_image = Image.objects.create( title='local image', file=get_test_image_file(), ) local_image_hash = get_image_hash(local_image) importer = importers.ImageImporter(self.site.pk, self.fake_base_url) self.assertEqual(importer.image_hashes[local_image_hash], local_image)
def test_attaching_image_info_save_image_twice(self): # creates the image which includes saving the image image = Image.objects.create( title="Test image", file=get_test_image_file(), ) self.assertEqual(ImageInfo.objects.count(), 1) image.save() # confirm that we're not creating an ImageInfo # object each time self.assertEqual(ImageInfo.objects.count(), 1)
def test_image_info_deleted_with_image(self): image = Image.objects.create( title="Test image", file=get_test_image_file(), ) self.assertEqual(Image.objects.count(), 1) self.assertEqual(ImageInfo.objects.count(), 1) image.delete() self.assertEqual(Image.objects.count(), 0) self.assertEqual(ImageInfo.objects.count(), 0)
def test_program_thumbnail(self): """Verify that a thumbnail shows up if specified for a ProgramPage""" self.create_and_login_user() image = Image.objects.create(title='Test image', file=get_test_image_file()) self.program_page.thumbnail_image = image self.program_page.save() resp = self.client.get('/') self.assertContains(resp, image.get_rendition('fill-690x530').url)
def test_article_image_in_admin_view(self): self.image = Image.objects.create( title="Test image", file=get_test_image_file(), ) article = self.mk_article(self.yourmind, title='article', image=self.image ) article.save_revision().publish() response = self.client.get( '/admin/core/articlepagelanguageproxy/' ) self.assertContains(response, '<img src="/media/images/')
def test_image_info_updated_on_file_change(self): file_1 = get_test_image_file(colour='black', size=(100, 100)) file_2 = get_test_image_file(colour='white', size=(80, 80)) image = Image.objects.create( title="Test image", file=file_1, ) id_ = image.id original_hash = image.image_info.image_hash image.file = file_2 image.save() updated_image = Image.objects.get(id=id_) new_hash = updated_image.image_info.image_hash self.assertNotEqual( original_hash, new_hash )
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)
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'])
def test_saving_image_creates_image_info(self): self.assertEqual(Image.objects.count(), 0) self.assertEqual(ImageInfo.objects.count(), 0) # creates the image which includes saving the image image = Image.objects.create( title="Test image", file=get_test_image_file(), ) # post save of image should create the image info self.assertEqual(Image.objects.count(), 1) self.assertEqual(ImageInfo.objects.count(), 1) # check image hash in image info is correct image_info = ImageInfo.objects.first() self.assertEqual(image_info.image_hash, TEST_IMAGE_HASH) self.assertEqual(image_info.image, image)
def test_articles_can_be_saved(self, mock_image): image = Image.objects.create( title="Test image", file=get_test_image_file(), ) mock_image.return_value = image # Create parent page to which articles will be saved section = self.mk_section( self.section_index, title="Parent Test Section 2", ) self.assertEqual(ArticlePage.objects.all().count(), 0) # Save the articles # Save the first available article # import pdb;pdb.set_trace() self.importer.save([0, ], section.id) self.assertEqual(ArticlePage.objects.all().count(), 1)
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"><div class="rich-text"><p>Rich text</p></div></div>', '<div class="block-rich_text"><div class="rich-text"><p>Привет, Микола</p></div></div>', '<div class="block-image">{}</div>'.format(img_tag), '<div class="block-text">Hello, World!</div>', ])
def setUp(self): # Permissions image_content_type = ContentType.objects.get_for_model(Image) add_image_permission = Permission.objects.get( content_type=image_content_type, codename='add_image') change_image_permission = Permission.objects.get( content_type=image_content_type, codename='change_image') delete_image_permission = Permission.objects.get( content_type=image_content_type, codename='delete_image') # Groups image_adders_group = Group.objects.create(name="Image adders") image_adders_group.permissions.add(add_image_permission) image_changers_group = Group.objects.create(name="Image changers") image_changers_group.permissions.add(change_image_permission) # Users User = get_user_model() self.superuser = User.objects.create_superuser( 'superuser', '*****@*****.**', 'password') self.inactive_superuser = User.objects.create_superuser( 'inactivesuperuser', '*****@*****.**', 'password', is_active=False) # a user with add_image permission through the 'Image adders' group self.image_adder = User.objects.create_user('imageadder', '*****@*****.**', 'password') self.image_adder.groups.add(image_adders_group) # a user with add_image permission through user_permissions self.oneoff_image_adder = User.objects.create_user( 'oneoffimageadder', '*****@*****.**', 'password') self.oneoff_image_adder.user_permissions.add(add_image_permission) # a user that has add_image permission, but is inactive self.inactive_image_adder = User.objects.create_user( 'inactiveimageadder', '*****@*****.**', 'password', is_active=False) self.inactive_image_adder.groups.add(image_adders_group) # a user with change_image permission through the 'Image changers' group self.image_changer = User.objects.create_user( 'imagechanger', '*****@*****.**', 'password') self.image_changer.groups.add(image_changers_group) # a user with change_image permission through user_permissions self.oneoff_image_changer = User.objects.create_user( 'oneoffimagechanger', '*****@*****.**', 'password') self.oneoff_image_changer.user_permissions.add(change_image_permission) # a user that has change_image permission, but is inactive self.inactive_image_changer = User.objects.create_user( 'inactiveimagechanger', '*****@*****.**', 'password', is_active=False) self.inactive_image_changer.groups.add(image_changers_group) # a user with delete_image permission through user_permissions self.oneoff_image_deleter = User.objects.create_user( 'oneoffimagedeleter', '*****@*****.**', 'password') self.oneoff_image_deleter.user_permissions.add(delete_image_permission) # a user with no permissions self.useless_user = User.objects.create_user( 'uselessuser', '*****@*****.**', 'password') self.anonymous_user = AnonymousUser() # Images # an image owned by 'imageadder' self.adder_image = Image.objects.create( title="imageadder's image", file=get_test_image_file(), uploaded_by_user=self.image_adder) # an image owned by 'uselessuser' self.useless_image = Image.objects.create( title="uselessuser's image", file=get_test_image_file(), uploaded_by_user=self.useless_user) # an image with no owner self.anonymous_image = Image.objects.create( title="anonymous image", file=get_test_image_file(), )
def setUp(self): ContentType = apps.get_model('contenttypes.ContentType') Site = apps.get_model('wagtailcore.Site') # Delete the default homepage Page.objects.get(id=2).delete() # Create content type for homepage model homepage_content_type, created = ContentType.objects.get_or_create( model='HomePage', app_label='tests') # Create a new homepage homepage = HomePage.objects.create( title="Homepage", slug='home', content_type=homepage_content_type, path='00010001', depth=1, url_path="/home-page", ) # Create a site with the new homepage set as the root site = Site.objects.create(hostname='localhost', root_page=homepage, is_default_site=True) RSSFeedsSettings.objects.create( site=site, feed_app_label='tests', feed_model_name='BlogStreamPage', feed_title='Test Feed', feed_link="https://example.com", feed_description="Test Description", feed_item_description_field="intro", feed_item_content_field="body", feed_image_in_content=True, feed_item_date_field='date', is_feed_item_date_field_datetime=False, ) # Create collection for image img_collection = Collection.objects.create(name="test", depth=1) # Create an image image = Image.objects.create( title="Test image", file=get_test_image_file(), collection=img_collection, ) blogpage_content_type, created = ContentType.objects.get_or_create( model='BlogPage', app_label='tests') # Create Blog Page BlogPage.objects.create( title="BlogPage", intro="Welcome to Blog", body="This is the body of blog", date="2016-06-30", slug='blog-post', url_path="/home-page/blog-post/", content_type=blogpage_content_type, feed_image=image, path='000100010002', depth=2, ) stream_blogpage_content_type, created = ContentType.objects.get_or_create( model='BlogStreamPage', app_label='tests') # Create Stream Field Blog Page stream_page = BlogStreamPage.objects.create( title="BlogStreamPage", intro="Welcome to Blog Stream Page", body= [('heading', 'foo'), ('paragraph', RichText( '<p>Rich text</p><div style="padding-bottom: 56.25%;"' + ' class="responsive-object"> <iframe width="480" height="270"' + ' src="https://www.youtube.com/embed/mSffkWuCkgQ?feature=oembed"' + ' frameborder="0" allowfullscreen=""></iframe>' + '<img alt="wagtail.jpg" height="500"' + ' src="/media/images/wagtail.original.jpg" width="1300">' + '</div>'))], date="2016-08-30", slug='blog-stream-post', url_path="/home-page/blog-stream-post/", content_type=stream_blogpage_content_type, feed_image=image, path='000100010003', depth=3, )
class ImageFactory(factory.DjangoModelFactory): title = factory.sequence(lambda x: "image-{0}".format([x])) file = factory.LazyAttribute(lambda x: get_test_image_file()) class Meta: model = Image
def setUp(self): super(TestJsonEncoding, self).setUp() self.image = Image.objects.create(title='Test image', file=get_test_image_file())
def mocked_requests_get(url, *args, **kwargs): """ This object will be used to mock requests.get() """ class MockResponse: def __init__(self, content, status_code): self.content = content self.status_code = status_code def content(self): return self.content def json(self): return self.content if url == "http://localhost:8000/api/v2/pages/": return MockResponse(AVAILABLE_ARTICLES, 200) elif url == "http://localhost:8000/api/v2/images/1/": return MockResponse(RELATED_IMAGE, 200) elif url == "http://localhost:8000/api/v2/pages/?child_of=2": return MockResponse(AVAILABLE_SECTION_CHILDREN, 200) # Responses for individual section page requests elif url == "http://localhost:8000/api/v2/pages/2/": return MockResponse(AVAILABLE_SECTIONS["items"][0], 200) elif url == "http://localhost:8000/api/v2/pages/3/": return MockResponse(AVAILABLE_SECTIONS["items"][1], 200) elif url == "http://localhost:8000/api/v2/pages/4/": return MockResponse(AVAILABLE_SECTIONS["items"][2], 200) # Responses for individual article page requests elif url == "http://localhost:8000/api/v2/pages/10/": return MockResponse(AVAILABLE_ARTICLES["items"][0], 200) elif url == "http://localhost:8000/api/v2/pages/11/": return MockResponse(AVAILABLE_ARTICLES["items"][1], 200) elif url == "http://localhost:8000/api/v2/pages/12/": return MockResponse(AVAILABLE_ARTICLES["items"][2], 200) elif url == "http://localhost:8000/api/v2/pages/?type=core.ArticlePage" \ "&fields=title,subtitle,body,tags,commenting_state," \ "commenting_open_time,commenting_close_time," \ "social_media_title,social_media_description," \ "social_media_image,related_sections," \ "featured_in_latest,featured_in_latest_start_date" \ ",featured_in_latest_end_date,featured_in_section," \ "featured_in_section_start_date," \ "featured_in_section_end_date" \ ",featured_in_homepage,featured_in_homepage_start_date" \ ",featured_in_homepage_end_date,feature_as_hero_article" \ ",promote_date,demote_date,metadata_tags," \ "latest_revision_created_at," \ "image,social_media_image,social_media_description," \ "social_media_title&order=latest_revision_created_at": return MockResponse(AVAILABLE_ARTICLES, 200) elif url == "http://localhost:8000/api/v2/images/": return MockResponse(json.dumps(WAGTAIL_API_LIST_VIEW_PAGE_1), 200) elif url == "http://localhost:8000/api/v2/images/?limit=20&offset=20": return MockResponse(json.dumps(WAGTAIL_API_LIST_VIEW_PAGE_2), 200) elif url == "http://localhost:8000/media/images/SIbomiWV1AQ.original.jpg": return MockResponse(get_test_image_file().__str__(), 200) elif url == "http://localhost:8000/api/v2/pages/?type=core.SectionIndexPage": # noqa return MockResponse( json.dumps(TYPE_SECTION_INDEX_PAGE_RESPONSE), 200) elif url == "http://localhost:8000/api/v2/pages/6/": return MockResponse(json.dumps(SECTION_INDEX_PAGE_RESPONSE), 200) elif url == "http://localhost:8000/api/v2/pages/178/": return MockResponse(json.dumps(SECTION_RESPONSE_1), 200) elif url == "http://localhost:8000/api/v2/pages/180/": return MockResponse(json.dumps(SECTION_RESPONSE_1_TRANSLATION_1), 200) elif url == "http://localhost:8000/api/v2/pages/181/": return MockResponse(json.dumps(ARTICLE_RESPONSE_1), 200) elif url == "http://localhost:8000/api/v2/pages/183/": return MockResponse(json.dumps(ARTICLE_RESPONSE_1_TRANSLATION), 200) elif url == "http://localhost:8000/api/v2/pages/182/": return MockResponse(json.dumps(ARTICLE_RESPONSE_2), 200) elif url == "http://localhost:8000/api/v2/pages/179/": return MockResponse(json.dumps(SECTION_RESPONSE_2), 200) elif url == "http://localhost:8000/api/v2/pages/184/": return MockResponse(json.dumps(SUB_SECTION_RESPONSE_1), 200) elif url == "http://localhost:8000/api/v2/pages/185/": return MockResponse(json.dumps(NESTED_ARTICLE_RESPONSE), 200) return MockResponse({}, 404)
def setUp(self): self.mk_main() self.factory = RequestFactory() self.main = Main.objects.all().first() 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=self.main, language=self.english) self.french = SiteLanguageRelation.objects.create( language_setting=self.language_setting, locale='fr', is_active=True) LanguageRelation.objects.create(page=self.main, language=self.french) LanguageRelation.objects.create(page=self.main, language=self.english) LanguageRelation.objects.create(page=self.banner_index, language=self.english) # 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) LanguageRelation.objects.create(page=self.main2, language=self.english2) LanguageRelation.objects.create(page=self.main2, language=self.spanish) # 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')
def setUp(self): self.image = Image.objects.create(title="Test image", file=get_test_image_file())
class ImageFactory(factory.DjangoModelFactory): title = factory.Faker('word') file = get_test_image_file() class Meta: model = get_image_model()
def test_section_importable(self): content = constants.SECTION_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(), ) record_keeper = importers.RecordKeeper() record_keeper.record_image_relation(foreign_image_id, image.id) class_ = SectionPage page = SectionPage.create_page( content_copy, class_, record_keeper=record_keeper) self.assertEqual(page.title, content["title"]) self.assertEqual(page.description, content["description"]) self.assertEqual(page.extra_style_hints, content["extra_style_hints"]) self.assertEqual(page.commenting_state, content["commenting_state"]) self.assertEqual(page.monday_rotation, content["monday_rotation"]) self.assertEqual(page.tuesday_rotation, content["tuesday_rotation"]) self.assertEqual(page.wednesday_rotation, content["wednesday_rotation"]) self.assertEqual(page.thursday_rotation, content["thursday_rotation"]) self.assertEqual(page.friday_rotation, content["friday_rotation"]) self.assertEqual(page.saturday_rotation, content["saturday_rotation"]) self.assertEqual(page.sunday_rotation, content["sunday_rotation"]) self.assertEqual(page.commenting_open_time, content["commenting_open_time"]) self.assertEqual(page.commenting_close_time, content["commenting_close_time"]) self.assertEqual(page.content_rotation_start_date, content["content_rotation_start_date"]) self.assertEqual(page.content_rotation_end_date, content["content_rotation_end_date"]) # NESTED FIELDS self.assertTrue(hasattr(page.time, "stream_data")) self.assertEqual(page.time.stream_data, content["time"]) # Check that image has been added self.assertTrue(page.image) self.assertEqual(page.image.title, content["image"]["title"]) # Check that foreign relationships have been created self.assertTrue( content["id"] in record_keeper.foreign_to_many_foreign_map["section_tags"]) self.assertEqual( (record_keeper.foreign_to_many_foreign_map["section_tags"] [content["id"]]), [content["section_tags"][0]["tag"]["id"], content["section_tags"][1]["tag"]["id"]])
def make_image(alt_text): return CFGOVImage.objects.create( title='test', file=get_test_image_file(), alt=alt_text )
def fill_out_page_meta_fields(self): self.page.search_description = 'Hello, world' self.page.search_image = Image.objects.create( title='Page image', file=get_test_image_file())
def run(): with transaction.atomic(): image = Image.objects.create( title = 'Test Image', file = get_test_image_file()) moondrop = Brand.objects.create( name = 'Moondrop', image = image, description = rich_text('<p>A Iems brand of china</p>')) shozy = Brand.objects.create( name = 'Shozy', image = image, description = rich_text('<h1>Another World of Sound</h1>')) Iem.objects.create( model = 'SSP', brand = moondrop, image = image, driver_unit = 'Berilium Dinamic Driver', impedance = 30, sensitivities = 105, frequency_response = '40HZ - 40,000KHZ', connection = '2 PIN', plug = '3.5 mm' ) Iem.objects.create( model = 'SSR', brand = moondrop, image = image, driver_unit = 'Berilium Dinamic Driver', impedance = 30, sensitivities = 105, frequency_response = '40HZ - 40,000KHZ', connection = '2 PIN', plug = '3.5 mm' ) Iem.objects.create( model = 'S8', brand = moondrop, image = image, ) Iem.objects.create( model = 'KXXS', brand = moondrop, ) Iem.objects.create( model = 'Rouge', brand = shozy, image = image, driver_unit = '2BA Knowles & 1 DD', impedance = 32, sensitivities = 150, frequency_response = '40HZ - 40,000KHZ', connection = '2 PIN', plug = '3.5 mm' ) Iem.objects.create( model = 'Form 1.1', brand = shozy, image = image, driver_unit = '1BA Knowles & 1 DD', impedance = 16, sensitivities = 100, frequency_response = '40HZ - 40,000KHZ', connection = '2 PIN', plug = '3.5 mm' ) Iem.objects.create( model = 'Black Hole', brand = shozy, image = image, driver_unit = '1 DD', impedance = 40, sensitivities = 90, frequency_response = '40HZ - 40,000KHZ', connection = '2 PIN', plug = '3.5 mm' )
def setUp(self): self.page = Site.objects.get(is_default_site=True).root_page self.image = CFGOVImage.objects.create(title='test', file=get_test_image_file())
def setUp(self): self.user = self.login() self.avatar = get_test_image_file() self.other_avatar = get_test_image_file()
def setUpTestData(cls): # Create an image for running tests on cls.image = Image.objects.create( title="Test image", file=get_test_image_file(), )
def test_get_path_for_image(self): image = Image.objects.create( title="Test image", file=get_test_image_file(), ) self.assertEqual(Resource.get_path(image), "images/1-test-image")
from django.contrib.auth.models import Permission from django.test import TestCase from django.urls import reverse from wagtail.core.models import Collection from wagtail.images import get_image_model from wagtail.images.tests.utils import get_test_image_file from wagtail.tests.utils import WagtailTestUtils Image = get_image_model() test_file = get_test_image_file() class TestBulkAddImagesToCollection(TestCase, WagtailTestUtils): def setUp(self): self.user = self.login() self.root_collection = Collection.get_first_root_node() self.dest_collection = self.root_collection.add_child(name="Destination") self.images = [ Image.objects.create(title=f"Test image - {i}", file=test_file) for i in range(1, 6) ] self.url = ( reverse( "wagtail_bulk_action", args=( "wagtailimages", "image", "add_to_collection", ), )
def setUp(self): self.image = CFGOVImage.objects.create(title='test', file=get_test_image_file())
def make_test_image(cls): image = get_image_model().objects.create(title='test', file=get_test_image_file()) return image, image.get_rendition('original')
def setUp(self): self.block = struct_blocks.ColumnBlock self.image = Image.objects.create(title="Test image", file=get_test_image_file())