diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-08-05 17:15:33 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-08-05 17:15:33 +0000 |
| commit | aa239e3e5405933af6a29dac3cf587b59a099927 (patch) | |
| tree | ea2cbd139c9a8cf84c09e0b2008bff70e05927ef /tests/regressiontests/forms | |
| parent | 45b73c9a4685809236f84046cc7ffd32a50db958 (diff) | |
gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.archive/attic/gis
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@8215 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms')
| -rw-r--r-- | tests/regressiontests/forms/fields.py | 106 | ||||
| -rw-r--r-- | tests/regressiontests/forms/forms.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/forms/formsets.py | 16 | ||||
| -rw-r--r-- | tests/regressiontests/forms/localflavor/at.py | 80 | ||||
| -rw-r--r-- | tests/regressiontests/forms/localflavor/ro.py | 175 | ||||
| -rw-r--r-- | tests/regressiontests/forms/models.py | 19 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests.py | 4 |
7 files changed, 342 insertions, 62 deletions
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py index c70ff2dff3..a9aae4f442 100644 --- a/tests/regressiontests/forms/fields.py +++ b/tests/regressiontests/forms/fields.py @@ -308,18 +308,18 @@ ValidationError: [u'This field is required.'] Traceback (most recent call last): ... ValidationError: [u'This field is required.'] ->>> f.clean('1') -Decimal("1") +>>> f.clean('1') == Decimal("1") +True >>> isinstance(f.clean('1'), Decimal) True ->>> f.clean('23') -Decimal("23") ->>> f.clean('3.14') -Decimal("3.14") ->>> f.clean(3.14) -Decimal("3.14") ->>> f.clean(Decimal('3.14')) -Decimal("3.14") +>>> f.clean('23') == Decimal("23") +True +>>> f.clean('3.14') == Decimal("3.14") +True +>>> f.clean(3.14) == Decimal("3.14") +True +>>> f.clean(Decimal('3.14')) == Decimal("3.14") +True >>> f.clean('a') Traceback (most recent call last): ... @@ -328,12 +328,12 @@ ValidationError: [u'Enter a number.'] Traceback (most recent call last): ... ValidationError: [u'Enter a number.'] ->>> f.clean('1.0 ') -Decimal("1.0") ->>> f.clean(' 1.0') -Decimal("1.0") ->>> f.clean(' 1.0 ') -Decimal("1.0") +>>> f.clean('1.0 ') == Decimal("1.0") +True +>>> f.clean(' 1.0') == Decimal("1.0") +True +>>> f.clean(' 1.0 ') == Decimal("1.0") +True >>> f.clean('1.0a') Traceback (most recent call last): ... @@ -350,18 +350,18 @@ ValidationError: [u'Ensure that there are no more than 2 decimal places.'] Traceback (most recent call last): ... ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.'] ->>> f.clean('-12.34') -Decimal("-12.34") +>>> f.clean('-12.34') == Decimal("-12.34") +True >>> f.clean('-123.45') Traceback (most recent call last): ... ValidationError: [u'Ensure that there are no more than 4 digits in total.'] ->>> f.clean('-.12') -Decimal("-0.12") ->>> f.clean('-00.12') -Decimal("-0.12") ->>> f.clean('-000.12') -Decimal("-0.12") +>>> f.clean('-.12') == Decimal("-0.12") +True +>>> f.clean('-00.12') == Decimal("-0.12") +True +>>> f.clean('-000.12') == Decimal("-0.12") +True >>> f.clean('-000.123') Traceback (most recent call last): ... @@ -380,8 +380,8 @@ ValidationError: [u'Enter a number.'] >>> f.clean(None) ->>> f.clean('1') -Decimal("1") +>>> f.clean('1') == Decimal("1") +True DecimalField accepts min_value and max_value just like IntegerField: >>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) @@ -394,14 +394,14 @@ ValidationError: [u'Ensure this value is less than or equal to 1.5.'] Traceback (most recent call last): ... ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] ->>> f.clean('1.5') -Decimal("1.5") ->>> f.clean('0.5') -Decimal("0.5") ->>> f.clean('.5') -Decimal("0.5") ->>> f.clean('00.50') -Decimal("0.50") +>>> f.clean('1.5') == Decimal("1.5") +True +>>> f.clean('0.5') == Decimal("0.5") +True +>>> f.clean('.5') == Decimal("0.5") +True +>>> f.clean('00.50') == Decimal("0.50") +True # DateField ################################################################### @@ -802,6 +802,9 @@ ValidationError: [u'The submitted file is empty.'] >>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'))) <class 'django.core.files.uploadedfile.SimpleUploadedFile'> +>>> type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह'))) +<class 'django.core.files.uploadedfile.SimpleUploadedFile'> + >>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf')) <class 'django.core.files.uploadedfile.SimpleUploadedFile'> @@ -817,15 +820,15 @@ Traceback (most recent call last): ... ValidationError: [u'This field is required.'] >>> f.clean('http://localhost') -u'http://localhost' +u'http://localhost/' >>> f.clean('http://example.com') -u'http://example.com' +u'http://example.com/' >>> f.clean('http://www.example.com') -u'http://www.example.com' +u'http://www.example.com/' >>> f.clean('http://www.example.com:8000/test') u'http://www.example.com:8000/test' >>> f.clean('http://200.8.9.10') -u'http://200.8.9.10' +u'http://200.8.9.10/' >>> f.clean('http://200.8.9.10:8000/test') u'http://200.8.9.10:8000/test' >>> f.clean('foo') @@ -855,9 +858,9 @@ u'' >>> f.clean(None) u'' >>> f.clean('http://example.com') -u'http://example.com' +u'http://example.com/' >>> f.clean('http://www.example.com') -u'http://www.example.com' +u'http://www.example.com/' >>> f.clean('foo') Traceback (most recent call last): ... @@ -883,7 +886,7 @@ URLField takes an optional verify_exists parameter, which is False by default. This verifies that the URL is live on the Internet and doesn't return a 404 or 500: >>> f = URLField(verify_exists=True) >>> f.clean('http://www.google.com') # This will fail if there's no Internet connection -u'http://www.google.com' +u'http://www.google.com/' >>> f.clean('http://example') Traceback (most recent call last): ... @@ -900,29 +903,38 @@ ValidationError: [u'This URL appears to be a broken link.'] >>> f.clean('') u'' >>> f.clean('http://www.google.com') # This will fail if there's no Internet connection -u'http://www.google.com' +u'http://www.google.com/' URLField also access min_length and max_length parameters, for convenience. >>> f = URLField(min_length=15, max_length=20) >>> f.clean('http://f.com') Traceback (most recent call last): ... -ValidationError: [u'Ensure this value has at least 15 characters (it has 12).'] +ValidationError: [u'Ensure this value has at least 15 characters (it has 13).'] >>> f.clean('http://example.com') -u'http://example.com' +u'http://example.com/' >>> f.clean('http://abcdefghijklmnopqrstuvwxyz.com') Traceback (most recent call last): ... -ValidationError: [u'Ensure this value has at most 20 characters (it has 37).'] +ValidationError: [u'Ensure this value has at most 20 characters (it has 38).'] URLField should prepend 'http://' if no scheme was given >>> f = URLField(required=False) >>> f.clean('example.com') -u'http://example.com' +u'http://example.com/' >>> f.clean('') u'' >>> f.clean('https://example.com') -u'https://example.com' +u'https://example.com/' + +URLField should append '/' if no path was given +>>> f = URLField() +>>> f.clean('http://example.com') +u'http://example.com/' + +URLField shouldn't change the path if it was given +>>> f.clean('http://example.com/test') +u'http://example.com/test' # BooleanField ################################################################ diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py index 6e6e4f79bf..d834bdaccc 100644 --- a/tests/regressiontests/forms/forms.py +++ b/tests/regressiontests/forms/forms.py @@ -1480,6 +1480,10 @@ not request.POST. >>> f.is_valid() True +>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')}, auto_id=False) +>>> print f +<tr><th>File1:</th><td><input type="file" name="file1" /></td></tr> + # Basic form processing in a view ############################################# >>> from django.template import Template, Context diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py index bbbd4cee5a..4fd0c17032 100644 --- a/tests/regressiontests/forms/formsets.py +++ b/tests/regressiontests/forms/formsets.py @@ -20,7 +20,7 @@ but we'll look at how to do so later. >>> formset = ChoiceFormSet(auto_id=False, prefix='choices') >>> print formset -<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_FORMS" value="0" /> +<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /> <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" /></td></tr> <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" /></td></tr> @@ -34,7 +34,6 @@ the TOTAL_FORMS field appropriately. >>> data = { ... 'choices-TOTAL_FORMS': '1', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... } @@ -61,7 +60,6 @@ any of the forms. >>> data = { ... 'choices-TOTAL_FORMS': '1', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '', ... } @@ -92,7 +90,6 @@ Let's simulate what would happen if we submitted this form. >>> data = { ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': '', @@ -114,7 +111,6 @@ handle that later. >>> data = { ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': 'The Decemberists', @@ -134,7 +130,6 @@ handle that case later. >>> data = { ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': '', # deleted value ... 'choices-0-votes': '', # deleted value ... 'choices-1-choice': '', @@ -172,7 +167,6 @@ number of forms to be completed. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': '', ... 'choices-0-votes': '', ... 'choices-1-choice': '', @@ -193,7 +187,6 @@ We can just fill out one of the forms. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': '', @@ -214,7 +207,6 @@ And once again, if we try to partially complete a form, validation will fail. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': 'The Decemberists', @@ -275,7 +267,6 @@ To delete something, we just need to set that form's special delete field to >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '2', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-DELETE': '', @@ -325,7 +316,6 @@ something at the front of the list, you'd need to set it's order to 0. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '2', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-ORDER': '1', @@ -352,7 +342,6 @@ they will be sorted below everything else. >>> data = { ... 'choices-TOTAL_FORMS': '4', # the number of forms rendered ... 'choices-INITIAL_FORMS': '3', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-ORDER': '1', @@ -414,7 +403,6 @@ Let's delete Fergie, and put The Decemberists ahead of Calexico. >>> data = { ... 'choices-TOTAL_FORMS': '4', # the number of forms rendered ... 'choices-INITIAL_FORMS': '3', # the number of forms with initial data -... 'choices-MAX_FORMS': '0', # the max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-ORDER': '1', @@ -473,7 +461,6 @@ We start out with a some duplicate data. >>> data = { ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data -... 'drinks-MAX_FORMS': '0', # the max number of forms ... 'drinks-0-name': 'Gin and Tonic', ... 'drinks-1-name': 'Gin and Tonic', ... } @@ -495,7 +482,6 @@ Make sure we didn't break the valid case. >>> data = { ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data -... 'drinks-MAX_FORMS': '0', # the max number of forms ... 'drinks-0-name': 'Gin and Tonic', ... 'drinks-1-name': 'Bloody Mary', ... } diff --git a/tests/regressiontests/forms/localflavor/at.py b/tests/regressiontests/forms/localflavor/at.py new file mode 100644 index 0000000000..54ca46898e --- /dev/null +++ b/tests/regressiontests/forms/localflavor/at.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# Tests for the contrib/localflavor/ AT form fields. + +tests = r""" +# ATZipCodeField ########################################################### + +>>> from django.contrib.localflavor.at.forms import ATZipCodeField +>>> f = ATZipCodeField() +>>> f.clean('1150') +u'1150' +>>> f.clean('4020') +u'4020' +>>> f.clean('8020') +u'8020' +>>> f.clean('111222') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXX.'] +>>> f.clean('eeffee') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXX.'] +>>> f.clean(u'') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + + +>>> f = ATZipCodeField(required=False) +>>> f.clean('1150') +u'1150' +>>> f.clean('4020') +u'4020' +>>> f.clean('8020') +u'8020' +>>> f.clean('111222') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXX.'] +>>> f.clean('eeffee') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXX.'] +>>> f.clean(None) +u'' +>>> f.clean('') +u'' +>>> f.clean(u'') +u'' + +# ATStateSelect ################################################################## + +>>> from django.contrib.localflavor.at.forms import ATStateSelect +>>> f = ATStateSelect() +>>> f.render('bundesland', 'WI') +u'<select name="bundesland">\n<option value="BL">Burgenland</option>\n<option value="KA">Carinthia</option>\n<option value="NO">Lower Austria</option>\n<option value="OO">Upper Austria</option>\n<option value="SA">Salzburg</option>\n<option value="ST">Styria</option>\n<option value="TI">Tyrol</option>\n<option value="VO">Vorarlberg</option>\n<option value="WI" selected="selected">Vienna</option>\n</select>' + +# ATSocialSecurityNumberField ################################################ + +>>> from django.contrib.localflavor.at.forms import ATSocialSecurityNumberField +>>> f = ATSocialSecurityNumberField() +>>> f.clean('1237 010180') +u'1237 010180' +>>> f.clean('1237 010181') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid Austrian Social Security Number in XXXX XXXXXX format.'] +>>> f.clean('12370 010180') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid Austrian Social Security Number in XXXX XXXXXX format.'] +""" diff --git a/tests/regressiontests/forms/localflavor/ro.py b/tests/regressiontests/forms/localflavor/ro.py new file mode 100644 index 0000000000..e885030029 --- /dev/null +++ b/tests/regressiontests/forms/localflavor/ro.py @@ -0,0 +1,175 @@ +# -*- coding: utf-8 -*- +# Tests for the contrib/localflavor/ RO form fields. + +tests = r""" +>>> from django.contrib.localflavor.ro.forms import * + +##ROCIFField ################################################################ + +f = ROCIFField() +f.clean('21694681') +u'21694681' +f.clean('RO21694681') +u'21694681' +f.clean('21694680') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid CIF'] +f.clean('21694680000') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at most 10 characters (it has 11).'] +f.clean('0') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at least 2 characters (it has 1).'] +f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +##ROCNPField ################################################################# + +f = ROCNPField() +f.clean('1981211204489') +u'1981211204489' +f.clean('1981211204487') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid CNP'] +f.clean('1981232204489') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid CNP'] +f.clean('9981211204489') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid CNP'] +f.clean('9981211209') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at least 13 characters (it has 10).'] +f.clean('19812112044891') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at most 13 characters (it has 14).'] +f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +##ROCountyField ############################################################## + +f = ROCountyField() +f.clean('CJ') +'CJ' +f.clean('cj') +'CJ' +f.clean('Argeş') +'AG' +f.clean('argeş') +'AG' +f.clean('Arges') +Traceback (most recent call last): +... +ValidationError: [u'Enter a Romanian county code or name.'] +f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +##ROCountySelect ############################################################# + +f = ROCountySelect() +f.render('county','CJ') +u'<select name="county">\n<option value="AB">Alba</option>\n<option value="AR">A +rad</option>\n<option value="AG">Arge\u015f</option>\n<option value="BC">Bac\u01 +03u</option>\n<option value="BH">Bihor</option>\n<option value="BN">Bistri\u0163 +a-N\u0103s\u0103ud</option>\n<option value="BT">Boto\u015fani</option>\n<option +value="BV">Bra\u015fov</option>\n<option value="BR">Br\u0103ila</option>\n<optio +n value="B">Bucure\u015fti</option>\n<option value="BZ">Buz\u0103u</option>\n<op +tion value="CS">Cara\u015f-Severin</option>\n<option value="CL">C\u0103l\u0103ra +\u015fi</option>\n<option value="CJ" selected="selected">Cluj</option>\n<option +value="CT">Constan\u0163a</option>\n<option value="CV">Covasna</option>\n<option + value="DB">D\xe2mbovi\u0163a</option>\n<option value="DJ">Dolj</option>\n<optio +n value="GL">Gala\u0163i</option>\n<option value="GR">Giurgiu</option>\n<option +value="GJ">Gorj</option>\n<option value="HR">Harghita</option>\n<option value="H +D">Hunedoara</option>\n<option value="IL">Ialomi\u0163a</option>\n<option value= +"IS">Ia\u015fi</option>\n<option value="IF">Ilfov</option>\n<option value="MM">M +aramure\u015f</option>\n<option value="MH">Mehedin\u0163i</option>\n<option valu +e="MS">Mure\u015f</option>\n<option value="NT">Neam\u0163</option>\n<option valu +e="OT">Olt</option>\n<option value="PH">Prahova</option>\n<option value="SM">Sat +u Mare</option>\n<option value="SJ">S\u0103laj</option>\n<option value="SB">Sibi +u</option>\n<option value="SV">Suceava</option>\n<option value="TR">Teleorman</o +ption>\n<option value="TM">Timi\u015f</option>\n<option value="TL">Tulcea</optio +n>\n<option value="VS">Vaslui</option>\n<option value="VL">V\xe2lcea</option>\n< +option value="VN">Vrancea</option>\n</select>' + +##ROIBANField ################################################################# + +f = ROIBANField() +f.clean('RO56RZBR0000060003291177') +u'RO56RZBR0000060003291177' +f.clean('RO56RZBR0000060003291176') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format'] + +f.clean('RO56-RZBR-0000-0600-0329-1177') +u'RO56RZBR0000060003291177' +f.clean('AT61 1904 3002 3457 3201') +Traceback (most recent call last): +... +ValidationError: [u'Enter a valid IBAN in ROXX-XXXX-XXXX-XXXX-XXXX-XXXX format'] + +f.clean('RO56RZBR000006000329117') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at least 24 characters (it has 23).'] +f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +##ROPhoneNumberField ########################################################## + +f = ROPhoneNumberField() +f.clean('0264485936') +u'0264485936' +f.clean('(0264)-485936') +u'0264485936' +f.clean('02644859368') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must be in XXXX-XXXXXX format.'] +f.clean('026448593') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at least 10 characters (it has 9).'] +f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +##ROPostalCodeField ########################################################### + +f = ROPostalCodeField() +f.clean('400473') +u'400473' +f.clean('40047') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at least 6 characters (it has 5).'] +f.clean('4004731') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value has at most 6 characters (it has 7).'] +f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +""" diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py index 98b9233d80..a6baa79811 100644 --- a/tests/regressiontests/forms/models.py +++ b/tests/regressiontests/forms/models.py @@ -1,6 +1,10 @@ +# -*- coding: utf-8 -*- import datetime from django.db import models +# Can't import as "forms" due to implementation details in the test suite (the +# current file is called "forms" and is already imported). +from django import forms as django_forms class BoundaryModel(models.Model): positive_integer = models.PositiveIntegerField(null=True, blank=True) @@ -14,8 +18,23 @@ class ChoiceModel(models.Model): """For ModelChoiceField and ModelMultipleChoiceField tests.""" name = models.CharField(max_length=10) +class FileModel(models.Model): + file = models.FileField(upload_to='/') + +class FileForm(django_forms.Form): + file1 = django_forms.FileField() + __test__ = {'API_TESTS': """ >>> from django.forms import form_for_model, form_for_instance +>>> from django.core.files.uploadedfile import SimpleUploadedFile + +# FileModel with unicode filename and data ######################### +>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')}, auto_id=False) +>>> f.is_valid() +True +>>> f.cleaned_data +{'file1': <SimpleUploadedFile: 我隻氣墊船裝滿晒鱔.txt (text/plain)>} +>>> m = FileModel.objects.create(file=f.cleaned_data['file1']) # Boundary conditions on a PostitiveIntegerField ######################### >>> BoundaryForm = form_for_model(BoundaryModel) diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index ff8213c8d9..6a8b017f44 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -4,6 +4,7 @@ from fields import tests as fields_tests from forms import tests as form_tests from error_messages import tests as custom_error_message_tests from localflavor.ar import tests as localflavor_ar_tests +from localflavor.at import tests as localflavor_at_tests from localflavor.au import tests as localflavor_au_tests from localflavor.br import tests as localflavor_br_tests from localflavor.ca import tests as localflavor_ca_tests @@ -19,6 +20,7 @@ from localflavor.it import tests as localflavor_it_tests from localflavor.jp import tests as localflavor_jp_tests from localflavor.nl import tests as localflavor_nl_tests from localflavor.pl import tests as localflavor_pl_tests +from localflavor.ro import tests as localflavor_ro_tests from localflavor.sk import tests as localflavor_sk_tests from localflavor.uk import tests as localflavor_uk_tests from localflavor.us import tests as localflavor_us_tests @@ -35,6 +37,7 @@ __test__ = { 'form_tests': form_tests, 'custom_error_message_tests': custom_error_message_tests, 'localflavor_ar_tests': localflavor_ar_tests, + 'localflavor_at_tests': localflavor_at_tests, 'localflavor_au_tests': localflavor_au_tests, 'localflavor_br_tests': localflavor_br_tests, 'localflavor_ca_tests': localflavor_ca_tests, @@ -50,6 +53,7 @@ __test__ = { 'localflavor_jp_tests': localflavor_jp_tests, 'localflavor_nl_tests': localflavor_nl_tests, 'localflavor_pl_tests': localflavor_pl_tests, + 'localflavor_ro_tests': localflavor_ro_tests, 'localflavor_sk_tests': localflavor_sk_tests, 'localflavor_uk_tests': localflavor_uk_tests, 'localflavor_us_tests': localflavor_us_tests, |
