From 0db9911316adc406a5966ab967e452084e3f0316 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 6 Aug 2010 16:18:10 +0000 Subject: [PATCH] Fixed #13495 -- Refactored the localflavor test directory to provide the placeholder structure for other flavors. Thanks to chronos for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13505 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/localflavor/models.py | 8 -- tests/regressiontests/localflavor/tests.py | 84 +------------------ .../localflavor/{ => us}/forms.py | 6 +- .../regressiontests/localflavor/us/models.py | 13 +++ tests/regressiontests/localflavor/us/tests.py | 82 ++++++++++++++++++ 5 files changed, 101 insertions(+), 92 deletions(-) rename tests/regressiontests/localflavor/{ => us}/forms.py (51%) create mode 100644 tests/regressiontests/localflavor/us/models.py create mode 100644 tests/regressiontests/localflavor/us/tests.py diff --git a/tests/regressiontests/localflavor/models.py b/tests/regressiontests/localflavor/models.py index f74a5051d4..e69de29bb2 100644 --- a/tests/regressiontests/localflavor/models.py +++ b/tests/regressiontests/localflavor/models.py @@ -1,8 +0,0 @@ -from django.db import models -from django.contrib.localflavor.us.models import USStateField - -class Place(models.Model): - state = USStateField(blank=True) - state_req = USStateField() - state_default = USStateField(default="CA", blank=True) - name = models.CharField(max_length=20) diff --git a/tests/regressiontests/localflavor/tests.py b/tests/regressiontests/localflavor/tests.py index 0ea3c52568..69682360d3 100644 --- a/tests/regressiontests/localflavor/tests.py +++ b/tests/regressiontests/localflavor/tests.py @@ -1,83 +1,5 @@ +import unittest from django.test import TestCase -from models import Place -from forms import PlaceForm -class USLocalflavorTests(TestCase): - def setUp(self): - self.form = PlaceForm({'state':'GA', 'state_req':'NC', 'name':'impossible'}) - - def test_get_display_methods(self): - """Test that the get_*_display() methods are added to the model instances.""" - place = self.form.save() - self.assertEqual(place.get_state_display(), 'Georgia') - self.assertEqual(place.get_state_req_display(), 'North Carolina') - - def test_required(self): - """Test that required USStateFields throw appropriate errors.""" - form = PlaceForm({'state':'GA', 'name':'Place in GA'}) - self.assertFalse(form.is_valid()) - self.assertEqual(form.errors['state_req'], [u'This field is required.']) - - def test_field_blank_option(self): - """Test that the empty option is there.""" - state_select_html = """\ -""" - self.assertEqual(str(self.form['state']), state_select_html) +# just import your tests here +from us.tests import * diff --git a/tests/regressiontests/localflavor/forms.py b/tests/regressiontests/localflavor/us/forms.py similarity index 51% rename from tests/regressiontests/localflavor/forms.py rename to tests/regressiontests/localflavor/us/forms.py index 2dd1da6dd0..9b77e1078b 100644 --- a/tests/regressiontests/localflavor/forms.py +++ b/tests/regressiontests/localflavor/us/forms.py @@ -1,7 +1,7 @@ from django.forms import ModelForm -from models import Place +from models import USPlace -class PlaceForm(ModelForm): +class USPlaceForm(ModelForm): """docstring for PlaceForm""" class Meta: - model = Place + model = USPlace diff --git a/tests/regressiontests/localflavor/us/models.py b/tests/regressiontests/localflavor/us/models.py new file mode 100644 index 0000000000..a8a4cf0f50 --- /dev/null +++ b/tests/regressiontests/localflavor/us/models.py @@ -0,0 +1,13 @@ +from django.db import models +from django.contrib.localflavor.us.models import USStateField + +# When creating models you need to remember to add a app_label as +# 'localflavor', so your model can be found + +class USPlace(models.Model): + state = USStateField(blank=True) + state_req = USStateField() + state_default = USStateField(default="CA", blank=True) + name = models.CharField(max_length=20) + class Meta: + app_label = 'localflavor' diff --git a/tests/regressiontests/localflavor/us/tests.py b/tests/regressiontests/localflavor/us/tests.py new file mode 100644 index 0000000000..07fe057833 --- /dev/null +++ b/tests/regressiontests/localflavor/us/tests.py @@ -0,0 +1,82 @@ +from django.test import TestCase +from forms import USPlaceForm + +class USLocalflavorTests(TestCase): + def setUp(self): + self.form = USPlaceForm({'state':'GA', 'state_req':'NC', 'name':'impossible'}) + + def test_get_display_methods(self): + """Test that the get_*_display() methods are added to the model instances.""" + place = self.form.save() + self.assertEqual(place.get_state_display(), 'Georgia') + self.assertEqual(place.get_state_req_display(), 'North Carolina') + + def test_required(self): + """Test that required USStateFields throw appropriate errors.""" + form = USPlaceForm({'state':'GA', 'name':'Place in GA'}) + self.assertFalse(form.is_valid()) + self.assertEqual(form.errors['state_req'], [u'This field is required.']) + + def test_field_blank_option(self): + """Test that the empty option is there.""" + state_select_html = """\ +""" + self.assertEqual(str(self.form['state']), state_select_html)