diff options
Diffstat (limited to 'tests/regressiontests/forms/fields.py')
-rw-r--r-- | tests/regressiontests/forms/fields.py | 106 |
1 files changed, 59 insertions, 47 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 ################################################################ |