Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@claudep claudep authored
View
12 django/contrib/formtools/tests/__init__.py
@@ -12,6 +12,7 @@
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
from django.utils import unittest
@@ -218,7 +219,6 @@ def __init__(self, POST=None):
)
class WizardTests(TestCase):
urls = 'django.contrib.formtools.tests.urls'
- input_re = re.compile('name="([^"]+)" value="([^"]+)"')
wizard_step_data = (
{
'0-name': 'Pony',
@@ -409,14 +409,13 @@ def grab_field_data(self, response):
"""
Pull the appropriate field data from the context to pass to the next wizard step
"""
- previous_fields = response.context['previous_fields']
+ previous_fields = parse_html(response.context['previous_fields'])
fields = {'wizard_step': response.context['step0']}
- def grab(m):
- fields[m.group(1)] = m.group(2)
- return ''
+ for input_field in previous_fields:
+ input_attrs = dict(input_field.attributes)
+ fields[input_attrs["name"]] = input_attrs["value"]
- self.input_re.sub(grab, previous_fields)
return fields
def check_wizard_step(self, response, step_no):
@@ -428,7 +427,6 @@ def check_wizard_step(self, response, step_no):
"""
step_count = len(self.wizard_step_data)
- self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Step %d of %d' % (step_no, step_count))
data = self.grab_field_data(response)
View
5 django/contrib/formtools/tests/wizard/cookiestorage.py
@@ -1,3 +1,5 @@
+import json
+
from django.test import TestCase
from django.core import signing
from django.core.exceptions import SuspiciousOperation
@@ -41,4 +43,5 @@ def test_reset_cookie(self):
storage.init_data()
storage.update_response(response)
unsigned_cookie_data = cookie_signer.unsign(response.cookies[storage.prefix].value)
- self.assertEqual(unsigned_cookie_data, '{"step_files":{},"step":null,"extra_data":{},"step_data":{}}')
+ self.assertEqual(json.loads(unsigned_cookie_data),
+ {"step_files": {}, "step": None, "extra_data": {}, "step_data": {}})
Please sign in to comment.
Something went wrong with that request. Please try again.