parts/django/tests/regressiontests/forms/localflavor/is_.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from django.contrib.localflavor.is_.forms import (ISIdNumberField,
       
     2     ISPhoneNumberField, ISPostalCodeSelect)
       
     3 
       
     4 from utils import LocalFlavorTestCase
       
     5 
       
     6 
       
     7 class ISLocalFlavorTests(LocalFlavorTestCase):
       
     8     def test_ISPostalCodeSelect(self):
       
     9         f = ISPostalCodeSelect()
       
    10         out = u'''<select name="foo">
       
    11 <option value="101">101 Reykjav\xedk</option>
       
    12 <option value="103">103 Reykjav\xedk</option>
       
    13 <option value="104">104 Reykjav\xedk</option>
       
    14 <option value="105">105 Reykjav\xedk</option>
       
    15 <option value="107">107 Reykjav\xedk</option>
       
    16 <option value="108">108 Reykjav\xedk</option>
       
    17 <option value="109">109 Reykjav\xedk</option>
       
    18 <option value="110">110 Reykjav\xedk</option>
       
    19 <option value="111">111 Reykjav\xedk</option>
       
    20 <option value="112">112 Reykjav\xedk</option>
       
    21 <option value="113">113 Reykjav\xedk</option>
       
    22 <option value="116">116 Kjalarnes</option>
       
    23 <option value="121">121 Reykjav\xedk</option>
       
    24 <option value="123">123 Reykjav\xedk</option>
       
    25 <option value="124">124 Reykjav\xedk</option>
       
    26 <option value="125">125 Reykjav\xedk</option>
       
    27 <option value="127">127 Reykjav\xedk</option>
       
    28 <option value="128">128 Reykjav\xedk</option>
       
    29 <option value="129">129 Reykjav\xedk</option>
       
    30 <option value="130">130 Reykjav\xedk</option>
       
    31 <option value="132">132 Reykjav\xedk</option>
       
    32 <option value="150">150 Reykjav\xedk</option>
       
    33 <option value="155">155 Reykjav\xedk</option>
       
    34 <option value="170">170 Seltjarnarnes</option>
       
    35 <option value="172">172 Seltjarnarnes</option>
       
    36 <option value="190">190 Vogar</option>
       
    37 <option value="200">200 K\xf3pavogur</option>
       
    38 <option value="201">201 K\xf3pavogur</option>
       
    39 <option value="202">202 K\xf3pavogur</option>
       
    40 <option value="203">203 K\xf3pavogur</option>
       
    41 <option value="210">210 Gar\xf0ab\xe6r</option>
       
    42 <option value="212">212 Gar\xf0ab\xe6r</option>
       
    43 <option value="220">220 Hafnarfj\xf6r\xf0ur</option>
       
    44 <option value="221">221 Hafnarfj\xf6r\xf0ur</option>
       
    45 <option value="222">222 Hafnarfj\xf6r\xf0ur</option>
       
    46 <option value="225">225 \xc1lftanes</option>
       
    47 <option value="230">230 Reykjanesb\xe6r</option>
       
    48 <option value="232">232 Reykjanesb\xe6r</option>
       
    49 <option value="233">233 Reykjanesb\xe6r</option>
       
    50 <option value="235">235 Keflav\xedkurflugv\xf6llur</option>
       
    51 <option value="240">240 Grindav\xedk</option>
       
    52 <option value="245">245 Sandger\xf0i</option>
       
    53 <option value="250">250 Gar\xf0ur</option>
       
    54 <option value="260">260 Reykjanesb\xe6r</option>
       
    55 <option value="270">270 Mosfellsb\xe6r</option>
       
    56 <option value="300">300 Akranes</option>
       
    57 <option value="301">301 Akranes</option>
       
    58 <option value="302">302 Akranes</option>
       
    59 <option value="310">310 Borgarnes</option>
       
    60 <option value="311">311 Borgarnes</option>
       
    61 <option value="320">320 Reykholt \xed Borgarfir\xf0i</option>
       
    62 <option value="340">340 Stykkish\xf3lmur</option>
       
    63 <option value="345">345 Flatey \xe1 Brei\xf0afir\xf0i</option>
       
    64 <option value="350">350 Grundarfj\xf6r\xf0ur</option>
       
    65 <option value="355">355 \xd3lafsv\xedk</option>
       
    66 <option value="356">356 Sn\xe6fellsb\xe6r</option>
       
    67 <option value="360">360 Hellissandur</option>
       
    68 <option value="370">370 B\xfa\xf0ardalur</option>
       
    69 <option value="371">371 B\xfa\xf0ardalur</option>
       
    70 <option value="380">380 Reykh\xf3lahreppur</option>
       
    71 <option value="400">400 \xcdsafj\xf6r\xf0ur</option>
       
    72 <option value="401">401 \xcdsafj\xf6r\xf0ur</option>
       
    73 <option value="410">410 Hn\xedfsdalur</option>
       
    74 <option value="415">415 Bolungarv\xedk</option>
       
    75 <option value="420">420 S\xfa\xf0av\xedk</option>
       
    76 <option value="425">425 Flateyri</option>
       
    77 <option value="430">430 Su\xf0ureyri</option>
       
    78 <option value="450">450 Patreksfj\xf6r\xf0ur</option>
       
    79 <option value="451">451 Patreksfj\xf6r\xf0ur</option>
       
    80 <option value="460">460 T\xe1lknafj\xf6r\xf0ur</option>
       
    81 <option value="465">465 B\xedldudalur</option>
       
    82 <option value="470">470 \xdeingeyri</option>
       
    83 <option value="471">471 \xdeingeyri</option>
       
    84 <option value="500">500 Sta\xf0ur</option>
       
    85 <option value="510">510 H\xf3lmav\xedk</option>
       
    86 <option value="512">512 H\xf3lmav\xedk</option>
       
    87 <option value="520">520 Drangsnes</option>
       
    88 <option value="522">522 Kj\xf6rvogur</option>
       
    89 <option value="523">523 B\xe6r</option>
       
    90 <option value="524">524 Nor\xf0urfj\xf6r\xf0ur</option>
       
    91 <option value="530">530 Hvammstangi</option>
       
    92 <option value="531">531 Hvammstangi</option>
       
    93 <option value="540">540 Bl\xf6ndu\xf3s</option>
       
    94 <option value="541">541 Bl\xf6ndu\xf3s</option>
       
    95 <option value="545">545 Skagastr\xf6nd</option>
       
    96 <option value="550">550 Sau\xf0\xe1rkr\xf3kur</option>
       
    97 <option value="551">551 Sau\xf0\xe1rkr\xf3kur</option>
       
    98 <option value="560">560 Varmahl\xed\xf0</option>
       
    99 <option value="565">565 Hofs\xf3s</option>
       
   100 <option value="566">566 Hofs\xf3s</option>
       
   101 <option value="570">570 Flj\xf3t</option>
       
   102 <option value="580">580 Siglufj\xf6r\xf0ur</option>
       
   103 <option value="600">600 Akureyri</option>
       
   104 <option value="601">601 Akureyri</option>
       
   105 <option value="602">602 Akureyri</option>
       
   106 <option value="603">603 Akureyri</option>
       
   107 <option value="610">610 Greniv\xedk</option>
       
   108 <option value="611">611 Gr\xedmsey</option>
       
   109 <option value="620">620 Dalv\xedk</option>
       
   110 <option value="621">621 Dalv\xedk</option>
       
   111 <option value="625">625 \xd3lafsfj\xf6r\xf0ur</option>
       
   112 <option value="630">630 Hr\xedsey</option>
       
   113 <option value="640">640 H\xfasav\xedk</option>
       
   114 <option value="641">641 H\xfasav\xedk</option>
       
   115 <option value="645">645 Fossh\xf3ll</option>
       
   116 <option value="650">650 Laugar</option>
       
   117 <option value="660">660 M\xfdvatn</option>
       
   118 <option value="670">670 K\xf3pasker</option>
       
   119 <option value="671">671 K\xf3pasker</option>
       
   120 <option value="675">675 Raufarh\xf6fn</option>
       
   121 <option value="680">680 \xde\xf3rsh\xf6fn</option>
       
   122 <option value="681">681 \xde\xf3rsh\xf6fn</option>
       
   123 <option value="685">685 Bakkafj\xf6r\xf0ur</option>
       
   124 <option value="690">690 Vopnafj\xf6r\xf0ur</option>
       
   125 <option value="700">700 Egilssta\xf0ir</option>
       
   126 <option value="701">701 Egilssta\xf0ir</option>
       
   127 <option value="710">710 Sey\xf0isfj\xf6r\xf0ur</option>
       
   128 <option value="715">715 Mj\xf3ifj\xf6r\xf0ur</option>
       
   129 <option value="720">720 Borgarfj\xf6r\xf0ur eystri</option>
       
   130 <option value="730">730 Rey\xf0arfj\xf6r\xf0ur</option>
       
   131 <option value="735">735 Eskifj\xf6r\xf0ur</option>
       
   132 <option value="740">740 Neskaupsta\xf0ur</option>
       
   133 <option value="750">750 F\xe1skr\xfa\xf0sfj\xf6r\xf0ur</option>
       
   134 <option value="755">755 St\xf6\xf0varfj\xf6r\xf0ur</option>
       
   135 <option value="760">760 Brei\xf0dalsv\xedk</option>
       
   136 <option value="765">765 Dj\xfapivogur</option>
       
   137 <option value="780">780 H\xf6fn \xed Hornafir\xf0i</option>
       
   138 <option value="781">781 H\xf6fn \xed Hornafir\xf0i</option>
       
   139 <option value="785">785 \xd6r\xe6fi</option>
       
   140 <option value="800">800 Selfoss</option>
       
   141 <option value="801">801 Selfoss</option>
       
   142 <option value="802">802 Selfoss</option>
       
   143 <option value="810">810 Hverager\xf0i</option>
       
   144 <option value="815">815 \xdeorl\xe1ksh\xf6fn</option>
       
   145 <option value="820">820 Eyrarbakki</option>
       
   146 <option value="825">825 Stokkseyri</option>
       
   147 <option value="840">840 Laugarvatn</option>
       
   148 <option value="845">845 Fl\xfa\xf0ir</option>
       
   149 <option value="850">850 Hella</option>
       
   150 <option value="851">851 Hella</option>
       
   151 <option value="860">860 Hvolsv\xf6llur</option>
       
   152 <option value="861">861 Hvolsv\xf6llur</option>
       
   153 <option value="870">870 V\xedk</option>
       
   154 <option value="871">871 V\xedk</option>
       
   155 <option value="880">880 Kirkjub\xe6jarklaustur</option>
       
   156 <option value="900">900 Vestmannaeyjar</option>
       
   157 <option value="902">902 Vestmannaeyjar</option>
       
   158 </select>'''
       
   159         self.assertEqual(f.render('foo', 'bar'), out)
       
   160     
       
   161     def test_ISIdNumberField(self):
       
   162         error_atleast = [u'Ensure this value has at least 10 characters (it has 9).']
       
   163         error_invalid = [u'Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.']
       
   164         error_atmost = [u'Ensure this value has at most 11 characters (it has 12).']
       
   165         error_notvalid = [u'The Icelandic identification number is not valid.']
       
   166         valid = {
       
   167             '2308803449': '230880-3449',
       
   168             '230880-3449': '230880-3449',
       
   169             '230880 3449': '230880-3449',
       
   170             '2308803440': '230880-3440',
       
   171         }
       
   172         invalid = {
       
   173             '230880343': error_atleast + error_invalid,
       
   174             '230880343234': error_atmost + error_invalid,
       
   175             'abcdefghijk': error_invalid,
       
   176             '2308803439': error_notvalid,
       
   177         
       
   178         }
       
   179         self.assertFieldOutput(ISIdNumberField, valid, invalid)
       
   180     
       
   181     def test_ISPhoneNumberField(self):
       
   182         error_invalid = [u'Enter a valid value.']
       
   183         error_atleast = [u'Ensure this value has at least 7 characters (it has 6).']
       
   184         error_atmost = [u'Ensure this value has at most 8 characters (it has 9).']
       
   185         valid = {
       
   186             '1234567': '1234567',
       
   187             '123 4567': '1234567',
       
   188             '123-4567': '1234567',
       
   189         }
       
   190         invalid = {
       
   191             '123-456': error_invalid,
       
   192             '123456': error_atleast + error_invalid,
       
   193             '123456555': error_atmost + error_invalid,
       
   194             'abcdefg': error_invalid,
       
   195             ' 1234567 ': error_atmost + error_invalid,
       
   196             ' 12367  ': error_invalid
       
   197         }
       
   198         self.assertFieldOutput(ISPhoneNumberField, valid, invalid)
       
   199