def test_image_add_to_collection(): root_collection = wagtail_factories.CollectionFactory(parent=None) image = wagtail_factories.ImageFactory( collection__parent=root_collection, collection__name='new') assert image.collection.name == 'new'
def setUp(self): super().setUp() self.image_model = get_image_model() self.assertEqual(self.image_model.objects.all().count(), 0) self.example_image = wagtail_factories.ImageFactory(title="Example Image") self.example_image.full_clean() self.example_image.save() self.assertEqual(self.image_model.objects.all().count(), 1)
def setUp(self): super().setUp() # Create Blog self.blog_page = BlogPageFactory(body=[ ("heading", "Test heading 1"), ("paragraph", RichText("This is a paragraph.")), ("heading", "Test heading 2"), ("image", wagtail_factories.ImageFactory()), ("decimal", decimal.Decimal(1.2)), ("date", datetime.date.today()), ("datetime", datetime.datetime.now()), ( "carousel", StreamValue( stream_block=CarouselBlock(), stream_data=[ ("image", wagtail_factories.ImageChooserBlockFactory()), ("image", wagtail_factories.ImageChooserBlockFactory()), ], ), ), ( "gallery", { "title": "Gallery title", "images": StreamValue( stream_block=ImageGalleryImages(), stream_data=[ ( "image", { "image": wagtail_factories.ImageChooserBlockFactory( ) }, ), ( "image", { "image": wagtail_factories.ImageChooserBlockFactory( ) }, ), ], ), }, ), ("objectives", ["Read all of article!"]), ("video", { "youtube_link": EmbedValue("https://youtube.com/") }), ])
def fake_content(): """ Fake Article Content for testing Purposes The Article content is a StreamField, therefore it can consist of any combinations of individual StreamBlocks TODO: - [ ] Devise a test which uses parametrized data to test different combinations of the Streamblocks, including repeating of some blocks """ fake_paragraph = fake_rich_text() fake_quote = { "text": fake.sentence(), "attribute_name": fake.name(), } fake_img = wagtail_factories.ImageFactory() three_random_words = fake.words(nb=3) fake_attribution = " ".join(three_random_words) data = [ {"type": "paragraph_block", "value": fake_paragraph}, {"type": "block_quote", "value": fake_quote}, {"type": "embed_block", "value": fake_embed_url()}, { "type": "heading_block", "value": { "heading_text": fake.sentence(), "size": random.choice(["h4", "h3", "h2"]), }, }, { "type": "table", "value": { "data": [ [fake.word(), fake.word(), fake.word()], ["1", " ".join(fake.words(nb=3)), fake.word()], ["2", " ".join(fake.words(nb=4)), fake.word()], ["3", " ".join(fake.words(nb=3)), fake.word()], ], "cell": [], "first_row_is_table_header": True, "first_col_is_header": False, "table_caption": fake.sentence(), }, }, { "type": "image_block", "value": { "image": fake_img.id, "caption": random.choice(["", fake.sentence()]), "attribution": random.choice(["", titlecase(fake_attribution)]), }, }, ] content_block = BaseStreamBlock() content_block_value = content_block.to_python(data) return content_block_value
def setUp(self): super().setUp() # Create Blog self.blog_page = BlogPageFactory(body=[ ("heading", "Test heading 1"), ("paragraph", RichText("This is a paragraph.")), ("heading", "Test heading 2"), ("image", wagtail_factories.ImageFactory()), ("decimal", decimal.Decimal(1.2)), ("date", datetime.date.today()), ("datetime", datetime.datetime.now()), ( "gallery", { "title": "Gallery title", "images": StreamValue( stream_block=ImageGalleryImages(), stream_data=[ ( "image", { "image": wagtail_factories.ImageChooserBlockFactory( ) }, ), ( "image", { "image": wagtail_factories.ImageChooserBlockFactory( ) }, ), ], ), }, ), ])
def test_factories(self): SchoolPageFactory(introduction_image=wagtail_factories.ImageFactory())
def setUp(self): self.home_page = HomePage.objects.first() self.school_page = SchoolPageFactory( introduction_image=wagtail_factories.ImageFactory(), parent=self.home_page)
def setUp(self): super().setUp() # Create Blog self.blog_page = BlogPageFactory( body=[ ("heading", "Test heading 1"), ("paragraph", RichText("This is a paragraph.")), ("heading", "Test heading 2"), ("image", wagtail_factories.ImageFactory()), ("decimal", decimal.Decimal(1.2)), ("date", datetime.date.today()), ("datetime", datetime.datetime.now()), ( "carousel", StreamValue( stream_block=CarouselBlock(), stream_data=[ ("image", wagtail_factories.ImageChooserBlockFactory()), ("image", wagtail_factories.ImageChooserBlockFactory()), ], ), ), ( "gallery", { "title": "Gallery title", "images": StreamValue( stream_block=ImageGalleryImages(), stream_data=[ ( "image", { "image": wagtail_factories. ImageChooserBlockFactory() }, ), ( "image", { "image": wagtail_factories. ImageChooserBlockFactory() }, ), ], ), }, ), ("callout", { "text": RichText("<p>Hello, World</p>") }), ("objectives", ["Read all of article!"]), ( "video", { "youtube_link": EmbedValue( "https://www.youtube.com/watch?v=_U79Wc965vw") }, ), ( "text_and_buttons", { "text": "Button text", "buttons": [{ "button_text": "btn", "button_link": "https://www.graphql.com/", }], "mainbutton": { "button_text": "Take me to the source", "button_link": "https://wagtail.io/", }, }, ), ("text_with_callable", TextWithCallableBlockFactory()), ], parent=self.home, )
def test_image_no_args_or_kwargs(): image = wagtail_factories.ImageFactory() assert image.collection.name == "Test collection"
def django_db_setup(django_db_setup, django_db_blocker, tmpdir_factory): """ Configure the DB for Testing. We also configure a MEDIA_ROOT temporary directory """ media_dir = "_media_store" media_storage = tmpdir_factory.mktemp(media_dir) tmpdir_factory.mktemp(media_dir).join("images") tmpdir_factory.mktemp(media_dir).join("original_images") settings.MEDIA_ROOT = str(media_storage) with django_db_blocker.unblock(): # create superuser UserFactory( is_staff=True, is_superuser=True, ) root_page = wagtail_factories.PageFactory(parent=None) home_page = HomePageFactory(parent=root_page, title="Home", slug="home") # Create a Site with the new homepage set as the root Site.objects.all().delete() Site.objects.create( hostname="www.example.com", root_page=home_page, site_name="Test Site", is_default_site=True, ) # create AboutPage # AboutPageFactory(parent=home_page, title="About", url_path="/about", slug="about") AboutPageFactory(parent=home_page, title="About", slug="about") # create BlogPage article_index_page = ArticleIndexPageFactory( parent=home_page, title="Blog", slug="blog", introduction=fake.text(max_nb_chars=254), ) # create some Articles ArticleFactory( parent=article_index_page, live=True, article_type="Post", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), author=fake.name(), content=fake_content(), ) ArticleFactory( parent=article_index_page, live=False, article_type="Post", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), author=fake.name(), content=fake_content(), ) ArticleFactory( parent=article_index_page, live=True, article_type="Shout", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), content=fake_content(), ) ArticleFactory( parent=article_index_page, live=True, article_type="Info", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), author=fake.name(), content=fake_content(), ) ArticleFactory( parent=article_index_page, live=False, article_type="Info", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), content=fake_content(), ) ArticleFactory( parent=article_index_page, live=True, article_type="Misc", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), content=fake_content(), ) ArticleFactory( parent=article_index_page, live=True, article_type="URL", cover_picture=wagtail_factories.ImageFactory(), summary=fake.text(max_nb_chars=254), author=fake.name(), external_url=fake.uri(), ) ArticleFactory( parent=article_index_page, live=False, article_type="URL", cover_picture=wagtail_factories.ImageFactory(), author="Foo Bar", summary=fake.text(max_nb_chars=254), external_url="https://www.freecodecamp.org/news/mechanical-engineering-to-software-developer/", ) # Create People fake_phone_num = fake.e164(region_code="US", valid=True, possible=True) PeopleFactory.create_batch( size=4, image=wagtail_factories.ImageFactory(), phone_number=fake_phone_num, status="published", ) PeopleFactory.create_batch( size=3, image=wagtail_factories.ImageFactory(), phone_number=fake_phone_num, status="draft", ) PeopleFactory( # no image for this one phone_number=fake_phone_num, first_name="Jane", last_name="Doe", status="draft", ) # create ContactPage contact_page = ContactPageFactory( parent=home_page, title="Contact", slug="contact", # address=fake.address() ) # create contact details for ContactPage phone_01 = ContactPagePhoneNumber( phone_number=fake.e164(region_code="CA", valid=True, possible=True), ) phone_02 = ContactPagePhoneNumber( phone_number=fake.e164(region_code="CA", valid=True, possible=True), ) email_01 = ContactPageEmailAddress(email_address=fake.company_email,) email_02 = ContactPageEmailAddress(email_address=fake.company_email,) contact_page.phone_numbers = [phone_01, phone_02] contact_page.email_addresses = [email_01, email_02] contact_page.save() # add some documents doc1 = factory.django.FileField(filename="document_01.pdf") doc2 = factory.django.FileField(filename="document_02.pdf") SimpleDocFactory(title="Document 1", file=doc1) SimpleDocFactory(title="Document 2", file=doc2)