|
@@ -1,6 +1,7 @@
|
|
|
from datetime import date, datetime, time
|
|
|
|
|
|
from django import forms
|
|
|
+from django.core.exceptions import ValidationError
|
|
|
from django.test import SimpleTestCase, override_settings
|
|
|
from django.utils.translation import activate, deactivate
|
|
|
|
|
@@ -19,7 +20,7 @@ class LocalizedTimeTests(SimpleTestCase):
|
|
|
"TimeFields can parse dates in the default format"
|
|
|
f = forms.TimeField()
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -46,7 +47,7 @@ class LocalizedTimeTests(SimpleTestCase):
|
|
|
"Localized TimeFields act as unlocalized widgets"
|
|
|
f = forms.TimeField(localize=True)
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -69,9 +70,9 @@ class LocalizedTimeTests(SimpleTestCase):
|
|
|
"TimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -94,9 +95,9 @@ class LocalizedTimeTests(SimpleTestCase):
|
|
|
"Localized TimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -122,7 +123,7 @@ class CustomTimeInputFormatsTests(SimpleTestCase):
|
|
|
"TimeFields can parse dates in the default format"
|
|
|
f = forms.TimeField()
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -145,7 +146,7 @@ class CustomTimeInputFormatsTests(SimpleTestCase):
|
|
|
"Localized TimeFields act as unlocalized widgets"
|
|
|
f = forms.TimeField(localize=True)
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -168,9 +169,9 @@ class CustomTimeInputFormatsTests(SimpleTestCase):
|
|
|
"TimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -193,9 +194,9 @@ class CustomTimeInputFormatsTests(SimpleTestCase):
|
|
|
"Localized TimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -220,7 +221,7 @@ class SimpleTimeFormatTests(SimpleTestCase):
|
|
|
"TimeFields can parse dates in the default format"
|
|
|
f = forms.TimeField()
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -243,7 +244,7 @@ class SimpleTimeFormatTests(SimpleTestCase):
|
|
|
"Localized TimeFields in a non-localized environment act as unlocalized widgets"
|
|
|
f = forms.TimeField()
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -266,7 +267,7 @@ class SimpleTimeFormatTests(SimpleTestCase):
|
|
|
"TimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"])
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -289,7 +290,7 @@ class SimpleTimeFormatTests(SimpleTestCase):
|
|
|
"Localized TimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"], localize=True)
|
|
|
# Parse a time in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05')
|
|
|
|
|
|
# Parse a time in a valid format, get a parsed result
|
|
@@ -321,7 +322,7 @@ class LocalizedDateTests(SimpleTestCase):
|
|
|
"DateFields can parse dates in the default format"
|
|
|
f = forms.DateField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21/12/2010')
|
|
|
|
|
|
# ISO formats are accepted, even if not specified in formats.py
|
|
@@ -347,7 +348,7 @@ class LocalizedDateTests(SimpleTestCase):
|
|
|
"Localized DateFields act as unlocalized widgets"
|
|
|
f = forms.DateField(localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21/12/2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -370,11 +371,11 @@ class LocalizedDateTests(SimpleTestCase):
|
|
|
"DateFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"])
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21/12/2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -397,11 +398,11 @@ class LocalizedDateTests(SimpleTestCase):
|
|
|
"Localized DateFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"], localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21/12/2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -427,7 +428,7 @@ class CustomDateInputFormatsTests(SimpleTestCase):
|
|
|
"DateFields can parse dates in the default format"
|
|
|
f = forms.DateField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -450,7 +451,7 @@ class CustomDateInputFormatsTests(SimpleTestCase):
|
|
|
"Localized DateFields act as unlocalized widgets"
|
|
|
f = forms.DateField(localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -473,9 +474,9 @@ class CustomDateInputFormatsTests(SimpleTestCase):
|
|
|
"DateFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"])
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21.12.2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -498,9 +499,9 @@ class CustomDateInputFormatsTests(SimpleTestCase):
|
|
|
"Localized DateFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"], localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21.12.2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -525,7 +526,7 @@ class SimpleDateFormatTests(SimpleTestCase):
|
|
|
"DateFields can parse dates in the default format"
|
|
|
f = forms.DateField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -548,7 +549,7 @@ class SimpleDateFormatTests(SimpleTestCase):
|
|
|
"Localized DateFields in a non-localized environment act as unlocalized widgets"
|
|
|
f = forms.DateField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -571,7 +572,7 @@ class SimpleDateFormatTests(SimpleTestCase):
|
|
|
"DateFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"])
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -594,7 +595,7 @@ class SimpleDateFormatTests(SimpleTestCase):
|
|
|
"Localized DateFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"], localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -626,7 +627,7 @@ class LocalizedDateTimeTests(SimpleTestCase):
|
|
|
"DateTimeFields can parse dates in the default format"
|
|
|
f = forms.DateTimeField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM 21/12/2010')
|
|
|
|
|
|
# ISO formats are accepted, even if not specified in formats.py
|
|
@@ -652,7 +653,7 @@ class LocalizedDateTimeTests(SimpleTestCase):
|
|
|
"Localized DateTimeFields act as unlocalized widgets"
|
|
|
f = forms.DateTimeField(localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM 21/12/2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -675,11 +676,11 @@ class LocalizedDateTimeTests(SimpleTestCase):
|
|
|
"DateTimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"])
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010-12-21 13:30:05 13:30:05')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM 21/12/2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05 21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -702,11 +703,11 @@ class LocalizedDateTimeTests(SimpleTestCase):
|
|
|
"Localized DateTimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"], localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('1:30:05 PM 21/12/2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05 21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -736,7 +737,7 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase):
|
|
|
"DateTimeFields can parse dates in the default format"
|
|
|
f = forms.DateTimeField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -759,7 +760,7 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase):
|
|
|
"Localized DateTimeFields act as unlocalized widgets"
|
|
|
f = forms.DateTimeField(localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -782,9 +783,9 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase):
|
|
|
"DateTimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"])
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05 21.12.2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -807,9 +808,9 @@ class CustomDateTimeInputFormatsTests(SimpleTestCase):
|
|
|
"Localized DateTimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"], localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05 21.12.2010')
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -834,7 +835,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase):
|
|
|
"DateTimeFields can parse dates in the default format"
|
|
|
f = forms.DateTimeField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05 21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -857,7 +858,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase):
|
|
|
"Localized DateTimeFields in a non-localized environment act as unlocalized widgets"
|
|
|
f = forms.DateTimeField()
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('13:30:05 21.12.2010')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -880,7 +881,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase):
|
|
|
"DateTimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"])
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|
|
@@ -903,7 +904,7 @@ class SimpleDateTimeFormatTests(SimpleTestCase):
|
|
|
"Localized DateTimeFields with manually specified input formats can accept those formats"
|
|
|
f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"], localize=True)
|
|
|
# Parse a date in an unaccepted format; get an error
|
|
|
- with self.assertRaises(forms.ValidationError):
|
|
|
+ with self.assertRaises(ValidationError):
|
|
|
f.clean('2010/12/21 13:30:05')
|
|
|
|
|
|
# Parse a date in a valid format, get a parsed result
|