PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/tr.py

https://code.google.com/p/mango-py/
Python | 73 lines | 68 code | 4 blank | 1 comment | 0 complexity | 3704c5b7a5e1aadb8bc4db05ad3d4462 MD5 | raw file
 1# Tests for the contrib/localflavor/ TR form fields.
 2
 3from django.contrib.localflavor.tr import forms as trforms
 4from django.core.exceptions import ValidationError
 5from django.utils.unittest import TestCase
 6
 7class TRLocalFlavorTests(TestCase):
 8    def test_TRPostalCodeField(self):
 9        f = trforms.TRPostalCodeField()
10        self.assertEqual(f.clean("06531"), "06531")
11        self.assertEqual(f.clean("12345"), "12345")
12        self.assertRaisesRegexp(ValidationError,
13            "Enter a postal code in the format XXXXX.",
14            f.clean, "a1234")
15        self.assertRaisesRegexp(ValidationError,
16            "Enter a postal code in the format XXXXX.",
17            f.clean, "1234")
18        self.assertRaisesRegexp(ValidationError,
19            "Enter a postal code in the format XXXXX.",
20            f.clean, "82123")
21        self.assertRaisesRegexp(ValidationError,
22            "Enter a postal code in the format XXXXX.",
23            f.clean, "00123")
24        self.assertRaisesRegexp(ValidationError,
25            "Enter a postal code in the format XXXXX.",
26            f.clean, "123456")
27        self.assertRaisesRegexp(ValidationError,
28            "Enter a postal code in the format XXXXX.",
29            f.clean, "12 34")
30        self.assertRaises(ValidationError, f.clean, None)
31
32    def test_TRPhoneNumberField(self):
33        f = trforms.TRPhoneNumberField()
34        self.assertEqual(f.clean("312 455 56 78"), "3124555678")
35        self.assertEqual(f.clean("312 4555678"), "3124555678")
36        self.assertEqual(f.clean("3124555678"), "3124555678")
37        self.assertEqual(f.clean("0312 455 5678"), "3124555678")
38        self.assertEqual(f.clean("0 312 455 5678"), "3124555678")
39        self.assertEqual(f.clean("0 (312) 455 5678"), "3124555678")
40        self.assertEqual(f.clean("+90 312 455 4567"), "3124554567")
41        self.assertEqual(f.clean("+90 312 455 45 67"), "3124554567")
42        self.assertEqual(f.clean("+90 (312) 4554567"), "3124554567")
43        self.assertRaisesRegexp(ValidationError,
44            'Phone numbers must be in 0XXX XXX XXXX format.',
45            f.clean, "1234 233 1234")
46        self.assertRaisesRegexp(ValidationError,
47            'Phone numbers must be in 0XXX XXX XXXX format.',
48            f.clean, "0312 233 12345")
49        self.assertRaisesRegexp(ValidationError,
50            'Phone numbers must be in 0XXX XXX XXXX format.',
51            f.clean, "0312 233 123")
52        self.assertRaisesRegexp(ValidationError,
53            'Phone numbers must be in 0XXX XXX XXXX format.',
54            f.clean, "0312 233 xxxx")
55
56    def test_TRIdentificationNumberField(self):
57        f = trforms.TRIdentificationNumberField()
58        self.assertEqual(f.clean("10000000146"), "10000000146")
59        self.assertRaisesRegexp(ValidationError,
60            'Enter a valid Turkish Identification number.',
61            f.clean, "10000000136")
62        self.assertRaisesRegexp(ValidationError,
63            'Enter a valid Turkish Identification number.',
64            f.clean, "10000000147")
65        self.assertRaisesRegexp(ValidationError,
66            'Turkish Identification number must be 11 digits.',
67            f.clean, "123456789")
68        self.assertRaisesRegexp(ValidationError,
69            'Enter a valid Turkish Identification number.',
70            f.clean, "1000000014x")
71        self.assertRaisesRegexp(ValidationError,
72            'Enter a valid Turkish Identification number.',
73            f.clean, "x0000000146")