Skip to content

Commit

Permalink
Fixes #168 - Use get_form_list() instead of form_list
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Schinckel <matt@schinckel.net>
  • Loading branch information
stuaxo and schinckel authored Mar 2, 2022
1 parent 954c9df commit 533a830
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion formtools/wizard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def get_form(self, step=None, data=None, files=None):
"""
if step is None:
step = self.steps.current
form_class = self.form_list[step]
form_class = self.get_form_list()[step]
# prepare the kwargs for the form instance.
kwargs = self.get_form_kwargs(step)
kwargs.update({
Expand Down
27 changes: 27 additions & 0 deletions tests/wizard/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def done(self, form_list, **kwargs):
return http.HttpResponse("All good")


class TestWizardWithCustomGetFormList(TestWizard):

form_list = [Step1]

def get_form_list(self):
return {'start': Step1, 'step2': Step2}


class FormTests(TestCase):
def test_form_init(self):
testform = TestWizard.get_initkwargs([Step1, Step2])
Expand Down Expand Up @@ -257,6 +265,25 @@ def test_form_list_type(self):
response, instance = testform(request)
self.assertEqual(response.status_code, 200)

def test_get_form_list_default(self):
request = get_request()
testform = TestWizard.as_view([('start', Step1)])
response, instance = testform(request)

form_list = instance.get_form_list()
self.assertEqual(form_list, {'start': Step1})
with self.assertRaises(KeyError):
instance.get_form('step2')

def test_get_form_list_custom(self):
request = get_request()
testform = TestWizardWithCustomGetFormList.as_view([('start', Step1)])
response, instance = testform(request)

form_list = instance.get_form_list()
self.assertEqual(form_list, {'start': Step1, 'step2': Step2})
self.assertIsInstance(instance.get_form('step2'), Step2)


class SessionFormTests(TestCase):
def test_init(self):
Expand Down

0 comments on commit 533a830

Please sign in to comment.