Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted modeltests.choices to unittests
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/test-refactor@13344 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
1 parent
e3bad40
commit 7289013
Showing
3 changed files
with
49 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
[ | |||
{ | |||
"pk": 1, | |||
"model": "choices.person", | |||
"fields": { | |||
"gender": "M", | |||
"name": "Adrian" | |||
} | |||
}, | |||
{ | |||
"pk": 2, | |||
"model": "choices.person", | |||
"fields": { | |||
"gender": "F", | |||
"name": "Sara" | |||
} | |||
} | |||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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') |