Esempio n. 1
0
    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>')},
            ]),
        }))
Esempio n. 2
0
    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>")
                    },
                ]),
            }),
        )
Esempio n. 3
0
 def test_cannot_create_second_peoplepage(self):
     home_page = HomePage.objects.get()
     self.assertCanCreate(home_page, PeoplePage, nested_form_data({
         'title': 'People',
     }))
     try:
         self.assertCanCreate(home_page, PeoplePage, nested_form_data({
             'title': 'People 2',
         }))
         self.fail('Expected to error')
     except AssertionError as ae:
         if str(ae) == 'Creating a people.peoplepage returned a 403':
             pass
         else:
             raise ae
Esempio n. 4
0
 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_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)
Esempio n. 6
0
    def test_inline_formset(self):
        result = nested_form_data({
            "lines":
            inline_formset([
                {
                    "text": "Hello"
                },
                {
                    "text": "World"
                },
            ])
        })

        self.assertEqual(
            result,
            {
                "lines-TOTAL_FORMS": "2",
                "lines-INITIAL_FORMS": "0",
                "lines-MIN_NUM_FORMS": "0",
                "lines-MAX_NUM_FORMS": "1000",
                "lines-0-text": "Hello",
                "lines-0-ORDER": "0",
                "lines-0-DELETE": "",
                "lines-1-text": "World",
                "lines-1-ORDER": "1",
                "lines-1-DELETE": "",
            },
        )
Esempio n. 7
0
    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": "",
            },
        )
Esempio n. 8
0
 def testCanCreateCalendar(self):
     self.assertCanCreate(
         self.home, CalendarPage,
         nested_form_data({
             'title': "Calendar",
             'intro': rich_text("<h4>What's happening</h4>")
         }))
Esempio n. 9
0
 def test_can_create_general_index(self):
     self.assertCanCreate(
         self.home, GeneralIndexPage,
         nested_form_data({
             'title': 'General Index Test Page',
             'body': streamfield([])
         }))
Esempio n. 10
0
 def testCanCreateGroup(self):
     self.assertCanCreate(
         self.home, GroupPage,
         nested_form_data({
             'title': "Moreporks Club",
             'intro': rich_text("<h4>Welcome to the club</h4>")
         }))
Esempio n. 11
0
 def test_can_create_general(self):
     self.assertCanCreate(
         self.home, GeneralPage,
         nested_form_data({
             'title': 'General Test Page',
             'body': streamfield([('html', '<p>Testing!</p>')])
         }))
Esempio n. 12
0
 def test_can_create_FAQ(self):
     self.assertCanCreate(
         self.home, FAQPage,
         nested_form_data({
             'title': 'FAQ Test Page',
             'body': streamfield([('heading', 'Testing!')])
         }))
Esempio n. 13
0
    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': '',
            }
        )
Esempio n. 14
0
 def test_can_create_home(self):
     self.assertCanCreate(
         self.home, HomePage,
         nested_form_data({
             'title': 'Home Test Page',
             'event_slides': inline_formset([])
         }))
Esempio n. 15
0
 def test_can_create_two_col_general(self):
     self.assertCanCreate(
         self.home, TwoColumnGeneralPage,
         nested_form_data({
             'title': 'Two Column General Test Page',
             'body': streamfield([])
         }))
Esempio n. 16
0
 def testCanCreateCancellation(self):
     self.assertCanCreate(self.event, CancellationPage,
                          nested_form_data({'overrides':            self.event.id,
                                            'except_date':          dt.date(2009,8,14),
                                            'cancellation_title':   "Meeting Cancelled",
                                            'cancellation_details':
                                                rich_text("<p>No meeting today</p>")}))
Esempio n. 17
0
    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)
Esempio n. 18
0
 def testCanCreateMultidayRecurringEvent(self):
     self.assertCanCreate(
         self.group,
         MultidayRecurringEventPage,
         nested_form_data({
             'title':
             "Team Retreat",
             'repeat_0':
             dt.date(1987, 8, 7),
             'repeat_1':
             0,  # yearly
             'repeat_2':
             1,  # every year
             'repeat_6':
             1,  # the first
             'repeat_7':
             4,  # Friday of
             'repeat_12': {
                 8: 8
             },  # August
             'num_days':
             3,
             'time_from':
             dt.time(17),
             'tz':
             pytz.timezone("Pacific/Auckland"),
             'details':
             rich_text("<p>Three days of T-E-A-M</p>")
         }))
Esempio n. 19
0
 def testCanCreateGeneralCalendar(self):
     GeneralCalendarPage.is_creatable = True
     self.assertCanCreate(
         self.home, GeneralCalendarPage,
         nested_form_data({
             'title': "Calendar",
             'intro': rich_text("<h4>What's happening</h4>")
         }))
Esempio n. 20
0
 def test_nested_form_data(self):
     result = nested_form_data({
         "foo": "bar",
         "parent": {
             "child": "field",
         },
     })
     self.assertEqual(result, {"foo": "bar", "parent-child": "field"})
Esempio n. 21
0
    def test_can_create_answer_page(self):
        # Get the HomePage
        root_page = Page.objects.get(id=1)
    
        # Test if FAQPage can be create
        self.assertCanCreate(root_page, FAQPage, nested_form_data({
            'title': 'FAQ'
        }))

        # Get the FAQPage created previously
        root_page = FAQPage.objects.get(title='FAQ')

        # Test if AnswerPage can be create
        self.assertCanCreate(root_page, AnswerPage, nested_form_data({
            'title': 'How to Lorem ipsum',
            'body': rich_text('<p>Lorem ipsum dolor sit amet</p>')
        }))
Esempio n. 22
0
 def testCanCreateMultidayEvent(self):
     self.assertCanCreate(self.group, MultidayEventPage,
                          nested_form_data({'title':      "Camp QA",
                                            'date_from':  dt.date(1987,7,10),
                                            'date_to':    dt.date(1987,7,12),
                                            'time_from':  dt.time(17),
                                            'time_to':    dt.time(14,30),
                                            'tz':         pytz.timezone("Pacific/Auckland"),
                                            'details':    rich_text("<p>Hello World</p>")}))
Esempio n. 23
0
 def testCanCreateSpecificCalendar(self):
     SpecificCalendarPage.is_creatable = True
     self.assertCanCreate(
         self.home, SpecificCalendarPage,
         nested_form_data({
             'title': "Calendar",
             'intro': rich_text("<h4>What's happening</h4>"),
             'default_view': "M"
         }))
Esempio n. 24
0
 def test_can_create_plant_collections(self):
     self.assertCanCreate(
         self.home, PlantCollectionsPage,
         nested_form_data({
             'title': 'Plant Collections Test Page',
             'intro': rich_text('Testing!'),
             'more_info_modal': rich_text('Testing!'),
             'plant_collections': inline_formset([])
         }))
Esempio n. 25
0
 def testCanCreateSimpleEvent(self):
     self.assertCanCreate(
         self.group, SimpleEventPage,
         nested_form_data({
             'title': "Mouse Hunt",
             'date': dt.date(1987, 6, 5),
             'tz': pytz.timezone("Pacific/Auckland"),
             'details': rich_text("<p>Hello Micee</p>")
         }))
Esempio n. 26
0
 def test_block_admin(self):
     self.assertCanCreate(
         self.root_page, TestPage,
         nested_form_data({
             'title':
             'VideoPage',
             'video_streamfield':
             streamfield([('video', self.video.id)])
         }))
Esempio n. 27
0
 def test_can_create_under_homepage(self):
     """
     Test that a TopicListPage can be created as a child of a HomePage.
     """
     home_page = HomePage.objects.get()
     self.assertCanCreate(home_page, TopicListPage,
                          nested_form_data({
                              'title': 'Topics',
                          }))
 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'
         }))
Esempio n. 29
0
 def test_can_create(self):
     self.assertCanCreateAt(HomePage, CollectionPage)
     self.assertCanCreate(
         self.home, CollectionPage,
         nested_form_data({
             'title': 'About the Collections',
             'slug': 'more-collections',
             'body': rich_text('collection overview here...'),
         }))
Esempio n. 30
0
 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
         }))
Esempio n. 31
0
 def test_nested_form_data(self):
     result = nested_form_data({
         'foo': 'bar',
         'parent': {
             'child': 'field',
         },
     })
     self.assertEqual(
         result,
         {'foo': 'bar', 'parent-child': 'field'}
     )
Esempio n. 32
0
    def test_inline_formset(self):
        result = nested_form_data({'lines': inline_formset([
            {'text': 'Hello'},
            {'text': 'World'},
        ])})

        self.assertEqual(
            result,
            {
                'lines-TOTAL_FORMS': '2',
                'lines-INITIAL_FORMS': '0',
                'lines-MIN_NUM_FORMS': '0',
                'lines-MAX_NUM_FORMS': '1000',
                'lines-0-text': 'Hello',
                'lines-0-ORDER': '0',
                'lines-0-DELETE': '',
                'lines-1-text': 'World',
                'lines-1-ORDER': '1',
                'lines-1-DELETE': '',
            }
        )