Fix empty string casted to datetime today in DateTimeField (#1533)
This commit is contained in:
committed by
Stefan Wójcik
parent
24d15d4274
commit
2f1fe5468e
@@ -35,6 +35,28 @@ __all__ = ("FieldTest", "EmbeddedDocumentListFieldTestCase")
|
||||
|
||||
class FieldTest(MongoDBTestCase):
|
||||
|
||||
def test_datetime_from_empty_string(self):
|
||||
"""
|
||||
Ensure an exception is raised when trying to
|
||||
cast an empty string to datetime.
|
||||
"""
|
||||
class MyDoc(Document):
|
||||
dt = DateTimeField()
|
||||
|
||||
md = MyDoc(dt='')
|
||||
self.assertRaises(ValidationError, md.save)
|
||||
|
||||
def test_datetime_from_whitespace_string(self):
|
||||
"""
|
||||
Ensure an exception is raised when trying to
|
||||
cast a whitespace-only string to datetime.
|
||||
"""
|
||||
class MyDoc(Document):
|
||||
dt = DateTimeField()
|
||||
|
||||
md = MyDoc(dt=' ')
|
||||
self.assertRaises(ValidationError, md.save)
|
||||
|
||||
def test_default_values_nothing_set(self):
|
||||
"""Ensure that default field values are used when creating
|
||||
a document.
|
||||
|
||||
Reference in New Issue
Block a user