Commit 70966cb9 authored by Jacob Kaplan-Moss's avatar Jacob Kaplan-Moss
Browse files

Fixed #6893: `FormWizard` now properly updates its `step` value. Thanks, siddhi and wamberg.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 05133baa
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
from django import forms
from django.contrib.formtools import preview
from django.contrib.formtools import preview, wizard
from django import http
from django.test import TestCase

@@ -101,3 +101,44 @@ class PreviewTests(TestCase):
        response = self.client.post('/test1/', self.test_data)
        self.assertEqual(response.content, success_string)

#
# FormWizard tests
#

class WizardPageOneForm(forms.Form):
    field = forms.CharField()

class WizardPageTwoForm(forms.Form):
    field = forms.CharField()

class WizardClass(wizard.FormWizard):
    def render_template(self, *args, **kw):
        return ""

    def done(self, request, cleaned_data):
        return http.HttpResponse(success_string)

class DummyRequest(object):
    def __init__(self, POST=None):
        self.method = POST and "POST" or "GET"
        self.POST = POST

class WizardTests(TestCase):
    def test_step_starts_at_zero(self):
        """
        step should be zero for the first form
        """
        wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm])
        request = DummyRequest()
        wizard(request)
        self.assertEquals(0, wizard.step)

    def test_step_increments(self):
        """
        step should be incremented when we go to the next page
        """
        wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm])
        request = DummyRequest(POST={"0-field":"test", "wizard_step":"0"})
        response = wizard(request)
        self.assertEquals(1, wizard.step)
+2 −2
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class FormWizard(object):
            # Otherwise, move along to the next step.
            else:
                form = self.get_form(next_step)
                current_step = next_step
                self.step = current_step = next_step

        return self.render(form, request, current_step)

@@ -203,7 +203,7 @@ class FormWizard(object):
        """
        context = context or {}
        context.update(self.extra_context)
        return render_to_response(self.get_template(self.step), dict(context,
        return render_to_response(self.get_template(step), dict(context,
            step_field=self.step_field_name,
            step0=step,
            step=step + 1,