Ticket #15856: localflavor_mk.patch

File localflavor_mk.patch, 26.1 KB (added by vasiliyeah, 4 years ago)

patch that adds contrib.localflavor.mk

  • new file django/contrib/localflavor/mk/forms.py

    diff --git a/django/contrib/localflavor/mk/__init__.py b/django/contrib/localflavor/mk/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/localflavor/mk/forms.py b/django/contrib/localflavor/mk/forms.py
    new file mode 100644
    index 0000000..485a317
    - +  
     1import datetime
     2from mk_choices import MK_MUNICIPALITIES
     3from django.forms import ValidationError
     4from django.forms.fields import RegexField, Select, CharField, Field, RegexField
     5from django.core.validators import EMPTY_VALUES
     6from django.utils.translation import ugettext_lazy as _
     7
     8class MKIdentityCardNumberField(RegexField):
     9    """
     10    A Macedonian ID card number. Accepts both old and new format.
     11    """
     12   
     13    default_error_messages = {
     14        'invalid': _(u'Identity card numbers must contain'\
     15                         ' either 4 to 7 digits or an uppercase letter and 7 digits.'),
     16    }
     17   
     18    def __init__(self, *args, **kwargs):
     19        kwargs['min_length'] = None
     20        kwargs['max_length'] = 8
     21        regex = ur'(^[A-Z]{1}\d{7}$)|(^\d{4,7}$)'
     22        super(MKIdentityCardNumberField, self).__init__(regex, *args, **kwargs)
     23       
     24   
     25
     26class MKMunicipalitySelect(Select):
     27    """
     28    A form ``Select`` widget that uses a list of Macedonian municipalities as
     29    choices. The label is the name of the municipality and the value
     30    is a 2 character code for the municipality.
     31    """
     32   
     33    def __init__(self, attrs=None):
     34        super(MKMunicipalitySelect, self).__init__(attrs, choices = MK_MUNICIPALITIES)
     35
     36       
     37
     38class UMCNField(RegexField):
     39    """
     40    A form field that validates input as a unique master citizen
     41    number.
     42
     43    The format of the unique master citizen number has been kept the same from
     44    Yugoslavia. It is still in use in other countries as well, it is not applicable
     45    solely in Macedonia. For more information see: 
     46    https://secure.wikimedia.org/wikipedia/en/wiki/Unique_Master_Citizen_Number
     47
     48    A value will pass validation if it complies to the following rules:
     49
     50    * Consists of exactly 13 digits
     51    * The first 7 digits represent a valid past date in the format DDMMYYY
     52    * The last digit of the UMCN passes a checksum test
     53    """
     54   
     55    default_error_messages = {
     56        'invalid': _(u'This field should contain exactly 13 digits.'),
     57        'date': _(u'The first 7 digits of the UMCN must represent a valid past date.'),
     58        'checksum': _(u'The UMCN is not valid.'),
     59    }
     60   
     61    def __init__(self, *args, **kwargs):
     62        kwargs['min_length'] = None
     63        kwargs['max_length'] = 13
     64        super(UMCNField, self).__init__(r'^\d{13}$', *args, **kwargs)
     65   
     66   
     67    def clean(self, value):
     68        value = super(UMCNField, self).clean(value)
     69
     70        if value in EMPTY_VALUES:
     71            return u''
     72
     73
     74        if not self._validate_date_part(value):
     75            raise ValidationError(self.error_messages['date'])
     76        if self._validate_checksum(value):
     77            return value
     78        else:
     79            raise ValidationError(self.error_messages['checksum'])
     80       
     81    def _validate_checksum(self, value):
     82        a,b,c,d,e,f,g,h,i,j,k,l,K = [int(digit) for digit in  value]
     83        m = 11 - (( 7*(a+g) + 6*(b+h) + 5*(c+i) + 4*(d+j) + 3*(e+k) + 2*(f+l)) % 11)
     84        if (m >= 1 and m <= 9) and K == m:
     85            return True
     86        elif m == 11 and K == 0:
     87            return True
     88        else:
     89            return False
     90   
     91    def _validate_date_part(self, value):
     92        daypart, monthpart, yearpart = int(value[:2]), int(value[2:4]), int(value[4:7])
     93        if yearpart >= 800:
     94            yearpart += 1000
     95        else:
     96            yearpart += 2000
     97        try:
     98            date = datetime.datetime(year = yearpart, month = monthpart, day = daypart).date()
     99        except ValueError:
     100            return False
     101        if date >= datetime.datetime.now().date():
     102            return False
     103        return True
     104
  • new file django/contrib/localflavor/mk/mk_choices.py

    diff --git a/django/contrib/localflavor/mk/mk_choices.py b/django/contrib/localflavor/mk/mk_choices.py
    new file mode 100644
    index 0000000..c5dffdb
    - +  
     1# -*- coding: utf-8 -*-
     2"""
     3Macedonian municipalities per the reorganization from 2004.
     4"""
     5from django.utils.translation import ugettext_lazy as _
     6
     7MK_MUNICIPALITIES = (
     8    ('AD', _(u'Aerodrom')),
     9    ('AR', _(u'Aračinovo')),
     10    ('BR', _(u'Berovo')),
     11    ('TL', _(u'Bitola')),
     12    ('BG', _(u'Bogdanci')),
     13    ('VJ', _(u'Bogovinje')),
     14    ('BS', _(u'Bosilovo')),
     15    ('BN', _(u'Brvenica')),
     16    ('BU', _(u'Butel')),
     17    ('VA', _(u'Valandovo')),
     18    ('VL', _(u'Vasilevo')),
     19    ('VV', _(u'Vevčani')),
     20    ('VE', _(u'Veles')),
     21    ('NI', _(u'Vinica')),
     22    ('VC', _(u'Vraneštica')),
     23    ('VH', _(u'Vrapčište')),
     24    ('GB', _(u'Gazi Baba')),
     25    ('GV', _(u'Gevgelija')),
     26    ('GT', _(u'Gostivar')),
     27    ('GR', _(u'Gradsko')),
     28    ('DB', _(u'Debar')),
     29    ('DA', _(u'Debarca')),
     30    ('DL', _(u'Delčevo')),
     31    ('DK', _(u'Demir Kapija')),
     32    ('DM', _(u'Demir Hisar')),
     33    ('DE', _(u'Dolneni')),
     34    ('DR', _(u'Drugovo')),
     35    ('GP', _(u'Gjorče Petrov')),
     36    ('ZE', _(u'Želino')),
     37    ('ZA', _(u'Zajas')),
     38    ('ZK', _(u'Zelenikovo')),
     39    ('ZR', _(u'Zrnovci')),
     40    ('IL', _(u'Ilinden')),
     41    ('JG', _(u'Jegunovce')),
     42    ('AV', _(u'Kavadarci')),
     43    ('KB', _(u'Karbinci')),
     44    ('KX', _(u'Karpoš')),
     45    ('VD', _(u'Kisela Voda')),
     46    ('KH', _(u'Kičevo')),
     47    ('KN', _(u'Konče')),
     48    ('OC', _(u'Koćani')),
     49    ('KY', _(u'Kratovo')),
     50    ('KZ', _(u'Kriva Palanka')),
     51    ('KG', _(u'Krivogaštani')),
     52    ('KS', _(u'Kruševo')),
     53    ('UM', _(u'Kumanovo')),
     54    ('LI', _(u'Lipkovo')),
     55    ('LO', _(u'Lozovo')),
     56    ('MR', _(u'Mavrovo i Rostuša')),
     57    ('MK', _(u'Makedonska Kamenica')),
     58    ('MD', _(u'Makedonski Brod')),
     59    ('MG', _(u'Mogila')),
     60    ('NG', _(u'Negotino')),
     61    ('NV', _(u'Novaci')),
     62    ('NS', _(u'Novo Selo')),
     63    ('OS', _(u'Oslomej')),
     64    ('OD', _(u'Ohrid')),
     65    ('PE', _(u'Petrovec')),
     66    ('PH', _(u'Pehčevo')),
     67    ('PN', _(u'Plasnica')),
     68    ('PP', _(u'Prilep')),
     69    ('PT', _(u'Probištip')),
     70    ('RV', _(u'Radoviš')),
     71    ('RN', _(u'Rankovce')),
     72    ('RE', _(u'Resen')),
     73    ('RO', _(u'Rosoman')),
     74    ('AJ', _(u'Saraj')),
     75    ('SL', _(u'Sveti Nikole')),
     76    ('SS', _(u'Sopište')),
     77    ('SD', _(u'Star Dojran')),
     78    ('NA', _(u'Staro Nagoričane')),
     79    ('UG', _(u'Struga')),
     80    ('RU', _(u'Strumica')),
     81    ('SU', _(u'Studeničani')),
     82    ('TR', _(u'Tearce')),
     83    ('ET', _(u'Tetovo')),
     84    ('CE', _(u'Centar')),
     85    ('CZ', _(u'Centar-Župa')),
     86    ('CI', _(u'Čair')),
     87    ('CA', _(u'Čaška')),
     88    ('CH', _(u'Češinovo-Obleševo')),
     89    ('CS', _(u'Čučer-Sandevo')),
     90    ('ST', _(u'Štip')),
     91    ('SO', _(u'Šuto Orizari')),
     92)
     93
  • new file django/contrib/localflavor/mk/models.py

    diff --git a/django/contrib/localflavor/mk/models.py b/django/contrib/localflavor/mk/models.py
    new file mode 100644
    index 0000000..c64881e
    - +  
     1from django.db.models.fields import CharField
     2from django.utils.translation import ugettext_lazy as _
     3from django.contrib.localflavor.mk.mk_choices import MK_MUNICIPALITIES
     4
     5
     6class MKIdentityCardNumberField(CharField):
     7
     8    description = _("Macedonian identity card number")
     9
     10    def __init__(self, *args, **kwargs):
     11        kwargs['max_length'] = 8
     12        super(MKIdentityCardNumberField, self).__init__(*args, **kwargs)
     13
     14    def formfield(self, **kwargs):
     15        from django.contrib.localflavor.mk.forms import MKIdentityCardNumberField as FormField
     16        defaults = {'form_class' : FormField}
     17        defaults.update(kwargs)
     18        return super(MKIdentityCardNumberField, self).formfield(**defaults)
     19
     20
     21class MKMunicipalityField(CharField):
     22
     23    description = _("A Macedonian municipality (2 character code)")
     24
     25    def __init__(self, *args, **kwargs):
     26        kwargs['choices'] = MK_MUNICIPALITIES
     27        kwargs['max_length'] = 2
     28        super(MKMunicipalityField, self).__init__(*args, **kwargs)
     29
     30
     31class UMCNField(CharField):
     32
     33    description = _("Unique master citizen number (13 digits)")
     34
     35    def __init__(self, *args, **kwargs):
     36        kwargs['max_length'] = 13
     37        super(UMCNField, self).__init__(*args, **kwargs)
     38
     39    def formfield(self, **kwargs):
     40        from django.contrib.localflavor.mk.forms import UMCNField as FormField
     41        defaults = {'form_class' : FormField}
     42        defaults.update(kwargs)
     43        return super(UMCNField, self).formfield(**defaults)
  • docs/ref/contrib/localflavor.txt

    diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt
    index f27f57c..eb07589 100644
    a b Countries currently supported by :mod:`~django.contrib.localflavor` are: 
    5757    * Italy_
    5858    * Japan_
    5959    * Kuwait_
     60    * Macedonia_
    6061    * Mexico_
    6162    * `The Netherlands`_
    6263    * Norway_
    Here's an example of how to use them:: 
    110111.. _Italy: `Italy (it)`_
    111112.. _Japan: `Japan (jp)`_
    112113.. _Kuwait: `Kuwait (kw)`_
     114.. _Macedonia: `Macedonia (mk)`_
    113115.. _Mexico: `Mexico (mx)`_
    114116.. _Norway: `Norway (no)`_
    115117.. _Peru: `Peru (pe)`_
    Kuwait (``kw``) 
    694696    * The birthdate of the person is a valid date.
    695697    * The calculated checksum equals to the last digit of the Civil ID.
    696698
     699
     700Macedonia (``mk``)
     701===================
     702
     703.. class:: mk.forms.MKIdentityCardNumberField
     704   
     705    A form field that validates input as a Macedonian identity card number.
     706    Both old and new identity card numbers are supported.
     707
     708
     709.. class:: mk.forms.MKMunicipalitySelect
     710
     711    A form ``Select`` widget that uses a list of Macedonian municipalities as
     712    choices.
     713
     714
     715.. class:: mk.forms.UMCNField
     716
     717    A form field that validates input as a unique master citizen
     718    number.
     719
     720    The format of the unique master citizen number is not unique
     721    to Macedonia. For more information see: 
     722    https://secure.wikimedia.org/wikipedia/en/wiki/Unique_Master_Citizen_Number
     723
     724    A value will pass validation if it complies to the following rules:
     725
     726    * Consists of exactly 13 digits
     727    * The first 7 digits represent a valid past date in the format DDMMYYY
     728    * The last digit of the UMCN passes a checksum test
     729
     730
     731.. class:: mk.models.MKIdentityCardNumberField
     732
     733   A model field that forms represent as a
     734   ``forms.MKIdentityCardNumberField`` field.
     735
     736
     737.. class:: mk.models.MKMunicipalityField
     738
     739   A model field that forms represent as a
     740   ``forms.MKMunicipalitySelect`` and stores the 2 character code of the
     741   municipality in the database.
     742
     743
     744.. class:: mk.models.UMCNField
     745
     746   A model field that forms represent as a ``forms.UMCNField`` field.
     747
     748
    697749Mexico (``mx``)
    698750===============
    699751
  • new file tests/regressiontests/forms/localflavor/mk.py

    diff --git a/tests/regressiontests/forms/localflavor/mk.py b/tests/regressiontests/forms/localflavor/mk.py
    new file mode 100644
    index 0000000..029236e
    - +  
     1from django.contrib.localflavor.mk.forms import ( MKIdentityCardNumberField,
     2                                                  MKMunicipalitySelect,
     3                                                  UMCNField, )
     4from utils import LocalFlavorTestCase
     5
     6
     7class MKLocalFlavorTests(LocalFlavorTestCase):
     8
     9    def test_MKIdentityCardNumberField(self):
     10        error_invalid  =u'Identity card numbers must contain'\
     11            ' either 4 to 7 digits or an uppercase letter and 7 digits.'
     12
     13        valid = {
     14                'L0018077':'L0018077',
     15                'A0078315' : 'A0078315',
     16                }
     17
     18        invalid = {
     19                '123': error_invalid,
     20                'abcdf': error_invalid,
     21                '234390a': error_invalid,
     22                }
     23       
     24        self.assertFieldOutput(MKIdentityCardNumberField, valid, invalid)
     25
     26   
     27    def test_MKMunicipalitySelect(self):
     28        f = MKMunicipalitySelect()
     29        out=u'''<select name="municipality">
     30<option value="AD">Aerodrom</option>
     31<option value="AR">Ara\u010dinovo</option>
     32<option value="BR">Berovo</option>
     33<option value="TL">Bitola</option>
     34<option value="BG">Bogdanci</option>
     35<option value="VJ">Bogovinje</option>
     36<option value="BS">Bosilovo</option>
     37<option value="BN">Brvenica</option>
     38<option value="BU">Butel</option>
     39<option value="VA">Valandovo</option>
     40<option value="VL">Vasilevo</option>
     41<option value="VV">Vev\u010dani</option>
     42<option value="VE">Veles</option>
     43<option value="NI">Vinica</option>
     44<option value="VC">Vrane\u0161tica</option>
     45<option value="VH">Vrap\u010di\u0161te</option>
     46<option value="GB">Gazi Baba</option>
     47<option value="GV">Gevgelija</option>
     48<option value="GT">Gostivar</option>
     49<option value="GR">Gradsko</option>
     50<option value="DB">Debar</option>
     51<option value="DA">Debarca</option>
     52<option value="DL" selected="selected">Del\u010devo</option>
     53<option value="DK">Demir Kapija</option>
     54<option value="DM">Demir Hisar</option>
     55<option value="DE">Dolneni</option>
     56<option value="DR">Drugovo</option>
     57<option value="GP">Gjor\u010de Petrov</option>
     58<option value="ZE">\u017delino</option>
     59<option value="ZA">Zajas</option>
     60<option value="ZK">Zelenikovo</option>
     61<option value="ZR">Zrnovci</option>
     62<option value="IL">Ilinden</option>
     63<option value="JG">Jegunovce</option>
     64<option value="AV">Kavadarci</option>
     65<option value="KB">Karbinci</option>
     66<option value="KX">Karpo\u0161</option>
     67<option value="VD">Kisela Voda</option>
     68<option value="KH">Ki\u010devo</option>
     69<option value="KN">Kon\u010de</option>
     70<option value="OC">Ko\u0107ani</option>
     71<option value="KY">Kratovo</option>
     72<option value="KZ">Kriva Palanka</option>
     73<option value="KG">Krivoga\u0161tani</option>
     74<option value="KS">Kru\u0161evo</option>
     75<option value="UM">Kumanovo</option>
     76<option value="LI">Lipkovo</option>
     77<option value="LO">Lozovo</option>
     78<option value="MR">Mavrovo i Rostu\u0161a</option>
     79<option value="MK">Makedonska Kamenica</option>
     80<option value="MD">Makedonski Brod</option>
     81<option value="MG">Mogila</option>
     82<option value="NG">Negotino</option>
     83<option value="NV">Novaci</option>
     84<option value="NS">Novo Selo</option>
     85<option value="OS">Oslomej</option>
     86<option value="OD">Ohrid</option>
     87<option value="PE">Petrovec</option>
     88<option value="PH">Peh\u010devo</option>
     89<option value="PN">Plasnica</option>
     90<option value="PP">Prilep</option>
     91<option value="PT">Probi\u0161tip</option>
     92<option value="RV">Radovi\u0161</option>
     93<option value="RN">Rankovce</option>
     94<option value="RE">Resen</option>
     95<option value="RO">Rosoman</option>
     96<option value="AJ">Saraj</option>
     97<option value="SL">Sveti Nikole</option>
     98<option value="SS">Sopi\u0161te</option>
     99<option value="SD">Star Dojran</option>
     100<option value="NA">Staro Nagori\u010dane</option>
     101<option value="UG">Struga</option>
     102<option value="RU">Strumica</option>
     103<option value="SU">Studeni\u010dani</option>
     104<option value="TR">Tearce</option>
     105<option value="ET">Tetovo</option>
     106<option value="CE">Centar</option>
     107<option value="CZ">Centar-\u017dupa</option>
     108<option value="CI">\u010cair</option>
     109<option value="CA">\u010ca\u0161ka</option>
     110<option value="CH">\u010ce\u0161inovo-Oble\u0161evo</option>
     111<option value="CS">\u010cu\u010der-Sandevo</option>
     112<option value="ST">\u0160tip</option>
     113<option value="SO">\u0160uto Orizari</option>
     114</select>'''
     115       
     116        self.assertEqual( f.render('municipality', 'DL' ), out)
     117       
     118    def test_UMCNField(self):
     119        error_invalid = [u'This field should contain exactly 13 digits.']
     120        error_checksum = [u'The UMCN is not valid.']
     121        error_date =  [u'The first 7 digits of the UMCN'\
     122                           ' must represent a valid past date.']
     123        valid = {
     124            '2402983450006': '2402983450006',
     125            '2803984430038': '2803984430038',
     126            '1909982045004': '1909982045004',
     127             }
     128
     129        invalid = {
     130            '240298345': error_invalid,
     131            'abcdefghj': error_invalid,
     132            '2402082450006': error_date,
     133            '3002982450006': error_date,
     134            '2402983450007': error_checksum,
     135            '2402982450006': error_checksum,
     136        }
     137       
     138        self.assertFieldOutput(UMCNField, valid, invalid)
     139       
     140
     141
     142
     143
  • tests/regressiontests/forms/localflavortests.py

    diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py
    index 73f46a7..68717ca 100644
    a b from localflavor.is_ import ISLocalFlavorTests 
    2121from localflavor.it import ITLocalFlavorTests
    2222from localflavor.jp import JPLocalFlavorTests
    2323from localflavor.kw import KWLocalFlavorTests
     24from localflavor.mk import MKLocalFlavorTests
    2425from localflavor.nl import NLLocalFlavorTests
    2526from localflavor.pl import PLLocalFlavorTests
    2627from localflavor.pt import PTLocalFlavorTests
  • tests/regressiontests/forms/tests/__init__.py

    diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py
    index 2d8f9e9..dfce783 100644
    a b from regressiontests.forms.localflavortests import ( 
    3535    ITLocalFlavorTests,
    3636    JPLocalFlavorTests,
    3737    KWLocalFlavorTests,
     38    MKLocalFlavorTests,
    3839    NLLocalFlavorTests,
    3940    PLLocalFlavorTests,
    4041    PTLocalFlavorTests,
  • new file tests/regressiontests/localflavor/mk/forms.py

    diff --git a/tests/regressiontests/localflavor/mk/__init__.py b/tests/regressiontests/localflavor/mk/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/localflavor/mk/forms.py b/tests/regressiontests/localflavor/mk/forms.py
    new file mode 100644
    index 0000000..4b743bf
    - +  
     1from django.forms import ModelForm
     2from models import MKPerson
     3
     4class MKPersonForm(ModelForm):
     5   
     6    class Meta:
     7        model = MKPerson
  • new file tests/regressiontests/localflavor/mk/models.py

    diff --git a/tests/regressiontests/localflavor/mk/models.py b/tests/regressiontests/localflavor/mk/models.py
    new file mode 100644
    index 0000000..2ef703d
    - +  
     1from django.db import models
     2from django.contrib.localflavor.mk.models import (MKIdentityCardNumberField,
     3                                                  MKMunicipalityField,
     4                                                  UMCNField)
     5
     6class MKPerson(models.Model):
     7    first_name = models.CharField(max_length = 20)
     8    last_name = models.CharField(max_length = 20)
     9    umcn = UMCNField()
     10    id_number = MKIdentityCardNumberField()
     11    municipality  = MKMunicipalityField(blank = True)
     12    municipality_req = MKMunicipalityField(blank = False)
     13
     14    class Meta:
     15        app_label = 'localflavor'
  • new file tests/regressiontests/localflavor/mk/tests.py

    diff --git a/tests/regressiontests/localflavor/mk/tests.py b/tests/regressiontests/localflavor/mk/tests.py
    new file mode 100644
    index 0000000..d4742b8
    - +  
     1from django.test import TestCase
     2from forms import MKPersonForm
     3
     4class MKLocalflavorTests(TestCase):
     5    def setUp(self):
     6        self.form = MKPersonForm({'first_name':'Someone',
     7                                  'last_name':'Something',
     8                                  'umcn': '2402983450006',
     9                                  'municipality':'OD',
     10                                  'municipality_req':'VE',
     11                                  'id_number':'A1234567'})
     12
     13       
     14    def test_get_display_methods(self):
     15        """Test that the get_*_display() methods are added to the model instances."""
     16
     17        person = self.form.save()
     18        self.assertEqual(person.get_municipality_display(), 'Ohrid')
     19        self.assertEqual(person.get_municipality_req_display(), 'Veles')
     20
     21       
     22    def test_municipality_required(self):
     23        """Test that required MKMunicipalityFields throw appropriate errors."""
     24
     25        form = MKPersonForm({'first_name':'Someone',
     26                             'last_name':'Something',
     27                             'umcn': '2402983450006',
     28                             'municipality':'OD',
     29                             'id_number':'A1234567'})
     30       
     31        self.assertFalse(form.is_valid())
     32        self.assertEqual(form.errors['municipality_req'], [u'This field is required.'])
     33
     34       
     35    def test_umcn_invalid(self):
     36        """Test that UMCNFields throw appropriate errors for invalid UMCNs"""
     37
     38        form = MKPersonForm({'first_name':'Someone',
     39                             'last_name':'Something',
     40                             'umcn': '2402983450007',
     41                             'municipality':'OD',
     42                             'municipality_req':'VE',
     43                             'id_number':'A1234567'})
     44       
     45        self.assertFalse(form.is_valid())
     46        self.assertEqual(form.errors['umcn'], [u'The UMCN is not valid.'])
     47
     48        form = MKPersonForm({'first_name':'Someone',
     49                             'last_name':'Something',
     50                             'umcn': '3002983450007',
     51                             'municipality':'OD',
     52                             'municipality_req':'VE',
     53                             'id_number':'A1234567'})
     54
     55        self.assertEqual(form.errors['umcn'],\
     56                [u'The first 7 digits of the UMCN must represent a valid past date.'])
     57
     58       
     59    def test_idnumber_invalid(self):
     60        """Test that MKIdentityCardNumberFields throw appropriate errors for invalid values"""
     61
     62        form = MKPersonForm({'first_name':'Someone',
     63                             'last_name':'Something',
     64                             'umcn': '2402983450007',
     65                             'municipality':'OD',
     66                             'municipality_req':'VE',
     67                             'id_number':'A123456a'})
     68       
     69        self.assertFalse(form.is_valid())
     70        self.assertEqual(form.errors['id_number'],\
     71                         [u'Identity card numbers must contain'\
     72                              ' either 4 to 7 digits or an uppercase letter and 7 digits.'])
     73       
     74   
     75       
     76    def test_field_blank_option(self):
     77        """Test that the empty option is there."""
     78
     79        municipality_select_html="""<select name="municipality" id="id_municipality">
     80<option value="">---------</option>
     81<option value="AD">Aerodrom</option>
     82<option value="AR">Ara\xc4\x8dinovo</option>
     83<option value="BR">Berovo</option>
     84<option value="TL">Bitola</option>
     85<option value="BG">Bogdanci</option>
     86<option value="VJ">Bogovinje</option>
     87<option value="BS">Bosilovo</option>
     88<option value="BN">Brvenica</option>
     89<option value="BU">Butel</option>
     90<option value="VA">Valandovo</option>
     91<option value="VL">Vasilevo</option>
     92<option value="VV">Vev\xc4\x8dani</option>
     93<option value="VE">Veles</option>
     94<option value="NI">Vinica</option>
     95<option value="VC">Vrane\xc5\xa1tica</option>
     96<option value="VH">Vrap\xc4\x8di\xc5\xa1te</option>
     97<option value="GB">Gazi Baba</option>
     98<option value="GV">Gevgelija</option>
     99<option value="GT">Gostivar</option>
     100<option value="GR">Gradsko</option>
     101<option value="DB">Debar</option>
     102<option value="DA">Debarca</option>
     103<option value="DL">Del\xc4\x8devo</option>
     104<option value="DK">Demir Kapija</option>
     105<option value="DM">Demir Hisar</option>
     106<option value="DE">Dolneni</option>
     107<option value="DR">Drugovo</option>
     108<option value="GP">Gjor\xc4\x8de Petrov</option>
     109<option value="ZE">\xc5\xbdelino</option>
     110<option value="ZA">Zajas</option>
     111<option value="ZK">Zelenikovo</option>
     112<option value="ZR">Zrnovci</option>
     113<option value="IL">Ilinden</option>
     114<option value="JG">Jegunovce</option>
     115<option value="AV">Kavadarci</option>
     116<option value="KB">Karbinci</option>
     117<option value="KX">Karpo\xc5\xa1</option>
     118<option value="VD">Kisela Voda</option>
     119<option value="KH">Ki\xc4\x8devo</option>
     120<option value="KN">Kon\xc4\x8de</option>
     121<option value="OC">Ko\xc4\x87ani</option>
     122<option value="KY">Kratovo</option>
     123<option value="KZ">Kriva Palanka</option>
     124<option value="KG">Krivoga\xc5\xa1tani</option>
     125<option value="KS">Kru\xc5\xa1evo</option>
     126<option value="UM">Kumanovo</option>
     127<option value="LI">Lipkovo</option>
     128<option value="LO">Lozovo</option>
     129<option value="MR">Mavrovo i Rostu\xc5\xa1a</option>
     130<option value="MK">Makedonska Kamenica</option>
     131<option value="MD">Makedonski Brod</option>
     132<option value="MG">Mogila</option>
     133<option value="NG">Negotino</option>
     134<option value="NV">Novaci</option>
     135<option value="NS">Novo Selo</option>
     136<option value="OS">Oslomej</option>
     137<option value="OD" selected="selected">Ohrid</option>
     138<option value="PE">Petrovec</option>
     139<option value="PH">Peh\xc4\x8devo</option>
     140<option value="PN">Plasnica</option>
     141<option value="PP">Prilep</option>
     142<option value="PT">Probi\xc5\xa1tip</option>
     143<option value="RV">Radovi\xc5\xa1</option>
     144<option value="RN">Rankovce</option>
     145<option value="RE">Resen</option>
     146<option value="RO">Rosoman</option>
     147<option value="AJ">Saraj</option>
     148<option value="SL">Sveti Nikole</option>
     149<option value="SS">Sopi\xc5\xa1te</option>
     150<option value="SD">Star Dojran</option>
     151<option value="NA">Staro Nagori\xc4\x8dane</option>
     152<option value="UG">Struga</option>
     153<option value="RU">Strumica</option>
     154<option value="SU">Studeni\xc4\x8dani</option>
     155<option value="TR">Tearce</option>
     156<option value="ET">Tetovo</option>
     157<option value="CE">Centar</option>
     158<option value="CZ">Centar-\xc5\xbdupa</option>
     159<option value="CI">\xc4\x8cair</option>
     160<option value="CA">\xc4\x8ca\xc5\xa1ka</option>
     161<option value="CH">\xc4\x8ce\xc5\xa1inovo-Oble\xc5\xa1evo</option>
     162<option value="CS">\xc4\x8cu\xc4\x8der-Sandevo</option>
     163<option value="ST">\xc5\xa0tip</option>
     164<option value="SO">\xc5\xa0uto Orizari</option>
     165</select>"""
     166
     167       
     168        self.assertEqual(str(self.form['municipality']), municipality_select_html)
     169
  • tests/regressiontests/localflavor/tests.py

    diff --git a/tests/regressiontests/localflavor/tests.py b/tests/regressiontests/localflavor/tests.py
    index e22fc0f..6a02d99 100644
    a b from django.test import TestCase 
    22from django.utils import unittest
    33
    44# just import your tests here
    5 from us.tests import *
    65from au.tests import *
     6from mk.tests import *
     7from us.tests import *
     8
Back to Top