def test_post_rerender(self): self.form.children['fields'].add_child( widgy_site, FormInput, label='foo', required=True, type='text', ) req = self.factory.post('/?from=/foo/') req.user = User(is_superuser=True) with mock.patch.object(Form, 'execute') as form_execute: with mock.patch('widgy.contrib.widgy_mezzanine.views.page_view' ) as page_view: page_view.return_value = object() resp = handle_form(req, form_node_pk=self.form.node.pk) form_execute.assert_not_called() self.assertIs(resp, page_view.return_value) args, kwargs = page_view.call_args self.assertIs(args[0], req) extra_context = kwargs['extra_context'] self.assertEqual(extra_context['root_node_override'], self.form.node) django_form = extra_context[self.form.context_var] self.assertIsInstance(django_form, forms.BaseForm) self.assertTrue(django_form.errors)
def test_post_rerender(self): self.form.children['fields'].add_child(widgy_site, FormInput, label='foo', required=True, type='text', ) req = self.factory.post('/?from=/foo/') req.user = User(is_superuser=True) with mock.patch.object(Form, 'execute') as form_execute: with mock.patch('widgy.contrib.widgy_mezzanine.views.page_view') as page_view: page_view.return_value = object() resp = handle_form(req, form_node_pk=self.form.node.pk) form_execute.assert_not_called() self.assertIs(resp, page_view.return_value) args, kwargs = page_view.call_args self.assertIs(args[0], req) extra_context = kwargs['extra_context'] self.assertEqual(extra_context['root_node_override'], self.form.node) django_form = extra_context[self.form.context_var] self.assertIsInstance(django_form, forms.BaseForm) self.assertTrue(django_form.errors)
def test_post(self): req = self.factory.post('/?from=/foo/') with mock.patch.object(Form, 'execute') as form_execute: form_execute.return_value = object() resp = handle_form(req, form_node_pk=self.form.node.pk) args, kwargs = form_execute.call_args self.assertIs(args[0], req) self.assertIsInstance(args[1], forms.BaseForm) # should use the form's response self.assertIs(resp, form_execute.return_value)
def test_post_no_404(self): """ Mezzanine==3.1.2 introduced a change that caused calls to page view (such as in the form_invalid of the handle_form view to 404. This test ensures that there is no 404. """ from widgy.contrib.widgy_mezzanine.models import WidgyPage page = WidgyPage.objects.create(title='Test') self.form.children['fields'].add_child(widgy_site, FormInput, label='foo', required=True, type='text', ) req = self.factory.post('/?from=/foo/') req.user = User(is_superuser=True) resp = handle_form(req, form_node_pk=self.form.node.pk, slug=page.slug) self.assertEqual(resp.status_code, 200)
def test_get(self): req = self.factory.get('/?from=/foo/') resp = handle_form(req, form_node_pk=self.form.node.pk) self.assertEqual(resp['Location'], '/foo/')