diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-04-18 15:51:11 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-04-18 15:51:11 +0000 |
| commit | 41260fb93165a9fa18dba31b4766c8be50b430cb (patch) | |
| tree | 440f030eebcd9e12a8749185aa69e54eb448ac06 /tests/regressiontests/model_forms_regress/tests.py | |
| parent | 800311964e0325545552febde0e092f93a12208f (diff) | |
Fixed #10156: `ModelMultipleChoiceField.clean` now does a single query instead of O(N). Thanks, Alex Gaynor. Also, I ported a few more doctests to unittests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10582 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/model_forms_regress/tests.py')
| -rw-r--r-- | tests/regressiontests/model_forms_regress/tests.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py new file mode 100644 index 0000000000..6547367812 --- /dev/null +++ b/tests/regressiontests/model_forms_regress/tests.py @@ -0,0 +1,61 @@ +from django import db +from django import forms +from django.conf import settings +from django.test import TestCase +from models import Person, Triple, FilePathModel + +class ModelMultipleChoiceFieldTests(TestCase): + + def setUp(self): + self.old_debug = settings.DEBUG + settings.DEBUG = True + + def tearDown(self): + settings.DEBUG = self.old_debug + + def test_model_multiple_choice_number_of_queries(self): + """ + Test that ModelMultipleChoiceField does O(1) queries instead of + O(n) (#10156). + """ + for i in range(30): + Person.objects.create(name="Person %s" % i) + + db.reset_queries() + f = forms.ModelMultipleChoiceField(queryset=Person.objects.all()) + selected = f.clean([1, 3, 5, 7, 9]) + self.assertEquals(len(db.connection.queries), 1) + +class TripleForm(forms.ModelForm): + class Meta: + model = Triple + +class UniqueTogetherTests(TestCase): + def test_multiple_field_unique_together(self): + """ + When the same field is involved in multiple unique_together + constraints, we need to make sure we don't remove the data for it + before doing all the validation checking (not just failing after + the first one). + """ + Triple.objects.create(left=1, middle=2, right=3) + + form = TripleForm({'left': '1', 'middle': '2', 'right': '3'}) + self.failIf(form.is_valid()) + + form = TripleForm({'left': '1', 'middle': '3', 'right': '1'}) + self.failUnless(form.is_valid()) + +class FPForm(forms.ModelForm): + class Meta: + model = FilePathModel + +class FilePathFieldTests(TestCase): + def test_file_path_field_blank(self): + """ + Regression test for #8842: FilePathField(blank=True) + """ + form = FPForm() + names = [p[1] for p in form['path'].field.choices] + names.sort() + self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py']) |
