Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #13495 -- Refactored the localflavor test directory to …

…provide the placeholder structure for other flavors. Thanks to chronos for the report and patch.

Backport of r13505 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e2fbe478bda2e1294035e433cd952c83d0b62866 1 parent c543f07
Russell Keith-Magee authored August 06, 2010
8  tests/regressiontests/localflavor/models.py
... ...
@@ -1,8 +0,0 @@
1  
-from django.db import models
2  
-from django.contrib.localflavor.us.models import USStateField
3  
-
4  
-class Place(models.Model):
5  
-    state = USStateField(blank=True)
6  
-    state_req = USStateField()
7  
-    state_default = USStateField(default="CA", blank=True)
8  
-    name = models.CharField(max_length=20)
84  tests/regressiontests/localflavor/tests.py
... ...
@@ -1,83 +1,5 @@
  1
+import unittest
1 2
 from django.test import TestCase
2  
-from models import Place
3  
-from forms import PlaceForm
4 3
 
5  
-class USLocalflavorTests(TestCase):
6  
-    def setUp(self):
7  
-        self.form = PlaceForm({'state':'GA', 'state_req':'NC', 'name':'impossible'})
8  
-        
9  
-    def test_get_display_methods(self):
10  
-        """Test that the get_*_display() methods are added to the model instances."""
11  
-        place = self.form.save()
12  
-        self.assertEqual(place.get_state_display(), 'Georgia')
13  
-        self.assertEqual(place.get_state_req_display(), 'North Carolina')
14  
-    
15  
-    def test_required(self):
16  
-        """Test that required USStateFields throw appropriate errors."""
17  
-        form = PlaceForm({'state':'GA', 'name':'Place in GA'})
18  
-        self.assertFalse(form.is_valid())
19  
-        self.assertEqual(form.errors['state_req'], [u'This field is required.'])
20  
-    
21  
-    def test_field_blank_option(self):
22  
-        """Test that the empty option is there."""
23  
-        state_select_html = """\
24  
-<select name="state" id="id_state">
25  
-<option value="">---------</option>
26  
-<option value="AL">Alabama</option>
27  
-<option value="AK">Alaska</option>
28  
-<option value="AS">American Samoa</option>
29  
-<option value="AZ">Arizona</option>
30  
-<option value="AR">Arkansas</option>
31  
-<option value="CA">California</option>
32  
-<option value="CO">Colorado</option>
33  
-<option value="CT">Connecticut</option>
34  
-<option value="DE">Delaware</option>
35  
-<option value="DC">District of Columbia</option>
36  
-<option value="FL">Florida</option>
37  
-<option value="GA" selected="selected">Georgia</option>
38  
-<option value="GU">Guam</option>
39  
-<option value="HI">Hawaii</option>
40  
-<option value="ID">Idaho</option>
41  
-<option value="IL">Illinois</option>
42  
-<option value="IN">Indiana</option>
43  
-<option value="IA">Iowa</option>
44  
-<option value="KS">Kansas</option>
45  
-<option value="KY">Kentucky</option>
46  
-<option value="LA">Louisiana</option>
47  
-<option value="ME">Maine</option>
48  
-<option value="MD">Maryland</option>
49  
-<option value="MA">Massachusetts</option>
50  
-<option value="MI">Michigan</option>
51  
-<option value="MN">Minnesota</option>
52  
-<option value="MS">Mississippi</option>
53  
-<option value="MO">Missouri</option>
54  
-<option value="MT">Montana</option>
55  
-<option value="NE">Nebraska</option>
56  
-<option value="NV">Nevada</option>
57  
-<option value="NH">New Hampshire</option>
58  
-<option value="NJ">New Jersey</option>
59  
-<option value="NM">New Mexico</option>
60  
-<option value="NY">New York</option>
61  
-<option value="NC">North Carolina</option>
62  
-<option value="ND">North Dakota</option>
63  
-<option value="MP">Northern Mariana Islands</option>
64  
-<option value="OH">Ohio</option>
65  
-<option value="OK">Oklahoma</option>
66  
-<option value="OR">Oregon</option>
67  
-<option value="PA">Pennsylvania</option>
68  
-<option value="PR">Puerto Rico</option>
69  
-<option value="RI">Rhode Island</option>
70  
-<option value="SC">South Carolina</option>
71  
-<option value="SD">South Dakota</option>
72  
-<option value="TN">Tennessee</option>
73  
-<option value="TX">Texas</option>
74  
-<option value="UT">Utah</option>
75  
-<option value="VT">Vermont</option>
76  
-<option value="VI">Virgin Islands</option>
77  
-<option value="VA">Virginia</option>
78  
-<option value="WA">Washington</option>
79  
-<option value="WV">West Virginia</option>
80  
-<option value="WI">Wisconsin</option>
81  
-<option value="WY">Wyoming</option>
82  
-</select>"""
83  
-        self.assertEqual(str(self.form['state']), state_select_html)
  4
+# just import your tests here
  5
+from us.tests import *
6  tests/regressiontests/localflavor/forms.py → tests/regressiontests/localflavor/us/forms.py
... ...
@@ -1,7 +1,7 @@
1 1
 from django.forms import ModelForm
2  
-from models import Place
  2
+from models import USPlace
3 3
 
4  
-class PlaceForm(ModelForm):
  4
+class USPlaceForm(ModelForm):
5 5
     """docstring for PlaceForm"""
6 6
     class Meta:
7  
-        model = Place
  7
+        model = USPlace
13  tests/regressiontests/localflavor/us/models.py
... ...
@@ -0,0 +1,13 @@
  1
+from django.db import models
  2
+from django.contrib.localflavor.us.models import USStateField
  3
+
  4
+# When creating models you need to remember to add a app_label as
  5
+# 'localflavor', so your model can be found
  6
+
  7
+class USPlace(models.Model):
  8
+    state = USStateField(blank=True)
  9
+    state_req = USStateField()
  10
+    state_default = USStateField(default="CA", blank=True)
  11
+    name = models.CharField(max_length=20)
  12
+    class Meta:
  13
+        app_label = 'localflavor'
82  tests/regressiontests/localflavor/us/tests.py
... ...
@@ -0,0 +1,82 @@
  1
+from django.test import TestCase
  2
+from forms import USPlaceForm
  3
+
  4
+class USLocalflavorTests(TestCase):
  5
+    def setUp(self):
  6
+        self.form = USPlaceForm({'state':'GA', 'state_req':'NC', 'name':'impossible'})
  7
+
  8
+    def test_get_display_methods(self):
  9
+        """Test that the get_*_display() methods are added to the model instances."""
  10
+        place = self.form.save()
  11
+        self.assertEqual(place.get_state_display(), 'Georgia')
  12
+        self.assertEqual(place.get_state_req_display(), 'North Carolina')
  13
+
  14
+    def test_required(self):
  15
+        """Test that required USStateFields throw appropriate errors."""
  16
+        form = USPlaceForm({'state':'GA', 'name':'Place in GA'})
  17
+        self.assertFalse(form.is_valid())
  18
+        self.assertEqual(form.errors['state_req'], [u'This field is required.'])
  19
+
  20
+    def test_field_blank_option(self):
  21
+        """Test that the empty option is there."""
  22
+        state_select_html = """\
  23
+<select name="state" id="id_state">
  24
+<option value="">---------</option>
  25
+<option value="AL">Alabama</option>
  26
+<option value="AK">Alaska</option>
  27
+<option value="AS">American Samoa</option>
  28
+<option value="AZ">Arizona</option>
  29
+<option value="AR">Arkansas</option>
  30
+<option value="CA">California</option>
  31
+<option value="CO">Colorado</option>
  32
+<option value="CT">Connecticut</option>
  33
+<option value="DE">Delaware</option>
  34
+<option value="DC">District of Columbia</option>
  35
+<option value="FL">Florida</option>
  36
+<option value="GA" selected="selected">Georgia</option>
  37
+<option value="GU">Guam</option>
  38
+<option value="HI">Hawaii</option>
  39
+<option value="ID">Idaho</option>
  40
+<option value="IL">Illinois</option>
  41
+<option value="IN">Indiana</option>
  42
+<option value="IA">Iowa</option>
  43
+<option value="KS">Kansas</option>
  44
+<option value="KY">Kentucky</option>
  45
+<option value="LA">Louisiana</option>
  46
+<option value="ME">Maine</option>
  47
+<option value="MD">Maryland</option>
  48
+<option value="MA">Massachusetts</option>
  49
+<option value="MI">Michigan</option>
  50
+<option value="MN">Minnesota</option>
  51
+<option value="MS">Mississippi</option>
  52
+<option value="MO">Missouri</option>
  53
+<option value="MT">Montana</option>
  54
+<option value="NE">Nebraska</option>
  55
+<option value="NV">Nevada</option>
  56
+<option value="NH">New Hampshire</option>
  57
+<option value="NJ">New Jersey</option>
  58
+<option value="NM">New Mexico</option>
  59
+<option value="NY">New York</option>
  60
+<option value="NC">North Carolina</option>
  61
+<option value="ND">North Dakota</option>
  62
+<option value="MP">Northern Mariana Islands</option>
  63
+<option value="OH">Ohio</option>
  64
+<option value="OK">Oklahoma</option>
  65
+<option value="OR">Oregon</option>
  66
+<option value="PA">Pennsylvania</option>
  67
+<option value="PR">Puerto Rico</option>
  68
+<option value="RI">Rhode Island</option>
  69
+<option value="SC">South Carolina</option>
  70
+<option value="SD">South Dakota</option>
  71
+<option value="TN">Tennessee</option>
  72
+<option value="TX">Texas</option>
  73
+<option value="UT">Utah</option>
  74
+<option value="VT">Vermont</option>
  75
+<option value="VI">Virgin Islands</option>
  76
+<option value="VA">Virginia</option>
  77
+<option value="WA">Washington</option>
  78
+<option value="WV">West Virginia</option>
  79
+<option value="WI">Wisconsin</option>
  80
+<option value="WY">Wyoming</option>
  81
+</select>"""
  82
+        self.assertEqual(str(self.form['state']), state_select_html)

0 notes on commit e2fbe47

Please sign in to comment.
Something went wrong with that request. Please try again.