PageRenderTime 116ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 70ms app.codeStats 0ms

/tests/regressiontests/formwizard/tests.py

https://code.google.com/p/mango-py/
Python | 59 lines | 51 code | 5 blank | 3 comment | 0 complexity | aa7853e0931cd91b27fedd1a6b1d40dd MD5 | raw file
 1import re
 2from django import forms
 3from django.test import TestCase
 4
 5class 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)