Ticket #14567: empty_queryset_test.diff
File empty_queryset_test.diff, 2.1 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/forms/models.py
4 4 import tempfile 5 5 6 6 from django.db import models 7 from django.db.models.query import QuerySet 7 8 # Can't import as "forms" due to implementation details in the test suite (the 8 9 # current file is called "forms" and is already imported). 9 10 from django import forms as django_forms … … 55 56 default=lambda: ChoiceOptionModel.objects.filter(name='default')) 56 57 multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int', 57 58 default=lambda: [1]) 59 multi_choice_optional = models.ManyToManyField(ChoiceOptionModel, blank=True, null=True, 60 related_name='multi_choice_optional') 58 61 59 62 class ChoiceFieldForm(django_forms.ModelForm): 60 63 class Meta: … … 85 88 self.assertNumQueries(1, test) 86 89 87 90 class ModelFormCallableModelDefault(TestCase): 91 def test_empty_queryset_return(self): 92 "If a model's ManyToManyField has blank=True and is saved with no data, a queryset is returned." 93 option = ChoiceOptionModel.objects.create(id=1, name='default') 94 form = ChoiceFieldForm({'multi_choice_optional': '', 'choice': option.id, 'choice_int': 1, 95 'multi_choice': ['1'], 'multi_choice_int': [1]}) 96 self.assertEqual(form.is_valid(), True) 97 self.assertEqual(isinstance(form.cleaned_data['multi_choice_optional'], QuerySet), True) 98 # While we're at it, test whether a QuerySet is returned if there *is* a value. 99 self.assertEqual(isinstance(form.cleaned_data['multi_choice'], QuerySet), True) 100 88 101 def test_no_empty_option(self): 89 102 "If a model's ForeignKey has blank=False and a default, no empty option is created (Refs #10792)." 90 103 option = ChoiceOptionModel.objects.create(name='default')