summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarcin Nowak <marcin.j.nowak@gmail.com>2016-07-18 20:04:35 +0200
committerTim Graham <timograham@gmail.com>2016-08-09 19:46:24 -0400
commit74bb013cc1edb0f2fcf24c750d4d942cae507765 (patch)
tree34191bb0886280b0192044afcc8079666acb379c /tests
parent2b759c94c562c9ee9b6ca970739be15014050fda (diff)
Fixed #26905 -- Allowed using MultiValueDict-like objects as form data.
Diffstat (limited to 'tests')
-rw-r--r--tests/forms_tests/tests/test_forms.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 2da04a4ef4..773b89a7bc 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -41,6 +41,11 @@ class PersonNew(Form):
birthday = DateField()
+class MultiValueDictLike(dict):
+ def getlist(self, key):
+ return [self[key]]
+
+
class FormsTestCase(SimpleTestCase):
# A Form is a collection of Fields. It knows how to validate a set of data and it
# knows how to render itself in a couple of default ways (e.g., an HTML table).
@@ -867,6 +872,12 @@ Java</label></li>
f = SongForm(data)
self.assertEqual(f.errors, {})
+ # SelectMultiple uses ducktyping so that MultiValueDictLike.getlist()
+ # is called.
+ f = SongForm(MultiValueDictLike({'name': 'Yesterday', 'composers': 'J'}))
+ self.assertEqual(f.errors, {})
+ self.assertEqual(f.cleaned_data['composers'], ['J'])
+
def test_multiple_hidden(self):
class SongForm(Form):
name = CharField()
@@ -904,6 +915,12 @@ Java</label></li>
self.assertEqual(f.cleaned_data['composers'], ['J', 'P'])
self.assertEqual(f.cleaned_data['name'], 'Yesterday')
+ # MultipleHiddenInput uses ducktyping so that
+ # MultiValueDictLike.getlist() is called.
+ f = SongForm(MultiValueDictLike({'name': 'Yesterday', 'composers': 'J'}))
+ self.assertEqual(f.errors, {})
+ self.assertEqual(f.cleaned_data['composers'], ['J'])
+
def test_escaping(self):
# Validation errors are HTML-escaped when output as HTML.
class EscapingForm(Form):