Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #19020 -- Do not depend on dict order in formtools tests

Thanks metzen for the report and initial patch, and Łukasz Rekucki
for an inspirational patch on his randomhash_fixes branch.
  • Loading branch information...
commit 1f84b042f1c3fab0f806de814d668917dd86236a 1 parent f7cffd4
Claude Paroz authored September 25, 2012
12  django/contrib/formtools/tests/__init__.py
@@ -12,6 +12,7 @@
12 12
 from django.contrib.formtools import preview, utils
13 13
 from django.contrib.formtools.wizard import FormWizard
14 14
 from django.test import TestCase
  15
+from django.test.html import parse_html
15 16
 from django.test.utils import override_settings
16 17
 from django.utils import unittest
17 18
 
@@ -218,7 +219,6 @@ def __init__(self, POST=None):
218 219
 )
219 220
 class WizardTests(TestCase):
220 221
     urls = 'django.contrib.formtools.tests.urls'
221  
-    input_re = re.compile('name="([^"]+)" value="([^"]+)"')
222 222
     wizard_step_data = (
223 223
         {
224 224
             '0-name': 'Pony',
@@ -409,14 +409,13 @@ def grab_field_data(self, response):
409 409
         """
410 410
         Pull the appropriate field data from the context to pass to the next wizard step
411 411
         """
412  
-        previous_fields = response.context['previous_fields']
  412
+        previous_fields = parse_html(response.context['previous_fields'])
413 413
         fields = {'wizard_step': response.context['step0']}
414 414
 
415  
-        def grab(m):
416  
-            fields[m.group(1)] = m.group(2)
417  
-            return ''
  415
+        for input_field in previous_fields:
  416
+            input_attrs = dict(input_field.attributes)
  417
+            fields[input_attrs["name"]] = input_attrs["value"]
418 418
 
419  
-        self.input_re.sub(grab, previous_fields)
420 419
         return fields
421 420
 
422 421
     def check_wizard_step(self, response, step_no):
@@ -428,7 +427,6 @@ def check_wizard_step(self, response, step_no):
428 427
         """
429 428
         step_count = len(self.wizard_step_data)
430 429
 
431  
-        self.assertEqual(response.status_code, 200)
432 430
         self.assertContains(response, 'Step %d of %d' % (step_no, step_count))
433 431
 
434 432
         data = self.grab_field_data(response)
5  django/contrib/formtools/tests/wizard/cookiestorage.py
... ...
@@ -1,3 +1,5 @@
  1
+import json
  2
+
1 3
 from django.test import TestCase
2 4
 from django.core import signing
3 5
 from django.core.exceptions import SuspiciousOperation
@@ -41,4 +43,5 @@ def test_reset_cookie(self):
41 43
         storage.init_data()
42 44
         storage.update_response(response)
43 45
         unsigned_cookie_data = cookie_signer.unsign(response.cookies[storage.prefix].value)
44  
-        self.assertEqual(unsigned_cookie_data, '{"step_files":{},"step":null,"extra_data":{},"step_data":{}}')
  46
+        self.assertEqual(json.loads(unsigned_cookie_data),
  47
+            {"step_files": {}, "step": None, "extra_data": {}, "step_data": {}})

0 notes on commit 1f84b04

Please sign in to comment.
Something went wrong with that request. Please try again.