Ticket #13495: ticket13495.patch

File ticket13495.patch, 10.7 KB (added by Felipe 'chronos' Prenholato, 15 years ago)

Refactoring of localflavor tests. Maybe is better check structure here: http://1l.to/g1e

  • deleted file tests/regressiontests/localflavor/forms.py

    diff --git a/tests/regressiontests/localflavor/__init__.py b/tests/regressiontests/localflavor/__init__.py
    deleted file mode 100644
    index e69de29..0000000
    diff --git a/tests/regressiontests/localflavor/forms.py b/tests/regressiontests/localflavor/forms.py
    deleted file mode 100644
    index 2dd1da6..0000000
    + -  
    1 from django.forms import ModelForm
    2 from models import Place
    3 
    4 class PlaceForm(ModelForm):
    5     """docstring for PlaceForm"""
    6     class Meta:
    7         model = Place
  • deleted file tests/regressiontests/localflavor/models.py

    diff --git a/tests/regressiontests/localflavor/models.py b/tests/regressiontests/localflavor/models.py
    deleted file mode 100644
    index f74a505..0000000
    + -  
    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)
  • deleted file tests/regressiontests/localflavor/tests.py

    diff --git a/tests/regressiontests/localflavor/tests.py b/tests/regressiontests/localflavor/tests.py
    deleted file mode 100644
    index 0ea3c52..0000000
    + -  
    1 from django.test import TestCase
    2 from models import Place
    3 from forms import PlaceForm
    4 
    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)
  • new file tests/regressiontests/localflavor_regress/tests.py

    diff --git a/tests/regressiontests/localflavor_regress/__init__.py b/tests/regressiontests/localflavor_regress/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/localflavor_regress/br/__init__.py b/tests/regressiontests/localflavor_regress/br/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/localflavor_regress/models.py b/tests/regressiontests/localflavor_regress/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/localflavor_regress/tests.py b/tests/regressiontests/localflavor_regress/tests.py
    new file mode 100644
    index 0000000..528a1b1
    - +  
     1import unittest
     2from django.test import TestCase
     3
     4# just import your tests here
     5from us.tests import *
     6
     7
     8# Get every subclass of TestCase and add to suite
     9# Now script check for every imported class, if is a subclass of TestCase add
     10# to testlist, and then suite create a TestSuite with these clases.
     11testlist=[]
     12for i in locals().values():
     13    try:
     14        if issubclass(i,TestCase) and i is not TestCase:
     15            testlist.append(unittest.TestLoader().loadTestsFromTestCase(i))
     16    except TypeError:
     17        pass
     18
     19def suite():
     20    return unittest.TestSuite(list(testlist))
     21
  • new file tests/regressiontests/localflavor_regress/us/forms.py

    diff --git a/tests/regressiontests/localflavor_regress/us/__init__.py b/tests/regressiontests/localflavor_regress/us/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/localflavor_regress/us/forms.py b/tests/regressiontests/localflavor_regress/us/forms.py
    new file mode 100644
    index 0000000..9b77e10
    - +  
     1from django.forms import ModelForm
     2from models import USPlace
     3
     4class USPlaceForm(ModelForm):
     5    """docstring for PlaceForm"""
     6    class Meta:
     7        model = USPlace
  • new file tests/regressiontests/localflavor_regress/us/models.py

    diff --git a/tests/regressiontests/localflavor_regress/us/models.py b/tests/regressiontests/localflavor_regress/us/models.py
    new file mode 100644
    index 0000000..f944014
    - +  
     1from django.db import models
     2from django.contrib.localflavor.us.models import USStateField
     3
     4# When creating models you need to remember to add a app_label as
     5# 'localflavor_regress', so your model can be found
     6
     7class 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_regress'
  • new file tests/regressiontests/localflavor_regress/us/tests.py

    diff --git a/tests/regressiontests/localflavor_regress/us/tests.py b/tests/regressiontests/localflavor_regress/us/tests.py
    new file mode 100644
    index 0000000..e85f0ad
    - +  
     1from django.test import TestCase
     2from forms import USPlaceForm
     3
     4class 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)
Back to Top