def test_streamfield(self): result = nested_form_data({'content': streamfield([ ('text', 'Hello, world'), ('text', 'Goodbye, world'), ('coffee', {'type': 'latte', 'milk': 'soya'}), ])}) self.assertEqual( result, { 'content-count': '3', 'content-0-type': 'text', 'content-0-value': 'Hello, world', 'content-0-order': '0', 'content-0-deleted': '', 'content-1-type': 'text', 'content-1-value': 'Goodbye, world', 'content-1-order': '1', 'content-1-deleted': '', 'content-2-type': 'coffee', 'content-2-value-type': 'latte', 'content-2-value-milk': 'soya', 'content-2-order': '2', 'content-2-deleted': '', } )
def test_can_create_general_index(self): self.assertCanCreate( self.home, GeneralIndexPage, nested_form_data({ 'title': 'General Index Test Page', 'body': streamfield([]) }))
def test_can_create_FAQ(self): self.assertCanCreate( self.home, FAQPage, nested_form_data({ 'title': 'FAQ Test Page', 'body': streamfield([('heading', 'Testing!')]) }))
def test_disable_cleaning_on_save(self): logo = Image.objects.create( title="logo", file=get_test_image_file(colour='white'), ) poster = Image.objects.create( title="poster", file=get_test_image_file(colour='white'), ) self.assertCanCreate(self.home, StoryPage, nested_form_data({ 'title': "Wagtail spotting", 'publisher': "Torchbox", 'publisher_logo': logo.id, 'poster_image': poster.id, 'pages': streamfield([ ('page', { 'id': 'cover', 'html': """ <amp-story-page id="cover"> <amp-story-grid-layer template="vertical"> <h1>Wagtail spotting</h1> <script>alert("boo!")</script> </amp-story-grid-layer> </amp-story-page> """ }), ]) })) page = StoryPage.objects.get(title="Wagtail spotting") cover_html = page.pages[0].value['html'].source self.assertIn("<h1>Wagtail spotting</h1>", cover_html) self.assertIn('<script>alert("boo!")</script>', cover_html)
def test_can_create_general(self): self.assertCanCreate( self.home, GeneralPage, nested_form_data({ 'title': 'General Test Page', 'body': streamfield([('html', '<p>Testing!</p>')]) }))
def test_assert_can_create_with_form_helpers(self): # same as test_assert_can_create, but using the helpers from wagtail.tests.utils.form_data # as an end-to-end test self.assertFalse(EventIndex.objects.exists()) self.assertCanCreate(self.root, EventIndex, nested_form_data({ 'title': 'Event Index', 'intro': rich_text('<p>Event intro</p>') })) self.assertTrue(EventIndex.objects.exists()) self.assertCanCreate(self.root, StreamPage, nested_form_data({ 'title': 'Flierp', 'body': streamfield([ ('text', 'Dit is onze mooie text'), ('rich_text', rich_text('<p>Dit is onze mooie text in een ferrari</p>')), ('product', {'name': 'pegs', 'price': 'a pound'}), ]), })) self.assertCanCreate(self.root, SectionedRichTextPage, nested_form_data({ 'title': 'Fight Club', 'sections': inline_formset([ {'body': rich_text('<p>Rule 1: You do not talk about Fight Club</p>')}, {'body': rich_text('<p>Rule 2: You DO NOT talk about Fight Club</p>')}, ]), }))
def test_can_create_two_col_general(self): self.assertCanCreate( self.home, TwoColumnGeneralPage, nested_form_data({ 'title': 'Two Column General Test Page', 'body': streamfield([]) }))
def test_too_long_hex_value(self): response = self._post_page_creation_data( self.parent, BlockPage, nested_form_data({ "title": "Some new title2", "extra_source": "<style>body {background-color: red;}</style>", "body": streamfield([( "single_element_block", { "headline": "Some headline", "text": rich_text("<p>Test</p>"), "text_alignment": "left", "advanced_options": { "background_color": "0000000" }, }, )]), }), ) form = response.context["form"] self.assertIn("body", form.errors)
def test_can_create_donor_package(self): self.assertCanCreate( self.home, DonorPackagePage, nested_form_data({ 'title': 'Donor Package Test Page', 'body': streamfield([('html', '<p>Testing!</p>')]) }))
def test_streamfield(self): result = nested_form_data({ "content": streamfield([ ("text", "Hello, world"), ("text", "Goodbye, world"), ("coffee", { "type": "latte", "milk": "soya" }), ]) }) self.assertEqual( result, { "content-count": "3", "content-0-type": "text", "content-0-value": "Hello, world", "content-0-order": "0", "content-0-deleted": "", "content-1-type": "text", "content-1-value": "Goodbye, world", "content-1-order": "1", "content-1-deleted": "", "content-2-type": "coffee", "content-2-value-type": "latte", "content-2-value-milk": "soya", "content-2-order": "2", "content-2-deleted": "", }, )
def test_can_create_concert(self): self.assertCanCreate( self.home, ConcertPage, nested_form_data({ 'title': 'Concert Test Page', 'body': streamfield( []) # Need to pass empty list to avoid ValidationError }))
def test_can_create_event_general(self): self.assertCanCreate( self.event_index, EventGeneralPage, nested_form_data({ 'title': 'Event General Test Page', 'event_dates': 'January', 'body': streamfield([('html', '<p>Testing!</p>')]), 'order_date': '2021-03-30 19:44:13.041150' }))
def test_can_create(self): self.assertCanCreateAt(HomePage, ContributorPage) root = HomePage.objects.first() self.assertCanNotCreateAt(ContentPage, ContributorPage) self.assertCanCreate( root, ContributorPage, nested_form_data({ 'title': 'Board Members and Contributors', 'slug': 'contributors', 'contributors': streamfield([]), 'board': streamfield([]), 'body': streamfield([('paragraph', rich_text('some analysis'))]) }))
def test_assert_can_create_with_form_helpers(self): # same as test_assert_can_create, but using the helpers from wagtail.tests.utils.form_data # as an end-to-end test self.assertFalse(EventIndex.objects.exists()) self.assertCanCreate( self.root, EventIndex, nested_form_data({ "title": "Event Index", "intro": rich_text("<p>Event intro</p>") }), ) self.assertTrue(EventIndex.objects.exists()) self.assertCanCreate( self.root, StreamPage, nested_form_data({ "title": "Flierp", "body": streamfield([ ("text", "Dit is onze mooie text"), ( "rich_text", rich_text( "<p>Dit is onze mooie text in een ferrari</p>"), ), ("product", { "name": "pegs", "price": "a pound" }), ]), }), ) self.assertCanCreate( self.root, SectionedRichTextPage, nested_form_data({ "title": "Fight Club", "sections": inline_formset([ { "body": rich_text( "<p>Rule 1: You do not talk about Fight Club</p>") }, { "body": rich_text( "<p>Rule 2: You DO NOT talk about Fight Club</p>") }, ]), }), )
def test_block_admin(self): self.assertCanCreate( self.root_page, TestPage, nested_form_data({ 'title': 'VideoPage', 'video_streamfield': streamfield([('video', self.video.id)]) }))
def test_link_text_without_link(self): response = self._post_page_creation_data( self.parent, BlockPage, nested_form_data({ "title": "Some new title2", "extra_source": "<style>body {background-color: red;}</style>", "body": streamfield([( "multi_element_block", { "headline": "Some headline", "text": rich_text("<p>Test</p>"), "text_alignment": "left", "alt_text": "Something", "elements": streamfield([( "two_column_block", { "content": streamfield([ ( "dll_element_block", { "link_text": "something" }, ), ("dll_element_block", {}), ]) }, )]), }, )]), }), ) self.assertIn("Link Text muss mit URL verwendet werden.", str(response.content))
def post_data(self, overrides={}): post_data = { 'name': 'Created campaign', 'subject': 'New subject', 'body': streamfield([ ('rich_text', rich_text('<p>Just some content</p>')) ]) } post_data.update(overrides) return nested_form_data(post_data)
def test_can_create_block_page(self): self.assertCanCreate( self.parent, BlockPage, nested_form_data({ "title": "Some new title", "extra_source": "<style>body {background-color: red;}</style>", "body": streamfield([]), }), )
def test_can_create_event_index(self): self.assertCanCreate( self.home, EventIndexPage, nested_form_data({ 'title': 'Another Event Index Test Page', 'body': streamfield( []), # Need to pass empty list to avoid ValidationError 'order_date': '2021-03-30 19:44:13.041150' }))
def get_form_data(self, include_cloumns, include_links): column_data = ( "column", {"heading": "Column Heading", "content": rich_text("Column Content")}, ) link_data = ("link", {"page": self.info_page.id, "title": "Link Title"}) included_column_data = [] if include_cloumns: included_column_data.append(column_data) included_link_data = [] if include_links: included_link_data.append(link_data) combined_data = { "footer_columns": streamfield(included_column_data), "footer_links": streamfield(included_link_data), } return nested_form_data(combined_data)
def test_creating_post(self): homepage = BlogListingPage.objects.get(title='خانه') self.assertCanCreate(homepage, BlogDetailPage, nested_form_data({ 'title': 'یک پست آزمایشی فوقالعاده', 'intro': 'یک پرندهی آرزو دار', 'slug': 'great-post', 'body': streamfield([ ('heading', 'تست کردن کار شایستهای است'), ('text', 'یونیتتست مینویسیم تا بدانیم وبسایتمان درست کار میکند'), ]) }))
def test_can_create_donor_schedule(self): self.assertCanCreate( self.home, DonorSchedulePage, nested_form_data({ 'title': 'Donor Schedule Test Page', 'body': streamfield([ ('table', '{\"data\": [[\"ARTIST\", \"FULL PACKAGE\", \"OPENER A\", \"OPENER B\"], [\"BELA FLECK AND THE FLECKTONES WITH BILLY STRINGS\", \"YES\", \"NO\", \"YES\"], [\"LITTLE FEAT\", \"YES\", \"YES\", \"NO\"]], \"cell\": [], \"first_row_is_table_header\": true, \"first_col_is_header\": false, \"table_caption\": \"2019 Donor Season Ticket Packages\"}' ), ]) }))
def test_can_create(self): self.assertCanCreateAt(HomePage, ContentPage) root = HomePage.objects.first() self.assertCanCreate( root, ContentPage, nested_form_data({ 'title': 'About of the PPA', 'slug': 'about', 'body': streamfield([('paragraph', rich_text('some analysis'))]) }))
def test_page_serializer(self): root_page = Page.objects.get(pk=1) data = nested_form_data({ 'title': 'All the sections on display. Like freaking peacocks.', 'body': streamfield([ ( 'hero_section', { 'title': 'Hero title', 'subtitle': 'Hero subtitle', # image = ImageChooserBlock(required=True, label='Hero image') 'content': streamfield([ ('button', { 'text': 'button text', 'url': 'https://www.testing-streamfields-sucks.com' }), ('video', 'https://www.youtube.com/watch?v=x_ZeDn-hHGE'), ('quote', { 'text': 'I am a super inspiring person', 'author': 'me' }), ]), }), # TODO Test other section types ]), }) self.assertCanCreate(root_page, SectionPage, data) page = SectionPage.objects.first() ser = SectionPageSerializer() ser.to_representation(page)
def test_can_create_a_page(self): """ Test to see if I can create a page """ root_page = HomePage.objects.first() self.assertCanCreate(root_page, SinglePage, nested_form_data({ 'title': 'About Test', 'body': streamfield([ ('title', 'About Test Page'), ('paragraph', rich_text('<p>This is my about test page.</p>')), ]) }))
def test_can_create(self): self.assertCanCreateAt(EditorialIndexPage, EditorialPage) parent = EditorialIndexPage.objects.first() # first test without authors, since they're optional self.assertCanCreate( parent, EditorialPage, nested_form_data({ 'title': 'Essay', 'slug': 'essay', 'date': date.today(), 'body': streamfield([('paragraph', rich_text('some analysis'))]), 'authors': streamfield([]) })) # now check that this can be done with the person snippet, # both with and without url foo = Person.objects.create(name='foo', url='http://bar.com/') bar = Person.objects.create(name='bar') self.assertCanCreate( parent, EditorialPage, nested_form_data({ 'title': 'Essay2', 'slug': 'essay2', 'date': date.today(), 'body': streamfield([('paragraph', rich_text('some analysis'))]), 'authors': streamfield([('author', foo.pk), ('author', bar.pk)]) }))
def test_can_create(self): """should be able to create contentpage under landingpage""" self.assertCanCreateAt( LandingPage, ContentPage, nested_form_data({ "title": "Data Curation", "slug": "data-curation", "body": streamfield([ ("paragraph", rich_text("data curation page text")), ]), }), )
def test_can_create(self): """should be able to create homepage at root""" self.assertCanCreateAt( Page, HomePage, nested_form_data({ "title": "Home 2", "slug": "home-2", "body": streamfield([ ("paragraph", rich_text("homepage body text")), ]), }), )
def test_can_create(self): """should be able to create landing page under homepage""" self.assertCanCreateAt( HomePage, LandingPage, nested_form_data({ "title": "Engage", "slug": "engage", "tagline": "Consult, collaborate, and work with us", "body": streamfield([ ("paragraph", rich_text("engage page text")), ]), }), )
def test_can_create_guide_page(self): # Get the HomePage root_page = Page.objects.get(id=1) # Test if GuidesPage can be create self.assertCanCreate(root_page, GuidesPage, nested_form_data({ 'title': 'Guides' })) # Get the GuidesPage created previously root_page = GuidesPage.objects.get(title='Guides') # Test if GuidePage can be create self.assertCanCreate(root_page, GuidePage, nested_form_data({ 'title': 'Guides', 'description': 'Lorem ipsum dolor', 'body': streamfield([ ('text', 'Lorem ipsum dolor sit amet'), ]) }))