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
This commit is contained in:
Jacob Kaplan-Moss 2008-08-26 21:33:56 +00:00
parent 05133baaaa
commit 70966cb9c7
2 changed files with 44 additions and 3 deletions

View File

@ -1,5 +1,5 @@
from django import forms from django import forms
from django.contrib.formtools import preview from django.contrib.formtools import preview, wizard
from django import http from django import http
from django.test import TestCase from django.test import TestCase
@ -101,3 +101,44 @@ class PreviewTests(TestCase):
response = self.client.post('/test1/', self.test_data) response = self.client.post('/test1/', self.test_data)
self.assertEqual(response.content, success_string) 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)

View File

@ -92,7 +92,7 @@ class FormWizard(object):
# Otherwise, move along to the next step. # Otherwise, move along to the next step.
else: else:
form = self.get_form(next_step) form = self.get_form(next_step)
current_step = next_step self.step = current_step = next_step
return self.render(form, request, current_step) return self.render(form, request, current_step)
@ -203,7 +203,7 @@ class FormWizard(object):
""" """
context = context or {} context = context or {}
context.update(self.extra_context) 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, step_field=self.step_field_name,
step0=step, step0=step,
step=step + 1, step=step + 1,