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