raises error when date string has too many components

This commit is contained in:
discopatrick 2017-04-14 01:32:18 +01:00
parent 3aebb30ad9
commit 8e6909bf4b
2 changed files with 3 additions and 2 deletions

View file

@ -555,7 +555,7 @@ class Period(object):
ordinal = string.count('-') ordinal = string.count('-')
if ordinal >= len(cls.date_formats): if ordinal >= len(cls.date_formats):
# Too many components. # Too many components.
return None raise InvalidQueryArgumentTypeError(string, 'a valid datetime string')
date_format = cls.date_formats[ordinal] date_format = cls.date_formats[ordinal]
try: try:
date = datetime.strptime(string, date_format) date = datetime.strptime(string, date_format)

View file

@ -121,7 +121,8 @@ class DateQueryConstructTest(unittest.TestCase):
DateQuery('added', '1409830085..1412422089') DateQuery('added', '1409830085..1412422089')
def test_too_many_components(self): def test_too_many_components(self):
DateQuery('added', '12-34-56-78') with self.assertRaises(InvalidQueryArgumentTypeError):
DateQuery('added', '12-34-56-78')
def suite(): def suite():