summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms/widgets.py
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2010-03-09 22:59:02 +0000
committerLuke Plant <L.Plant.98@cantab.net>2010-03-09 22:59:02 +0000
commit693dcd90139a87462fc636c0b698743bfce677a0 (patch)
tree5e874b3bd6a12c2e9e515a5ff4f879a600415eda /tests/regressiontests/forms/widgets.py
parent0a7ec91dc3fb03502a38ea501f2b24f5730c484c (diff)
[1.1.X] Fixed #12048 - MultiWidget does not define `__deepcopy__`
Thanks to powderflask for report, test case and initial patch. Backport of [12739] from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12740 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/widgets.py')
-rw-r--r--tests/regressiontests/forms/widgets.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
index a397cdf63b..dfa3a79353 100644
--- a/tests/regressiontests/forms/widgets.py
+++ b/tests/regressiontests/forms/widgets.py
@@ -1234,3 +1234,43 @@ u'<input type="hidden" name="date_0" value="2007-09-17" /><input type="hidden" n
"""
+
+from django.utils import copycompat as copy
+from unittest import TestCase
+from django import forms
+
+
+class SelectAndTextWidget(forms.MultiWidget):
+ """
+ MultiWidget subclass
+ """
+ def __init__(self, choices=[]):
+ widgets = [
+ forms.RadioSelect(choices=choices),
+ forms.TextInput
+ ]
+ super(SelectAndTextWidget, self).__init__(widgets)
+
+ def _set_choices(self, choices):
+ """
+ When choices are set for this widget, we want to pass those along to the Select widget
+ """
+ self.widgets[0].choices = choices
+ def _get_choices(self):
+ """
+ The choices for this widget are the Select widget's choices
+ """
+ return self.widgets[0].choices
+ choices = property(_get_choices, _set_choices)
+
+
+class WidgetTests(TestCase):
+
+ def test_12048(self):
+ # See ticket #12048.
+ w1 = SelectAndTextWidget(choices=[1,2,3])
+ w2 = copy.deepcopy(w1)
+ w2.choices = [4,5,6]
+ # w2 ought to be independent of w1, since MultiWidget ought
+ # to make a copy of its sub-widgets when it is copied.
+ self.assertEqual(w1.choices, [1,2,3])