Ticket #16663: 16663-failing-test.patch

File 16663-failing-test.patch, 2.2 KB (added by Aymeric Augustin, 13 years ago)
  • tests/modeltests/choices/tests.py

     
    11from django.test import TestCase
    22
    3 from models import Person
     3from models import Person, Mutant
    44
    55
    66class ChoicesTests(TestCase):
     7
    78    def test_display(self):
    89        a = Person.objects.create(name='Adrian', gender='M')
    910        s = Person.objects.create(name='Sara', gender='F')
     
    2122        a.gender = 'U'
    2223        self.assertEqual(a.get_gender_display(), 'U')
    2324
     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

     
    2222
    2323    def __unicode__(self):
    2424        return self.name
     25
     26
     27class 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

     
    9393        self.serialize = serialize
    9494        self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month
    9595        self.unique_for_year = unique_for_year
    96         self._choices = choices or []
     96        self._choices = [] if choices is None else choices
    9797        self.help_text = help_text
    9898        self.db_column = db_column
    9999        self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
Back to Top