diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2010-03-09 22:52:04 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2010-03-09 22:52:04 +0000 |
| commit | e316b8b981344c6f4663ddcec268e995db61202e (patch) | |
| tree | 24c035337b03ee5335bcd801ecb158ec19dbaf1e /tests/regressiontests/forms | |
| parent | ea288f14e0066848c31f18a7fc7344c6a51a6926 (diff) | |
Fixed #12048 - MultiWidget does not define `__deepcopy__`
Thanks to powderflask for report, test case and initial patch
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms')
| -rw-r--r-- | tests/regressiontests/forms/tests.py | 1 | ||||
| -rw-r--r-- | tests/regressiontests/forms/widgets.py | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index db70500909..8757e799a9 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -39,6 +39,7 @@ from media import media_tests from fields import FieldsTests from validators import TestFieldWithValidators +from widgets import WidgetTests __test__ = { 'extra_tests': extra_tests, diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py index d862f40b01..cc83a888cf 100644 --- a/tests/regressiontests/forms/widgets.py +++ b/tests/regressiontests/forms/widgets.py @@ -1269,3 +1269,43 @@ u'<input type="hidden" name="date_0" value="17.09.2007" /><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]) |
