PageRenderTime 100ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/tests/modeltests/choices/tests.py

https://code.google.com/p/mango-py/
Python | 23 lines | 16 code | 5 blank | 2 comment | 0 complexity | f8e80db7e86637f8dd74ef561c6dffad MD5 | raw file
 1from django.test import TestCase
 2
 3from models import Person
 4
 5
 6class ChoicesTests(TestCase):
 7    def test_display(self):
 8        a = Person.objects.create(name='Adrian', gender='M')
 9        s = Person.objects.create(name='Sara', gender='F')
10        self.assertEqual(a.gender, 'M')
11        self.assertEqual(s.gender, 'F')
12        
13        self.assertEqual(a.get_gender_display(), 'Male')
14        self.assertEqual(s.get_gender_display(), 'Female')
15        
16        # If the value for the field doesn't correspond to a valid choice,
17        # the value itself is provided as a display value.
18        a.gender = ''
19        self.assertEqual(a.get_gender_display(), '')
20
21        a.gender = 'U'
22        self.assertEqual(a.get_gender_display(), 'U')
23