summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-07-05 11:40:08 +0200
committerClaude Paroz <claude@2xlibre.net>2014-07-05 13:35:53 +0200
commit83a185a3f7d07af295880ed02efba4af4c86a204 (patch)
tree02d6e5b209c3a588974ee0154ae230a45e3a9455 /tests/forms_tests
parentb68c7a5abbb737c54dff91e56e0e56e67cd3f718 (diff)
[1.7.x] Ensured bound field renders as unicode safe data
Refs #22950. Backport of 920904921 from master.
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_forms.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index a2be118e10..b79f53d6cb 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -22,7 +22,9 @@ from django.template import Template, Context
from django.test import TestCase
from django.test.utils import str_prefix
from django.utils.datastructures import MultiValueDict, MergeDict
-from django.utils.safestring import mark_safe
+from django.utils.encoding import force_text
+from django.utils.html import format_html
+from django.utils.safestring import mark_safe, SafeData
from django.utils import six
@@ -1335,6 +1337,21 @@ class FormsTestCase(TestCase):
self.assertEqual(bound['password'].value(), 'foo')
self.assertEqual(unbound['password'].value(), None)
+ def test_boundfield_rendering(self):
+ """
+ Python 2 issue: Test that rendering a BoundField with bytestring content
+ doesn't lose it's safe string status (#22950).
+ """
+ class CustomWidget(TextInput):
+ def render(self, name, value, attrs=None):
+ return format_html(str('<input{0} />'), ' id=custom')
+
+ class SampleForm(Form):
+ name = CharField(widget=CustomWidget)
+
+ f = SampleForm(data={'name': 'bar'})
+ self.assertIsInstance(force_text(f['name']), SafeData)
+
def test_initial_datetime_values(self):
now = datetime.datetime.now()
# Nix microseconds (since they should be ignored). #22502