Exemple #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>')},
            ]),
        }))
Exemple #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>")
                    },
                ]),
            }),
        )
Exemple #3
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([])
         }))
    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)
Exemple #5
0
 def test_rich_text_with_custom_features(self):
     # feature list doesn't allow <h2>, so it should become an unstyled paragraph block
     result = rich_text("<h2>title</h2><p>para</p>", features=["p"])
     self.assertTrue(
         content_state_equal(
             json.loads(result),
             {
                 "entityMap": {},
                 "blocks": [
                     {
                         "inlineStyleRanges": [],
                         "text": "title",
                         "depth": 0,
                         "type": "unstyled",
                         "key": "00000",
                         "entityRanges": [],
                     },
                     {
                         "inlineStyleRanges": [],
                         "text": "para",
                         "depth": 0,
                         "type": "unstyled",
                         "key": "00000",
                         "entityRanges": [],
                     },
                 ],
             },
         ))
Exemple #6
0
 def test_default_rich_text(self):
     result = rich_text("<h2>title</h2><p>para</p>")
     self.assertTrue(
         content_state_equal(
             json.loads(result),
             {
                 "entityMap": {},
                 "blocks": [
                     {
                         "inlineStyleRanges": [],
                         "text": "title",
                         "depth": 0,
                         "type": "header-two",
                         "key": "00000",
                         "entityRanges": [],
                     },
                     {
                         "inlineStyleRanges": [],
                         "text": "para",
                         "depth": 0,
                         "type": "unstyled",
                         "key": "00000",
                         "entityRanges": [],
                     },
                 ],
             },
         ))
Exemple #7
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>")}))
 def testEndTimeBeforeStartTime(self):
     page = PostponementPage(owner=self.user)
     form = self.Form(
         {
             'overrides':
             self.event,
             'except_date':
             "2017-02-06",
             'date':
             "2017-02-07",
             'time_from':
             "13:00:00",
             'time_to':
             "04:00:00",
             'cancellation_title':
             "Meeting postponed",
             'cancellation_details':
             rich_text("The meeting has been postponed until tomorrow"),
             'postponement_title':
             "Committee Meeting"
         },
         instance=page,
         parent_page=self.event)
     self.assertFalse(form.is_valid())
     self.assertDictEqual(
         form.errors, {'time_to': ['Event cannot end before it starts']})
 def testCanCreateGroup(self):
     self.assertCanCreate(
         self.home, GroupPage,
         nested_form_data({
             'title': "Moreporks Club",
             'intro': rich_text("<h4>Welcome to the club</h4>")
         }))
Exemple #10
0
 def testCanCreateCalendar(self):
     self.assertCanCreate(
         self.home, CalendarPage,
         nested_form_data({
             'title': "Calendar",
             'intro': rich_text("<h4>What's happening</h4>")
         }))
Exemple #11
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>")
         }))
Exemple #12
0
    def setUp(self) -> None:
        self.image = Image.objects.create(title='Sony test',
                                          file=get_test_image_file())

        with transaction.atomic():
            Iem.objects.all().delete()
            Brand.objects.all().delete()
            Brand.objects.create(
                name='Shozy',
                image=self.image,
                description=rich_text('<h1>Hello world Shozy way!!!!</h1>'))

            Brand.objects.create(
                name='Moondrop',
                image=self.image,
                description=rich_text(
                    '<h1>Hello world Moondrop Chinnese way!!!!</h1>'))
Exemple #13
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>")
         }))
Exemple #14
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...'),
         }))
Exemple #15
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>")}))
Exemple #16
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>")
         }))
Exemple #17
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"
         }))
Exemple #18
0
 def test_can_create(self):
     self.assertCanCreateAt(HomePage, EditorialIndexPage)
     root = HomePage.objects.first()
     self.assertCanCreate(
         root, EditorialIndexPage,
         nested_form_data({
             'title': 'Editorialization',
             'slug': 'ed',
             'intro': rich_text('about these essays'),
         }))
Exemple #19
0
 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)
Exemple #20
0
 def testCanCreatePostponement(self):
     self.assertCanCreate(self.event, PostponementPage,
                          nested_form_data({'overrides':            self.event.id,
                                            'except_date':          dt.date(2009,8,16),
                                            'cancellation_title':   "Meeting Postponed",
                                            'cancellation_details':
                                                rich_text("<p>Meeting will be held tommorrow</p>"),
                                            'postponement_title':   "Test Meeting",
                                            'date':                 dt.date(2009,8,15),
                                            'time_from':            dt.time(13)}))
Exemple #21
0
 def testCanCreateExtraInfo(self):
     self.assertCanCreate(
         self.event, ExtraInfoPage,
         nested_form_data({
             'overrides':
             self.event.id,
             'except_date':
             dt.date(2009, 8, 14),
             'extra_information':
             rich_text("<h3>A special announcement</h3>")
         }))
Exemple #22
0
 def test_extended_link_hook_registration(self):
     self.assertCanCreate(
         self.parent,
         SimplePage,
         nested_form_data({
             "title":
             "Some new title",
             "body":
             rich_text("<a href='http://google.com'>Some Link</a>"),
         }),
     )
Exemple #23
0
 def testExceptionAlreadyExists(self):
     page = ExtraInfoPage(owner=self.user)
     form = self.Form({'overrides':         self.event,
                       'except_date':       "1999-01-05",
                       'extra_title':       "Es ist Freitag",
                       'extra_information': rich_text("Besonderer spezieller Freitag")},
                       instance=page,
                       parent_page=self.event)
     self.assertFalse(form.is_valid())
     self.assertDictEqual(form.errors,
                          {'except_date': ['Dieses Datum enthält bereits zusätzliche information']})
Exemple #24
0
 def test_person_required(self, people_landing_page):
     """profile page must be for an existing person"""
     with pytest.raises(ValidationError):
         people_landing_page.add_child(instance=Profile(
             title="tom r. jones",
             education=rich_text("school"),
             body=json.dumps([{
                 "type": "paragraph",
                 "value": "about me"
             }]),
         ))
Exemple #25
0
 def testExceptionAlreadyExists(self):
     page = ExtraInfoPage(owner=self.user)
     form = self.Form({'overrides':         self.event,
                       'except_date':       "1999-01-05",
                       'extra_title':       "It's Friday",
                       'extra_information': rich_text("Special Special Friday")},
                       instance=page,
                       parent_page=self.event)
     self.assertFalse(form.is_valid())
     self.assertDictEqual(form.errors,
                          {'except_date': ['That date already has extra information']})
Exemple #26
0
 def testCanCreateRecurringEvent(self):
     self.assertCanCreate(self.group, RecurringEventPage,
                          nested_form_data({'title':      "Stand up",
                                            'repeat_0':   dt.date(1987,6,7),
                                            'repeat_1':   2,                    # weekly
                                            'repeat_2':   1,                    # every week
                                            'repeat_3':   {0:0, 1:1, 2:2, 4:4}, # Mon,Tue,Wed,Fri
                                            'time_from':  dt.time(9),
                                            'time_to':    dt.time(10),
                                            'tz':         pytz.timezone("Pacific/Auckland"),
                                            'details':
                                                rich_text("<p>Stand up straight!</p>")}))
Exemple #27
0
 def test_default_rich_text(self):
     result = rich_text('<h2>title</h2><p>para</p>')
     self.assertTrue(content_state_equal(
         json.loads(result),
         {
             'entityMap': {},
             'blocks': [
                 {'inlineStyleRanges': [], 'text': 'title', 'depth': 0, 'type': 'header-two', 'key': '00000', 'entityRanges': []},
                 {'inlineStyleRanges': [], 'text': 'para', 'depth': 0, 'type': 'unstyled', 'key': '00000', 'entityRanges': []},
             ]
         }
     ))
Exemple #28
0
 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'))])
         }))
Exemple #29
0
 def test_rich_text_with_custom_features(self):
     # feature list doesn't allow <h2>, so it should become an unstyled paragraph block
     result = rich_text('<h2>title</h2><p>para</p>', features=['p'])
     self.assertTrue(content_state_equal(
         json.loads(result),
         {
             'entityMap': {},
             'blocks': [
                 {'inlineStyleRanges': [], 'text': 'title', 'depth': 0, 'type': 'unstyled', 'key': '00000', 'entityRanges': []},
                 {'inlineStyleRanges': [], 'text': 'para', 'depth': 0, 'type': 'unstyled', 'key': '00000', 'entityRanges': []},
             ]
         }
     ))
Exemple #30
0
    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>')),
            ])
        }))
Exemple #31
0
 def test_rich_text_with_alternative_editor(self):
     result = rich_text('<h2>title</h2><p>para</p>', editor='hallo')
     self.assertEqual(result, '<h2>title</h2><p>para</p>')