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.
This commit is contained in:
parent
f7cffd43ec
commit
1f84b042f1
|
@ -12,6 +12,7 @@ from django.conf import settings
|
||||||
from django.contrib.formtools import preview, utils
|
from django.contrib.formtools import preview, utils
|
||||||
from django.contrib.formtools.wizard import FormWizard
|
from django.contrib.formtools.wizard import FormWizard
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.test.html import parse_html
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
|
@ -218,7 +219,6 @@ class DummyRequest(http.HttpRequest):
|
||||||
)
|
)
|
||||||
class WizardTests(TestCase):
|
class WizardTests(TestCase):
|
||||||
urls = 'django.contrib.formtools.tests.urls'
|
urls = 'django.contrib.formtools.tests.urls'
|
||||||
input_re = re.compile('name="([^"]+)" value="([^"]+)"')
|
|
||||||
wizard_step_data = (
|
wizard_step_data = (
|
||||||
{
|
{
|
||||||
'0-name': 'Pony',
|
'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
|
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']}
|
fields = {'wizard_step': response.context['step0']}
|
||||||
|
|
||||||
def grab(m):
|
for input_field in previous_fields:
|
||||||
fields[m.group(1)] = m.group(2)
|
input_attrs = dict(input_field.attributes)
|
||||||
return ''
|
fields[input_attrs["name"]] = input_attrs["value"]
|
||||||
|
|
||||||
self.input_re.sub(grab, previous_fields)
|
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
def check_wizard_step(self, response, step_no):
|
def check_wizard_step(self, response, step_no):
|
||||||
|
@ -428,7 +427,6 @@ class WizardTests(TestCase):
|
||||||
"""
|
"""
|
||||||
step_count = len(self.wizard_step_data)
|
step_count = len(self.wizard_step_data)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
self.assertContains(response, 'Step %d of %d' % (step_no, step_count))
|
self.assertContains(response, 'Step %d of %d' % (step_no, step_count))
|
||||||
|
|
||||||
data = self.grab_field_data(response)
|
data = self.grab_field_data(response)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import json
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.core import signing
|
from django.core import signing
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
|
@ -41,4 +43,5 @@ class TestCookieStorage(TestStorage, TestCase):
|
||||||
storage.init_data()
|
storage.init_data()
|
||||||
storage.update_response(response)
|
storage.update_response(response)
|
||||||
unsigned_cookie_data = cookie_signer.unsign(response.cookies[storage.prefix].value)
|
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": {}})
|
||||||
|
|
Loading…
Reference in New Issue