Permalink
Browse files

Update tw2.core Date and DateTime validators to match with tw2.forms.…

…calendars formats
  • Loading branch information...
amol- committed May 8, 2014
1 parent 92324f0 commit 06da5b9023c576b4efb73187d53d6c9a9f691f4d
Showing with 8 additions and 8 deletions.
  1. +6 −6 tests/test_validation.py
  2. +2 −2 tw2/core/validation.py
@@ -494,7 +494,7 @@ class TestOneOfValidator(tb.ValidatorTest):
class TestDateValidator(tb.ValidatorTest):
validator = DateValidator
to_python_attrs = [{}, {}]
to_python_params = ['01/01/2009', 'asdf']
to_python_params = ['2009-01-01', 'asdf']
to_python_expected = [datetime.date(2009, 1, 1), ValidationError]
attrs = [{'required': False}, {'required': True}]
@@ -503,22 +503,22 @@ class TestDateValidator(tb.ValidatorTest):
from_python_attrs = [{}, {}]
from_python_params = [datetime.date(2009, 1, 1)]
from_python_expected = ['01/01/2009']
from_python_expected = ['2009-01-01']
def test_max_str(self):
expected = '31/12/2009'
expected = '2009-12-31'
r = DateValidator(max=datetime.date(2009, 12, 31)).max_str
eq_(r, expected)
def test_min_str(self):
expected = '31/12/2009'
expected = '2009-12-31'
r = DateValidator(min=datetime.date(2009, 12, 31)).min_str
eq_(r, expected)
class TestDatetimeValidator(tb.ValidatorTest):
validator = DateTimeValidator
to_python_attrs = [{}, {}]
to_python_params = ['01/01/2009 01:00', 'asdf']
to_python_params = ['2009-01-01 01:00', 'asdf']
to_python_expected = [datetime.datetime.strptime('1/1/2009 1:00', '%d/%m/%Y %H:%M'), ValidationError]
attrs = [{'required': False}, {'required': True}]
@@ -527,7 +527,7 @@ class TestDatetimeValidator(tb.ValidatorTest):
from_python_attrs = [{}, {}]
from_python_params = [datetime.datetime.strptime('1/1/2009 1:00', '%d/%m/%Y %H:%M')]
from_python_expected = ['01/01/2009 01:00']
from_python_expected = ['2009-01-01 01:00']
class TestRegexValidator(tb.ValidatorTest):
validator = RegexValidator
@@ -441,7 +441,7 @@ class DateTimeValidator(RangeValidator):
'toosmall': ('date_toosmall', _('Cannot be earlier than $min_str')),
'toobig': ('date_toobig', _('Cannot be later than $max_str')),
}
format = '%d/%m/%Y %H:%M'
format = '%Y-%m-%d %H:%M'
format_tbl = {
'd': 'day',
@@ -494,7 +494,7 @@ class DateValidator(DateTimeValidator):
'baddatetime': (
'baddate', _('Must follow date format $format_str')),
}
format = '%d/%m/%Y'
format = '%Y-%m-%d'
def _convert_to_python(self, value, state=None):
value = super(DateValidator, self)._convert_to_python(value)

0 comments on commit 06da5b9

Please sign in to comment.