Converted doctest to unittest. Patch by Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13725 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bb00b28399
commit
7543eb95e6
|
@ -22,29 +22,3 @@ class Person(models.Model):
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
__test__ = {'API_TESTS':"""
|
|
||||||
>>> a = Person(name='Adrian', gender='M')
|
|
||||||
>>> a.save()
|
|
||||||
>>> s = Person(name='Sara', gender='F')
|
|
||||||
>>> s.save()
|
|
||||||
>>> a.gender
|
|
||||||
'M'
|
|
||||||
>>> s.gender
|
|
||||||
'F'
|
|
||||||
>>> a.get_gender_display()
|
|
||||||
u'Male'
|
|
||||||
>>> s.get_gender_display()
|
|
||||||
u'Female'
|
|
||||||
|
|
||||||
# If the value for the field doesn't correspond to a valid choice,
|
|
||||||
# the value itself is provided as a display value.
|
|
||||||
>>> a.gender = ''
|
|
||||||
>>> a.get_gender_display()
|
|
||||||
u''
|
|
||||||
|
|
||||||
>>> a.gender = 'U'
|
|
||||||
>>> a.get_gender_display()
|
|
||||||
u'U'
|
|
||||||
|
|
||||||
"""}
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from models import Person
|
||||||
|
|
||||||
|
|
||||||
|
class ChoicesTests(TestCase):
|
||||||
|
def test_display(self):
|
||||||
|
a = Person.objects.create(name='Adrian', gender='M')
|
||||||
|
s = Person.objects.create(name='Sara', gender='F')
|
||||||
|
self.assertEqual(a.gender, 'M')
|
||||||
|
self.assertEqual(s.gender, 'F')
|
||||||
|
|
||||||
|
self.assertEqual(a.get_gender_display(), 'Male')
|
||||||
|
self.assertEqual(s.get_gender_display(), 'Female')
|
||||||
|
|
||||||
|
# If the value for the field doesn't correspond to a valid choice,
|
||||||
|
# the value itself is provided as a display value.
|
||||||
|
a.gender = ''
|
||||||
|
self.assertEqual(a.get_gender_display(), '')
|
||||||
|
|
||||||
|
a.gender = 'U'
|
||||||
|
self.assertEqual(a.get_gender_display(), 'U')
|
||||||
|
|
Loading…
Reference in New Issue