|
1 import re |
|
2 from django import forms |
|
3 from django.test import TestCase |
|
4 |
|
5 class FormWizardWithNullBooleanField(TestCase): |
|
6 urls = 'regressiontests.formwizard.urls' |
|
7 |
|
8 input_re = re.compile('name="([^"]+)" value="([^"]+)"') |
|
9 |
|
10 wizard_url = '/wiz/' |
|
11 wizard_step_data = ( |
|
12 { |
|
13 '0-name': 'Pony', |
|
14 '0-thirsty': '2', |
|
15 }, |
|
16 { |
|
17 '1-address1': '123 Main St', |
|
18 '1-address2': 'Djangoland', |
|
19 }, |
|
20 { |
|
21 '2-random_crap': 'blah blah', |
|
22 } |
|
23 ) |
|
24 |
|
25 def grabFieldData(self, response): |
|
26 """ |
|
27 Pull the appropriate field data from the context to pass to the next wizard step |
|
28 """ |
|
29 previous_fields = response.context['previous_fields'] |
|
30 fields = {'wizard_step': response.context['step0']} |
|
31 |
|
32 def grab(m): |
|
33 fields[m.group(1)] = m.group(2) |
|
34 return '' |
|
35 |
|
36 self.input_re.sub(grab, previous_fields) |
|
37 return fields |
|
38 |
|
39 def checkWizardStep(self, response, step_no): |
|
40 """ |
|
41 Helper function to test each step of the wizard |
|
42 - Make sure the call succeeded |
|
43 - Make sure response is the proper step number |
|
44 - return the result from the post for the next step |
|
45 """ |
|
46 step_count = len(self.wizard_step_data) |
|
47 |
|
48 self.assertEqual(response.status_code, 200) |
|
49 self.assertContains(response, 'Step %d of %d' % (step_no, step_count)) |
|
50 |
|
51 data = self.grabFieldData(response) |
|
52 data.update(self.wizard_step_data[step_no - 1]) |
|
53 |
|
54 return self.client.post(self.wizard_url, data) |
|
55 |
|
56 def testWizard(self): |
|
57 response = self.client.get(self.wizard_url) |
|
58 for step_no in range(1, len(self.wizard_step_data) + 1): |
|
59 response = self.checkWizardStep(response, step_no) |