def test_context_has_form(self):
        block = WagtailFormBlock()

        context = block.get_context(block.to_python({
            'form': self.form.pk,
            'form_action': '/foo/',
            'form_reference': 'some-ref'
        }))

        self.assertIsNotNone(context['form'])
Beispiel #2
0
    def test_context_has_form(self):
        block = WagtailFormBlock()

        context = block.get_context(
            block.to_python({
                "form": self.form.pk,
                "form_action": "/foo/",
                "form_reference": "some-ref",
            }))

        self.assertIsNotNone(context["form"])
Beispiel #3
0
    def test_context_form_is_invalid_when_parent_context_has_this_form_with_errors(
        self, ):
        invalid_form = self.form.get_form({
            "form_id": self.form.id,
            "form_reference": "some-ref"
        })
        assert not invalid_form.is_valid()

        self.assertDictEqual(
            invalid_form.errors,
            {
                "singleline": ["This field is required."],
                "multiline": ["This field is required."],
                "date": ["This field is required."],
                "datetime": ["This field is required."],
                "email": ["This field is required."],
                "url": ["This field is required."],
                "number": ["This field is required."],
                "dropdown": ["This field is required."],
                "radio": ["This field is required."],
                "checkboxes": ["This field is required."],
                "checkbox": ["This field is required."],
                "hidden": ["This field is required."],
                "singlefile": ["This field is required."],
                "multifile": ["This field is required."],
            },
        )

        # this is the context a page will set for an invalid form
        parent_context = {
            "invalid_stream_form_reference": "some-ref",
            "invalid_stream_form": invalid_form,
        }

        block = WagtailFormBlock()

        # get a new block context
        context = block.get_context(
            block.to_python({
                "form": self.form.pk,
                "form_action": "/foo/",
                "form_reference": "some-ref",
            }),
            parent_context,
        )

        # finally make sure the form in the block is the one with errors
        self.assertEqual(context["form"], invalid_form)
Beispiel #4
0
    def test_context_form_is_invalid_when_parent_context_has_this_form_with_errors(
            self):
        invalid_form = self.form.get_form({
            'form_id': self.form.id,
            'form_reference': 'some-ref'
        })
        assert not invalid_form.is_valid()

        self.assertDictEqual(
            invalid_form.errors, {
                'singleline': ['This field is required.'],
                'multiline': ['This field is required.'],
                'date': ['This field is required.'],
                'datetime': ['This field is required.'],
                'email': ['This field is required.'],
                'url': ['This field is required.'],
                'number': ['This field is required.'],
                'dropdown': ['This field is required.'],
                'multiselect': ['This field is required.'],
                'radio': ['This field is required.'],
                'checkboxes': ['This field is required.'],
                'checkbox': ['This field is required.'],
                'hidden': ['This field is required.'],
                'singlefile': ['This field is required.'],
                'multifile': ['This field is required.']
            })

        # this is the context a page will set for an invalid form
        parent_context = {
            'invalid_stream_form_reference': 'some-ref',
            'invalid_stream_form': invalid_form
        }

        block = WagtailFormBlock()

        # get a new block context
        context = block.get_context(
            block.to_python({
                'form': self.form.pk,
                'form_action': '/foo/',
                'form_reference': 'some-ref'
            }), parent_context)

        # finally make sure the form in the block is the one with errors
        self.assertEqual(context['form'], invalid_form)
    def test_context_form_is_invalid_when_parent_context_has_this_form_with_errors(self):
        invalid_form = self.form.get_form({'form_id': self.form.id, 'form_reference': 'some-ref'})
        assert not invalid_form.is_valid()

        self.assertEqual(invalid_form.errors, {'name': ['This field is required.']})

        # this is the context a page will set for an invalid form
        parent_context = {
            'invalid_stream_form_reference': 'some-ref',
            'invalid_stream_form': invalid_form
        }

        block = WagtailFormBlock()

        # get a new block context
        context = block.get_context(block.to_python({
            'form': self.form.pk,
            'form_action': '/foo/',
            'form_reference': 'some-ref'
        }), parent_context)

        # finally make sure the form in the block is the one with errors
        self.assertEqual(context['form'], invalid_form)