Navigation Menu

Skip to content

Commit

Permalink
Converted modeltests.choices to unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMcMillan committed Jun 9, 2010
1 parent e3bad40 commit 7289013
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
18 changes: 18 additions & 0 deletions tests/modeltests/choices/fixtures/initial_data.json
@@ -0,0 +1,18 @@
[
{
"pk": 1,
"model": "choices.person",
"fields": {
"gender": "M",
"name": "Adrian"
}
},
{
"pk": 2,
"model": "choices.person",
"fields": {
"gender": "F",
"name": "Sara"
}
}
]
26 changes: 0 additions & 26 deletions tests/modeltests/choices/models.py
Expand Up @@ -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'
"""}
31 changes: 31 additions & 0 deletions tests/modeltests/choices/tests.py
@@ -0,0 +1,31 @@
from django.test import TestCase

from models import Person

class ChoicesFieldTestCase(TestCase):
fixtures = ['initial_data.json']

def setUp(self):
self.a = Person.objects.get(name='Adrian')
self.s = Person.objects.get(name='Sara')

def test_choice_storage(self):
self.assertEqual(self.a.gender,
'M')
self.assertEqual(self.s.gender,
'F')

def test_gender_display(self):
self.assertEqual(self.a.get_gender_display(),
u'Male')
self.assertEqual(self.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.
self.a.gender = ''
self.assertEqual(self.a.get_gender_display(),
u'')
self.a.gender = 'U'
self.assertEqual(self.a.get_gender_display(),
u'U')

0 comments on commit 7289013

Please sign in to comment.