Ticket #19189: ticket_19189.diff

File ticket_19189.diff, 5.7 KB (added by kenth, 3 years ago)

Patch with tests

  • django/contrib/formtools/tests/wizard/__init__.py

    diff --git a/django/contrib/formtools/tests/wizard/__init__.py b/django/contrib/formtools/tests/wizard/__init__.py
    index a2a9692..c025a08 100644
    a b from django.contrib.formtools.tests.wizard.wizardtests.tests import ( 
    1616    WizardTestKwargs,
    1717    WizardTestGenericViewInterface,
    1818    WizardFormKwargsOverrideTests,
     19    WizardRevalidationTests,
    1920)
  • django/contrib/formtools/tests/wizard/wizardtests/forms.py

    diff --git a/django/contrib/formtools/tests/wizard/wizardtests/forms.py b/django/contrib/formtools/tests/wizard/wizardtests/forms.py
    index 6a81329..1127b29 100644
    a b class SessionContactWizard(ContactWizard): 
    6565class CookieContactWizard(ContactWizard):
    6666    storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'
    6767
     68class EmptyPage1(forms.Form):
     69    on_page1 = forms.NullBooleanField()
     70
     71class EmptyPage2(forms.Form):
     72    on_page2 = forms.NullBooleanField()
     73
     74class EmptyPage3(forms.Form):
     75    on_page3 = forms.NullBooleanField()
     76
     77class RevalidationWizard(SessionContactWizard):
     78    def done(self, form_list, **kwargs):
     79        step = self.form_list.keys()[1]
     80        form = form_list[1]
     81        raise self.RevalidationError(step, form, **kwargs)
     82
  • django/contrib/formtools/tests/wizard/wizardtests/tests.py

    diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py
    index 586bd59..761d1fd 100644
    a b class WizardFormKwargsOverrideTests(TestCase): 
    385385        self.assertEqual(formset.initial_form_count(), 1)
    386386        self.assertEqual(['staff@example.com'],
    387387            list(formset.queryset.values_list('email', flat=True)))
     388
     389class WizardRevalidationTests(TestCase):
     390    urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls'
     391
     392    wizard_url = '/wiz_revalidation/'
     393    wizard_step_1_data = {
     394        'revalidation_wizard-current_step': 'form1',
     395    }
     396    wizard_step_data = (
     397        {
     398            'revalidation_wizard-current_step': 'form1',
     399        },
     400        {
     401            'revalidation_wizard-current_step': 'form2',
     402        },
     403        {
     404            'revalidation_wizard-current_step': 'form3',
     405        },
     406    )
     407
     408    def test_form_revalidate(self):
     409        response = self.client.get(self.wizard_url)
     410        self.assertEqual(response.status_code, 200)
     411        self.assertEqual(response.context['wizard']['steps'].current, 'form1')
     412
     413        response = self.client.post(self.wizard_url, self.wizard_step_data[0])
     414        self.assertEqual(response.status_code, 200)
     415        self.assertEqual(response.context['wizard']['steps'].current, 'form2')
     416
     417        post_data = self.wizard_step_data[1]
     418        response = self.client.post(self.wizard_url, post_data)
     419        self.assertEqual(response.status_code, 200)
     420        self.assertEqual(response.context['wizard']['steps'].current, 'form3')
     421
     422        response = self.client.post(self.wizard_url, self.wizard_step_data[2])
     423        self.assertEqual(response.status_code, 200)
     424        self.assertEqual(response.context['wizard']['steps'].current, 'form2')
     425
  • django/contrib/formtools/tests/wizard/wizardtests/urls.py

    diff --git a/django/contrib/formtools/tests/wizard/wizardtests/urls.py b/django/contrib/formtools/tests/wizard/wizardtests/urls.py
    index dabce53..f15e2dd 100644
    a b from django.conf.urls import patterns, url 
    22from django.contrib.formtools.tests.wizard.wizardtests.forms import (
    33    SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
    44
     5from django.contrib.formtools.tests.wizard.wizardtests.forms import (
     6    RevalidationWizard, EmptyPage1, EmptyPage2, EmptyPage3)
     7
    58urlpatterns = patterns('',
    69    url(r'^wiz_session/$', SessionContactWizard.as_view(
    710        [('form1', Page1),
    urlpatterns = patterns('', 
    1922          ('form3', Page3),
    2023          ('form4', Page4)],
    2124          template_name='other_wizard_form.html')),
     25    url(r'^wiz_revalidation/$', RevalidationWizard.as_view(
     26        [('form1', EmptyPage1),
     27         ('form2', EmptyPage2),
     28         ('form3', EmptyPage3)])),
    2229)
  • django/contrib/formtools/wizard/views.py

    diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py
    index ea41e86..2119301 100644
    a b class WizardView(TemplateView): 
    307307        self.storage.current_step = next_step
    308308        return self.render(new_form, **kwargs)
    309309
     310    class RevalidationError(Exception):
     311        def __init__(self, step, form, **kwargs):
     312            self.step = step
     313            self.form = form
     314            self.kwargs = kwargs
     315
     316        def __repr__(self):
     317            return '%s(%s)' % (self.__class__, self.step)
     318        __str__ = __repr__
     319
    310320    def render_done(self, form, **kwargs):
    311321        """
    312322        This method gets called when all forms passed. The method should also
    class WizardView(TemplateView): 
    327337        # render the done view and reset the wizard before returning the
    328338        # response. This is needed to prevent from rendering done with the
    329339        # same data twice.
    330         done_response = self.done(final_form_list, **kwargs)
     340        try:
     341            done_response = self.done(final_form_list, **kwargs)
     342        except self.RevalidationError as e:
     343            return self.render_revalidation_failure(e.step, e.form, **e.kwargs)
     344
    331345        self.storage.reset()
    332346        return done_response
    333347
Back to Top