From 1f84b042f1c3fab0f806de814d668917dd86236a Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 25 Sep 2012 18:38:47 +0200 Subject: [PATCH] Fixed #19020 -- Do not depend on dict order in formtools tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks metzen for the report and initial patch, and Ɓukasz Rekucki for an inspirational patch on his randomhash_fixes branch. --- django/contrib/formtools/tests/__init__.py | 12 +++++------- .../contrib/formtools/tests/wizard/cookiestorage.py | 5 ++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py index 15941332ed..a21ffde533 100644 --- a/django/contrib/formtools/tests/__init__.py +++ b/django/contrib/formtools/tests/__init__.py @@ -12,6 +12,7 @@ from django.conf import settings 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 @@ class DummyRequest(http.HttpRequest): ) 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 @@ class WizardTests(TestCase): """ 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 @@ class WizardTests(TestCase): """ 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) diff --git a/django/contrib/formtools/tests/wizard/cookiestorage.py b/django/contrib/formtools/tests/wizard/cookiestorage.py index 495d3afd03..d450f47861 100644 --- a/django/contrib/formtools/tests/wizard/cookiestorage.py +++ b/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 @@ class TestCookieStorage(TestStorage, TestCase): 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": {}})