summaryrefslogtreecommitdiff
path: root/tests/regressiontests/model_fields
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-04-10 19:54:31 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-04-10 19:54:31 +0000
commita34b718192b4356a5ab39ac49d0e927d8a425a9c (patch)
treee3c445b7635b7e79cf67b31b617c610a1cab76a6 /tests/regressiontests/model_fields
parent3524c74f0bc4d88c8c0643c97ef51970b6aef220 (diff)
Fixed #9640, #10549: BooleanFields with choices, a default, and null=False now correctly doesn't generate a blank option.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10500 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/model_fields')
-rw-r--r--tests/regressiontests/model_fields/tests.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
index ec52668e60..3d232ffeee 100644
--- a/tests/regressiontests/model_fields/tests.py
+++ b/tests/regressiontests/model_fields/tests.py
@@ -1,6 +1,7 @@
import datetime
import unittest
import django.test
+from django import forms
from django.db import models
from django.core.exceptions import ValidationError
from models import Foo, Bar, Whiz, BigD, BigS
@@ -83,10 +84,22 @@ class BooleanFieldTests(unittest.TestCase):
def test_booleanfield_get_db_prep_lookup(self):
self._test_get_db_prep_lookup(models.BooleanField())
-
+
def test_nullbooleanfield_get_db_prep_lookup(self):
self._test_get_db_prep_lookup(models.NullBooleanField())
+ def test_booleanfield_choices_blank(self):
+ """
+ Test that BooleanField with choices and defaults doesn't generate a
+ formfield with the blank option (#9640, #10549).
+ """
+ choices = [(1, u'Si'), (2, 'No')]
+ f = models.BooleanField(choices=choices, default=1, null=True)
+ self.assertEqual(f.formfield().choices, [('', '---------')] + choices)
+
+ f = models.BooleanField(choices=choices, default=1, null=False)
+ self.assertEqual(f.formfield().choices, choices)
+
class ChoicesTests(django.test.TestCase):
def test_choices_and_field_display(self):
"""