Permalink
Browse files

Removed the legacy form wizard.

  • Loading branch information...
1 parent 0522711 commit d4ea02b9929eca32887efe773a8e6a717590b055 @aaugustin aaugustin committed Dec 24, 2012
@@ -10,7 +10,6 @@
from django import http
from django.conf import settings
from django.contrib.formtools import preview, utils
-from django.contrib.formtools.wizard import FormWizard
from django.test import TestCase
from django.test.html import parse_html
from django.test.utils import override_settings
@@ -187,255 +186,3 @@ def test_empty_permitted(self):
hash1 = utils.form_hmac(f1)
hash2 = utils.form_hmac(f2)
self.assertEqual(hash1, hash2)
-
-
-#
-# FormWizard tests
-#
-
-class TestWizardClass(FormWizard):
-
- def get_template(self, step):
- return 'forms/wizard.html'
-
- def done(self, request, cleaned_data):
- return http.HttpResponse(success_string)
-
-
-class DummyRequest(http.HttpRequest):
-
- def __init__(self, POST=None):
- super(DummyRequest, self).__init__()
- self.method = POST and "POST" or "GET"
- if POST is not None:
- self.POST.update(POST)
- self._dont_enforce_csrf_checks = True
-
-
-@override_settings(
- SECRET_KEY="123",
- TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(upath(__file__)), 'templates'),
- ),
-)
-class WizardTests(TestCase):
- urls = 'django.contrib.formtools.tests.urls'
- wizard_step_data = (
- {
- '0-name': 'Pony',
- '0-thirsty': '2',
- },
- {
- '1-address1': '123 Main St',
- '1-address2': 'Djangoland',
- },
- {
- '2-random_crap': 'blah blah',
- }
- )
-
- def setUp(self):
- super(WizardTests, self).setUp()
- self.save_warnings_state()
- warnings.filterwarnings('ignore', category=DeprecationWarning,
- module='django.contrib.formtools.wizard')
-
- def tearDown(self):
- super(WizardTests, self).tearDown()
- self.restore_warnings_state()
-
- def test_step_starts_at_zero(self):
- """
- step should be zero for the first form
- """
- response = self.client.get('/wizard1/')
- self.assertEqual(0, response.context['step0'])
-
- def test_step_increments(self):
- """
- step should be incremented when we go to the next page
- """
- response = self.client.post('/wizard1/', {"0-field":"test", "wizard_step":"0"})
- self.assertEqual(1, response.context['step0'])
-
- def test_bad_hash(self):
- """
- Form should not advance if the hash is missing or bad
- """
- response = self.client.post('/wizard1/',
- {"0-field":"test",
- "1-field":"test2",
- "wizard_step": "1"})
- self.assertEqual(0, response.context['step0'])
-
- def test_good_hash(self):
- """
- Form should advance if the hash is present and good, as calculated using
- current method.
- """
- data = {"0-field": "test",
- "1-field": "test2",
- "hash_0": {
- 2: "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
- 3: "9355d5dff22d49dbad58e46189982cec649f9f5b",
- }[pickle.HIGHEST_PROTOCOL],
- "wizard_step": "1"}
- response = self.client.post('/wizard1/', data)
- self.assertEqual(2, response.context['step0'])
-
- def test_11726(self):
- """
- Regression test for ticket #11726.
- Wizard should not raise Http404 when steps are added dynamically.
- """
- reached = [False]
- that = self
-
- class WizardWithProcessStep(TestWizardClass):
- def process_step(self, request, form, step):
- if step == 0:
- if self.num_steps() < 2:
- self.form_list.append(WizardPageTwoForm)
- if step == 1:
- that.assertTrue(isinstance(form, WizardPageTwoForm))
- reached[0] = True
-
- wizard = WizardWithProcessStep([WizardPageOneForm])
- data = {"0-field": "test",
- "1-field": "test2",
- "hash_0": {
- 2: "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
- 3: "9355d5dff22d49dbad58e46189982cec649f9f5b",
- }[pickle.HIGHEST_PROTOCOL],
- "wizard_step": "1"}
- wizard(DummyRequest(POST=data))
- self.assertTrue(reached[0])
-
- data = {"0-field": "test",
- "1-field": "test2",
- "hash_0": {
- 2: "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
- 3: "9355d5dff22d49dbad58e46189982cec649f9f5b",
- }[pickle.HIGHEST_PROTOCOL],
- "hash_1": {
- 2: "1e6f6315da42e62f33a30640ec7e007ad3fbf1a1",
- 3: "c33142ef9d01b1beae238adf22c3c6c57328f51a",
- }[pickle.HIGHEST_PROTOCOL],
- "wizard_step": "2"}
- self.assertRaises(http.Http404, wizard, DummyRequest(POST=data))
-
- def test_14498(self):
- """
- Regression test for ticket #14498. All previous steps' forms should be
- validated.
- """
- reached = [False]
- that = self
-
- class WizardWithProcessStep(TestWizardClass):
- def process_step(self, request, form, step):
- that.assertTrue(form.is_valid())
- reached[0] = True
-
- wizard = WizardWithProcessStep([WizardPageOneForm,
- WizardPageTwoForm,
- WizardPageThreeForm])
- data = {"0-field": "test",
- "1-field": "test2",
- "hash_0": {
- 2: "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
- 3: "9355d5dff22d49dbad58e46189982cec649f9f5b",
- }[pickle.HIGHEST_PROTOCOL],
- "wizard_step": "1"}
- wizard(DummyRequest(POST=data))
- self.assertTrue(reached[0])
-
- def test_14576(self):
- """
- Regression test for ticket #14576.
-
- The form of the last step is not passed to the done method.
- """
- reached = [False]
- that = self
-
- class Wizard(TestWizardClass):
- def done(self, request, form_list):
- reached[0] = True
- that.assertTrue(len(form_list) == 2)
-
- wizard = Wizard([WizardPageOneForm,
- WizardPageTwoForm])
-
- data = {"0-field": "test",
- "1-field": "test2",
- "hash_0": {
- 2: "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
- 3: "9355d5dff22d49dbad58e46189982cec649f9f5b",
- }[pickle.HIGHEST_PROTOCOL],
- "wizard_step": "1"}
- wizard(DummyRequest(POST=data))
- self.assertTrue(reached[0])
-
- def test_15075(self):
- """
- Regression test for ticket #15075. Allow modifying wizard's form_list
- in process_step.
- """
- reached = [False]
- that = self
-
- class WizardWithProcessStep(TestWizardClass):
- def process_step(self, request, form, step):
- if step == 0:
- self.form_list[1] = WizardPageTwoAlternativeForm
- if step == 1:
- that.assertTrue(isinstance(form, WizardPageTwoAlternativeForm))
- reached[0] = True
-
- wizard = WizardWithProcessStep([WizardPageOneForm,
- WizardPageTwoForm,
- WizardPageThreeForm])
- data = {"0-field": "test",
- "1-field": "test2",
- "hash_0": {
- 2: "cd13b1db3e8f55174bc5745a1b1a53408d4fd1ca",
- 3: "9355d5dff22d49dbad58e46189982cec649f9f5b",
- }[pickle.HIGHEST_PROTOCOL],
- "wizard_step": "1"}
- wizard(DummyRequest(POST=data))
- self.assertTrue(reached[0])
-
- def grab_field_data(self, response):
- """
- Pull the appropriate field data from the context to pass to the next wizard step
- """
- previous_fields = parse_html(response.context['previous_fields'])
- fields = {'wizard_step': response.context['step0']}
-
- for input_field in previous_fields:
- input_attrs = dict(input_field.attributes)
- fields[input_attrs["name"]] = input_attrs["value"]
-
- return fields
-
- def check_wizard_step(self, response, step_no):
- """
- Helper function to test each step of the wizard
- - Make sure the call succeeded
- - Make sure response is the proper step number
- - return the result from the post for the next step
- """
- step_count = len(self.wizard_step_data)
-
- self.assertContains(response, 'Step %d of %d' % (step_no, step_count))
-
- data = self.grab_field_data(response)
- data.update(self.wizard_step_data[step_no - 1])
-
- return self.client.post('/wizard2/', data)
-
- def test_9473(self):
- response = self.client.get('/wizard2/')
- for step_no in range(1, len(self.wizard_step_data) + 1):
- response = self.check_wizard_step(response, step_no)
@@ -1,21 +1,4 @@
from django import forms
-from django.contrib.formtools.wizard import FormWizard
-from django.http import HttpResponse
-
-class Page1(forms.Form):
- name = forms.CharField(max_length=100)
- thirsty = forms.NullBooleanField()
-
-class Page2(forms.Form):
- address1 = forms.CharField(max_length=100)
- address2 = forms.CharField(max_length=100)
-
-class Page3(forms.Form):
- random_crap = forms.CharField(max_length=100)
-
-class ContactWizard(FormWizard):
- def done(self, request, form_list):
- return HttpResponse("")
class TestForm(forms.Form):
field1 = forms.CharField()
@@ -30,15 +13,3 @@ class HashTestForm(forms.Form):
class HashTestBlankForm(forms.Form):
name = forms.CharField(required=False)
bio = forms.CharField(required=False)
-
-class WizardPageOneForm(forms.Form):
- field = forms.CharField()
-
-class WizardPageTwoForm(forms.Form):
- field = forms.CharField()
-
-class WizardPageTwoAlternativeForm(forms.Form):
- field = forms.CharField()
-
-class WizardPageThreeForm(forms.Form):
- field = forms.CharField()
@@ -5,15 +5,11 @@
from __future__ import absolute_import
from django.conf.urls import patterns, url
-from django.contrib.formtools.tests import TestFormPreview, TestWizardClass
+from django.contrib.formtools.tests import TestFormPreview
-from django.contrib.formtools.tests.forms import (ContactWizard, Page1, Page2,
- Page3, TestForm, WizardPageOneForm, WizardPageTwoForm, WizardPageThreeForm)
+from django.contrib.formtools.tests.forms import TestForm
urlpatterns = patterns('',
url(r'^preview/', TestFormPreview(TestForm)),
- url(r'^wizard1/$', TestWizardClass(
- [WizardPageOneForm, WizardPageTwoForm, WizardPageThreeForm])),
- url(r'^wizard2/$', ContactWizard([Page1, Page2, Page3])),
)
@@ -1 +0,0 @@
-from django.contrib.formtools.wizard.legacy import FormWizard
Oops, something went wrong.

0 comments on commit d4ea02b

Please sign in to comment.