From 050e11956f8bf6589e8c93c6ccdbe5fc03e7e410 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 12 Jun 2011 13:31:40 +0000 Subject: Fixed #15856 -- Added Macedonian localflavor. Many thanks to vasiliyeah. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16385 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor/mk.py | 131 +++++++++++++++++ tests/regressiontests/forms/localflavortests.py | 1 + tests/regressiontests/forms/tests/__init__.py | 1 + tests/regressiontests/localflavor/mk/__init__.py | 0 tests/regressiontests/localflavor/mk/forms.py | 7 + tests/regressiontests/localflavor/mk/models.py | 14 ++ tests/regressiontests/localflavor/mk/tests.py | 176 +++++++++++++++++++++++ tests/regressiontests/localflavor/tests.py | 4 +- 8 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 tests/regressiontests/forms/localflavor/mk.py create mode 100644 tests/regressiontests/localflavor/mk/__init__.py create mode 100644 tests/regressiontests/localflavor/mk/forms.py create mode 100644 tests/regressiontests/localflavor/mk/models.py create mode 100644 tests/regressiontests/localflavor/mk/tests.py (limited to 'tests') diff --git a/tests/regressiontests/forms/localflavor/mk.py b/tests/regressiontests/forms/localflavor/mk.py new file mode 100644 index 0000000000..8ef84af384 --- /dev/null +++ b/tests/regressiontests/forms/localflavor/mk.py @@ -0,0 +1,131 @@ +from django.contrib.localflavor.mk.forms import ( + MKIdentityCardNumberField, MKMunicipalitySelect, UMCNField) + +from utils import LocalFlavorTestCase + + +class MKLocalFlavorTests(LocalFlavorTestCase): + + def test_MKIdentityCardNumberField(self): + error_invalid = (u'Identity card numbers must contain' + ' either 4 to 7 digits or an uppercase letter and 7 digits.') + valid = { + 'L0018077':'L0018077', + 'A0078315' : 'A0078315', + } + invalid = { + '123': error_invalid, + 'abcdf': error_invalid, + '234390a': error_invalid, + } + self.assertFieldOutput(MKIdentityCardNumberField, valid, invalid) + + def test_MKMunicipalitySelect(self): + f = MKMunicipalitySelect() + out=u'''''' + self.assertEqual(f.render('municipality', 'DL' ), out) + + def test_UMCNField(self): + error_invalid = [u'This field should contain exactly 13 digits.'] + error_checksum = [u'The UMCN is not valid.'] + error_date = [u'The first 7 digits of the UMCN ' + 'must represent a valid past date.'] + valid = { + '2402983450006': '2402983450006', + '2803984430038': '2803984430038', + '1909982045004': '1909982045004', + } + invalid = { + '240298345': error_invalid, + 'abcdefghj': error_invalid, + '2402082450006': error_date, + '3002982450006': error_date, + '2402983450007': error_checksum, + '2402982450006': error_checksum, + } + self.assertFieldOutput(UMCNField, valid, invalid) diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index e2d5aa65ff..5a28a2b137 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/tests/regressiontests/forms/localflavortests.py @@ -23,6 +23,7 @@ from localflavor.is_ import ISLocalFlavorTests from localflavor.it import ITLocalFlavorTests from localflavor.jp import JPLocalFlavorTests from localflavor.kw import KWLocalFlavorTests +from localflavor.mk import MKLocalFlavorTests from localflavor.nl import NLLocalFlavorTests from localflavor.pl import PLLocalFlavorTests from localflavor.pt import PTLocalFlavorTests diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 39db39f0df..cb5f83cdac 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -36,6 +36,7 @@ from regressiontests.forms.localflavortests import ( ITLocalFlavorTests, JPLocalFlavorTests, KWLocalFlavorTests, + MKLocalFlavorTests, NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests, diff --git a/tests/regressiontests/localflavor/mk/__init__.py b/tests/regressiontests/localflavor/mk/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/localflavor/mk/forms.py b/tests/regressiontests/localflavor/mk/forms.py new file mode 100644 index 0000000000..50fcf05f94 --- /dev/null +++ b/tests/regressiontests/localflavor/mk/forms.py @@ -0,0 +1,7 @@ +from django.forms import ModelForm +from models import MKPerson + +class MKPersonForm(ModelForm): + + class Meta: + model = MKPerson diff --git a/tests/regressiontests/localflavor/mk/models.py b/tests/regressiontests/localflavor/mk/models.py new file mode 100644 index 0000000000..b79239a9bf --- /dev/null +++ b/tests/regressiontests/localflavor/mk/models.py @@ -0,0 +1,14 @@ +from django.db import models +from django.contrib.localflavor.mk.models import ( + MKIdentityCardNumberField, MKMunicipalityField, UMCNField) + +class MKPerson(models.Model): + first_name = models.CharField(max_length = 20) + last_name = models.CharField(max_length = 20) + umcn = UMCNField() + id_number = MKIdentityCardNumberField() + municipality = MKMunicipalityField(blank = True) + municipality_req = MKMunicipalityField(blank = False) + + class Meta: + app_label = 'localflavor' diff --git a/tests/regressiontests/localflavor/mk/tests.py b/tests/regressiontests/localflavor/mk/tests.py new file mode 100644 index 0000000000..f7f2981a85 --- /dev/null +++ b/tests/regressiontests/localflavor/mk/tests.py @@ -0,0 +1,176 @@ +from django.test import TestCase +from forms import MKPersonForm + +class MKLocalflavorTests(TestCase): + def setUp(self): + self.form = MKPersonForm({ + 'first_name':'Someone', + 'last_name':'Something', + 'umcn': '2402983450006', + 'municipality':'OD', + 'municipality_req':'VE', + 'id_number':'A1234567', + }) + + def test_get_display_methods(self): + """ + Test that the get_*_display() methods are added to the model instances. + """ + person = self.form.save() + self.assertEqual(person.get_municipality_display(), 'Ohrid') + self.assertEqual(person.get_municipality_req_display(), 'Veles') + + def test_municipality_required(self): + """ + Test that required MKMunicipalityFields throw appropriate errors. + """ + + form = MKPersonForm({ + 'first_name':'Someone', + 'last_name':'Something', + 'umcn': '2402983450006', + 'municipality':'OD', + 'id_number':'A1234567', + }) + self.assertFalse(form.is_valid()) + self.assertEqual( + form.errors['municipality_req'], [u'This field is required.']) + + def test_umcn_invalid(self): + """ + Test that UMCNFields throw appropriate errors for invalid UMCNs. + """ + form = MKPersonForm({ + 'first_name':'Someone', + 'last_name':'Something', + 'umcn': '2402983450007', + 'municipality':'OD', + 'municipality_req':'VE', + 'id_number':'A1234567', + }) + self.assertFalse(form.is_valid()) + self.assertEqual(form.errors['umcn'], [u'The UMCN is not valid.']) + + form = MKPersonForm({ + 'first_name':'Someone', + 'last_name':'Something', + 'umcn': '3002983450007', + 'municipality':'OD', + 'municipality_req':'VE', + 'id_number':'A1234567', + }) + self.assertEqual(form.errors['umcn'], + [u'The first 7 digits of the UMCN must represent a valid past date.']) + + def test_idnumber_invalid(self): + """ + Test that MKIdentityCardNumberFields throw + appropriate errors for invalid values + """ + + form = MKPersonForm({ + 'first_name':'Someone', + 'last_name':'Something', + 'umcn': '2402983450007', + 'municipality':'OD', + 'municipality_req':'VE', + 'id_number':'A123456a', + }) + self.assertFalse(form.is_valid()) + self.assertEqual(form.errors['id_number'], + [u'Identity card numbers must contain either 4 to 7 ' + 'digits or an uppercase letter and 7 digits.']) + + def test_field_blank_option(self): + """ + Test that the empty option is there. + """ + municipality_select_html = """\ +""" + self.assertEqual(str(self.form['municipality']), municipality_select_html) diff --git a/tests/regressiontests/localflavor/tests.py b/tests/regressiontests/localflavor/tests.py index e22fc0f5be..6a02d99004 100644 --- a/tests/regressiontests/localflavor/tests.py +++ b/tests/regressiontests/localflavor/tests.py @@ -2,5 +2,7 @@ from django.test import TestCase from django.utils import unittest # just import your tests here -from us.tests import * from au.tests import * +from mk.tests import * +from us.tests import * + -- cgit v1.3