Ticket #16663: 16663-failing-test.patch
File 16663-failing-test.patch, 2.2 KB (added by , 13 years ago) |
---|
-
tests/modeltests/choices/tests.py
1 1 from django.test import TestCase 2 2 3 from models import Person 3 from models import Person, Mutant 4 4 5 5 6 6 class ChoicesTests(TestCase): 7 7 8 def test_display(self): 8 9 a = Person.objects.create(name='Adrian', gender='M') 9 10 s = Person.objects.create(name='Sara', gender='F') … … 21 22 a.gender = 'U' 22 23 self.assertEqual(a.get_gender_display(), 'U') 23 24 25 def test_mutable_list_of_choices(self): 26 # Regression test for #16663: when a list (or list-like object) is 27 # passed in the `choices` keyword argument of the field, it must be 28 # used even if it's empty. 29 m = Mutant.objects.create(name='Alien', gender='O') 30 import pdb; pdb.set_trace() 31 self.assertEqual(m.get_gender_display(), 'O') 32 Mutant.gender_choices = [('O', 'Other')] 33 self.assertEqual(m.get_gender_display(), 'Other') 34 -
tests/modeltests/choices/models.py
22 22 23 23 def __unicode__(self): 24 24 return self.name 25 26 27 class Mutant(models.Model): 28 gender_choices = [] 29 30 name = models.CharField(max_length=20) 31 gender = models.CharField(max_length=1, choices=gender_choices) -
django/db/models/fields/__init__.py
93 93 self.serialize = serialize 94 94 self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month 95 95 self.unique_for_year = unique_for_year 96 self._choices = choices or []96 self._choices = [] if choices is None else choices 97 97 self.help_text = help_text 98 98 self.db_column = db_column 99 99 self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE