Exemple #1
0
    def test_check_invalid_base_form_class(self):
        class BadFormClass(object):
            pass

        # Clear any old EditHandlers generated
        ValidatedPage.get_edit_handler.cache_clear()

        with mock.patch.object(ValidatedPage,
                               'base_form_class',
                               new=BadFormClass):
            errors = ValidatedPage.check()
            self.assertEqual(len(errors), 1)

            error = errors[0]
            self.assertEqual(
                error,
                checks.Error(
                    "base_form_class does not extend WagtailAdminPageForm",
                    hint=
                    "Ensure that wagtail.wagtailadmin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageForm",
                    obj=ValidatedPage,
                    id='wagtailcore.E002'))

        # Clear the bad EditHandler generated just now
        ValidatedPage.get_edit_handler.cache_clear()
Exemple #2
0
 def test_custom_edit_handler_form_class(self):
     """
     Set a custom edit handler on a Page class, but dont customise
     ValidatedPage.base_form_class, or provide a custom form class for the
     edit handler. Check the generated form class is of the correct type.
     """
     ValidatedPage.edit_handler = TabbedInterface()
     with mock.patch.object(ValidatedPage, 'edit_handler', new=TabbedInterface(), create=True):
         form_class = ValidatedPage.get_edit_handler().get_form_class()
         self.assertTrue(issubclass(form_class, WagtailAdminPageForm))
         errors = ValidatedPage.check()
         self.assertEqual(errors, [])
 def test_custom_edit_handler_form_class(self):
     """
     Set a custom edit handler on a Page class, but dont customise
     ValidatedPage.base_form_class, or provide a custom form class for the
     edit handler. Check the generated form class is of the correct type.
     """
     ValidatedPage.edit_handler = TabbedInterface([])
     with mock.patch.object(ValidatedPage, 'edit_handler', new=TabbedInterface([]), create=True):
         form_class = ValidatedPage.get_edit_handler().get_form_class(ValidatedPage)
         self.assertTrue(issubclass(form_class, WagtailAdminPageForm))
         errors = ValidatedPage.check()
         self.assertEqual(errors, [])
    def test_check_invalid_base_form_class(self):
        class BadFormClass(object):
            pass

        invalid_base_form = checks.Error(
            "ValidatedPage.base_form_class does not extend WagtailAdminPageForm",
            hint="Ensure that wagtail.wagtailadmin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageForm",
            obj=ValidatedPage,
            id='wagtailcore.E002')

        invalid_edit_handler = checks.Error(
            "ValidatedPage.get_edit_handler().get_form_class(ValidatedPage) does not extend WagtailAdminPageForm",
            hint="Ensure that the EditHandler for ValidatedPage creates a subclass of WagtailAdminPageForm",
            obj=ValidatedPage,
            id='wagtailcore.E003')

        with mock.patch.object(ValidatedPage, 'base_form_class', new=BadFormClass):
            errors = ValidatedPage.check()
            self.assertEqual(errors, [invalid_base_form, invalid_edit_handler])
Exemple #5
0
    def test_check_invalid_base_form_class(self):
        class BadFormClass(object):
            pass

        # Clear any old EditHandlers generated
        ValidatedPage.get_edit_handler.cache_clear()

        with mock.patch.object(ValidatedPage, 'base_form_class', new=BadFormClass):
            errors = ValidatedPage.check()
            self.assertEqual(len(errors), 1)

            error = errors[0]
            self.assertEqual(error, checks.Error(
                "base_form_class does not extend WagtailAdminPageForm",
                hint="Ensure that wagtail.wagtailadmin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageForm",
                obj=ValidatedPage,
                id='wagtailcore.E002'))

        # Clear the bad EditHandler generated just now
        ValidatedPage.get_edit_handler.cache_clear()
Exemple #6
0
    def test_check_invalid_base_form_class(self):
        class BadFormClass(object):
            pass

        invalid_base_form = checks.Error(
            "ValidatedPage.base_form_class does not extend WagtailAdminPageForm",
            hint=
            "Ensure that wagtail.wagtailadmin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageForm",
            obj=ValidatedPage,
            id='wagtailcore.E002')

        invalid_edit_handler = checks.Error(
            "ValidatedPage.get_edit_handler().get_form_class(ValidatedPage) does not extend WagtailAdminPageForm",
            hint=
            "Ensure that the EditHandler for ValidatedPage creates a subclass of WagtailAdminPageForm",
            obj=ValidatedPage,
            id='wagtailcore.E003')

        with mock.patch.object(ValidatedPage,
                               'base_form_class',
                               new=BadFormClass):
            errors = ValidatedPage.check()
            self.assertEqual(errors, [invalid_base_form, invalid_edit_handler])