On Tuesday, 7 August 2012 10:30:22 UTC+8, jscn wrote:
> I've been having the exact same problem. After looking at the unit tests for the form wizard and much messing around, I eventually figured it out. You're right about needing to pass in some extra data in.
>
>
>
> Specifically, you need to add a field to the POST data called 'your_views_name-current_step' with the zero-based value of the step to which you're POSTing. Additionally, you need to prepend the zero-based step number to the names of the other fields you're POSTing.
>
>
>
> Assuming you have some classes like:
>
>
>
> class MyForm(forms.Form):
>
> some_field = forms.CharField()
>
>
>
> class MyWizard(SessionWizardView):
>
> # ...do some stuff...
>
>
>
> And a url like:
>
>
>
> url(r'^wizard/$', views.MyWizard.as_view([MyForm, MyOtherForm]))
>
>
>
>
>
> Then your test needs to look like:
>
> class TestWizardView(TestCase):
>
> def test_form(self):
>
> data = {'my_wizard_view-current_step': '0', '0-some_field': 'whatever'}
>
> response =
self.client.post('/wizard/', data=data)
>
> # your assertions here
>
>
>
> Josh
Oops, that should be: data = {'my_wizard-current_step': '0', '0-some_field': 'whatever'}