| 1 | # -*- coding: utf-8 -*- |
| 2 | # Tests for the contrib/localflavor/ NZ form fields. |
| 3 | |
| 4 | tests = r""" |
| 5 | ## NZPostCodeField ########################################################## |
| 6 | |
| 7 | A field that accepts a four digit New Zealand post code. |
| 8 | |
| 9 | >>> from django.contrib.localflavor.nz.forms import NZPostCodeField |
| 10 | >>> f = NZPostCodeField() |
| 11 | >>> f.clean('1234') |
| 12 | u'1234' |
| 13 | >>> f.clean('2000') |
| 14 | u'2000' |
| 15 | >>> f.clean('abcd') |
| 16 | Traceback (most recent call last): |
| 17 | ... |
| 18 | ValidationError: [u'Enter a 4 digit post code.'] |
| 19 | >>> f.clean('20001') |
| 20 | Traceback (most recent call last): |
| 21 | ... |
| 22 | ValidationError: [u'Enter a 4 digit post code.'] |
| 23 | >>> f.clean(None) |
| 24 | Traceback (most recent call last): |
| 25 | ... |
| 26 | ValidationError: [u'This field is required.'] |
| 27 | >>> f.clean('') |
| 28 | Traceback (most recent call last): |
| 29 | ... |
| 30 | ValidationError: [u'This field is required.'] |
| 31 | |
| 32 | >>> f = NZPostCodeField(required=False) |
| 33 | >>> f.clean('1234') |
| 34 | u'1234' |
| 35 | >>> f.clean('2000') |
| 36 | u'2000' |
| 37 | >>> f.clean('abcd') |
| 38 | Traceback (most recent call last): |
| 39 | ... |
| 40 | ValidationError: [u'Enter a 4 digit post code.'] |
| 41 | >>> f.clean('20001') |
| 42 | Traceback (most recent call last): |
| 43 | ... |
| 44 | ValidationError: [u'Enter a 4 digit post code.'] |
| 45 | >>> f.clean(None) |
| 46 | u'' |
| 47 | >>> f.clean('') |
| 48 | u'' |
| 49 | |
| 50 | ## NZPhoneNumberField ######################################################## |
| 51 | |
| 52 | A field that accepts a 9 digit New Zealand phone number, or a 8-10 digit |
| 53 | New Zealand mobile phone number (starting with 02). |
| 54 | Allows spaces and parentheses around area code. |
| 55 | |
| 56 | >>> from django.contrib.localflavor.nz.forms import NZPhoneNumberField |
| 57 | >>> f = NZPhoneNumberField() |
| 58 | >>> f.clean('012345678') |
| 59 | u'012345678' |
| 60 | >>> f.clean('0213456789') |
| 61 | u'0213456789' |
| 62 | >>> f.clean('02 13 45 67 8') |
| 63 | u'021345678' |
| 64 | >>> f.clean('(02) 1345 6789') |
| 65 | u'0213456789' |
| 66 | >>> f.clean('(02) 1345-6789') |
| 67 | u'0213456789' |
| 68 | >>> f.clean('(02)1345-6789') |
| 69 | u'0213456789' |
| 70 | >>> f.clean('0228 123 45') |
| 71 | u'022812345' |
| 72 | >>> f.clean('123') |
| 73 | Traceback (most recent call last): |
| 74 | ... |
| 75 | ValidationError: [u'Phone numbers must contain 9 digits (including area code), unless they are mobile numbers (02, then 7-9 digits).'] |
| 76 | >>> f.clean('1800DJANGO') |
| 77 | Traceback (most recent call last): |
| 78 | ... |
| 79 | ValidationError: [u'Phone numbers must contain 9 digits (including area code), unless they are mobile numbers (02, then 7-9 digits).'] |
| 80 | >>> f.clean(None) |
| 81 | Traceback (most recent call last): |
| 82 | ... |
| 83 | ValidationError: [u'This field is required.'] |
| 84 | >>> f.clean('') |
| 85 | Traceback (most recent call last): |
| 86 | ... |
| 87 | ValidationError: [u'This field is required.'] |
| 88 | |
| 89 | >>> f = NZPhoneNumberField(required=False) |
| 90 | >>> f.clean('1234567890') |
| 91 | Traceback (most recent call last): |
| 92 | ... |
| 93 | ValidationError: [u'Phone numbers must contain 9 digits (including area code), unless they are mobile numbers (02, then 7-9 digits).'] |
| 94 | >>> f.clean('0213456789') |
| 95 | u'0213456789' |
| 96 | >>> f.clean('02 13 45 67 89') |
| 97 | u'0213456789' |
| 98 | >>> f.clean('(02) 1345 6789') |
| 99 | u'0213456789' |
| 100 | >>> f.clean('(02) 1345-6789') |
| 101 | u'0213456789' |
| 102 | >>> f.clean('(02)1345-6789') |
| 103 | u'0213456789' |
| 104 | >>> f.clean('0408 123 456') |
| 105 | Traceback (most recent call last): |
| 106 | ... |
| 107 | ValidationError: [u'Phone numbers must contain 9 digits (including area code), unless they are mobile numbers (02, then 7-9 digits).'] |
| 108 | |
| 109 | >>> f.clean('123') |
| 110 | Traceback (most recent call last): |
| 111 | ... |
| 112 | ValidationError: [u'Phone numbers must contain 9 digits (including area code), unless they are mobile numbers (02, then 7-9 digits).'] |
| 113 | >>> f.clean('1800DJANGO') |
| 114 | Traceback (most recent call last): |
| 115 | ... |
| 116 | ValidationError: [u'Phone numbers must contain 9 digits (including area code), unless they are mobile numbers (02, then 7-9 digits).'] |
| 117 | >>> f.clean(None) |
| 118 | u'' |
| 119 | >>> f.clean('') |
| 120 | u'' |
| 121 | |
| 122 | |
| 123 | ## NZStateSelect ############################################################# |
| 124 | |
| 125 | NZProvincialDistrictSelect is a Select widget that uses a list of New Zealand |
| 126 | provincial districts as its choices. |
| 127 | |
| 128 | >>> from django.contrib.localflavor.nz.forms import NZProvincialDistrictSelect |
| 129 | >>> f = NZProvincialDistrictSelect() |
| 130 | >>> print f.render('provincial_district', 'Wellington') |
| 131 | <select name="provincial_district"> |
| 132 | <option value="Auckland">Auckland Province</option> |
| 133 | <option value="Canterbury">Canterbury</option> |
| 134 | <option value="Chatham">Chatham Islands</option> |
| 135 | <option value="HawkesBay">Hawke's Bay</option> |
| 136 | <option value="Marlborough">Marlborough</option> |
| 137 | <option value="Nelson">Nelson</option> |
| 138 | <option value="Northland">Northland</option> |
| 139 | <option value="Otago">Otago Province</option> |
| 140 | <option value="SouthCanterbury">South Canterbury</option> |
| 141 | <option value="Southland">Southland</option> |
| 142 | <option value="Taranaki">Taranaki (New Plymouth)</option> |
| 143 | <option value="Wellington" selected="selected">Wellington Province</option> |
| 144 | <option value="Westland">Westland</option> |
| 145 | </select> |
| 146 | |
| 147 | """ |
| 148 | No newline at end of file |