From 7289013cf18905ad2022eb21a51be91b02284a56 Mon Sep 17 00:00:00 2001 From: Paul McMillan Date: Wed, 9 Jun 2010 22:13:03 +0000 Subject: [PATCH] Converted modeltests.choices to unittests git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/test-refactor@13344 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../choices/fixtures/initial_data.json | 18 +++++++++++ tests/modeltests/choices/models.py | 26 ---------------- tests/modeltests/choices/tests.py | 31 +++++++++++++++++++ 3 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 tests/modeltests/choices/fixtures/initial_data.json create mode 100644 tests/modeltests/choices/tests.py diff --git a/tests/modeltests/choices/fixtures/initial_data.json b/tests/modeltests/choices/fixtures/initial_data.json new file mode 100644 index 0000000000000..e8236ce7c8157 --- /dev/null +++ b/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" + } + } +] \ No newline at end of file diff --git a/tests/modeltests/choices/models.py b/tests/modeltests/choices/models.py index e37826059879e..27316f5deae79 100644 --- a/tests/modeltests/choices/models.py +++ b/tests/modeltests/choices/models.py @@ -22,29 +22,3 @@ class Person(models.Model): def __unicode__(self): 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' - -"""} diff --git a/tests/modeltests/choices/tests.py b/tests/modeltests/choices/tests.py new file mode 100644 index 0000000000000..ed593a91085ab --- /dev/null +++ b/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')