MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / test_validation

Method test_validation

tests/fields/test_date_field.py:136–163  ·  view source on GitHub ↗

Ensure that invalid values cannot be assigned to datetime fields.

(self)

Source from the content-addressed store, hash-verified

134 assert logs.count() == 10
135
136 def test_validation(self):
137 """Ensure that invalid values cannot be assigned to datetime
138 fields.
139 """
140
141 class LogEntry(Document):
142 time = DateField()
143
144 log = LogEntry()
145 log.time = datetime.datetime.now()
146 log.validate()
147
148 log.time = datetime.date.today()
149 log.validate()
150
151 log.time = datetime.datetime.now().isoformat(" ")
152 log.validate()
153
154 if dateutil:
155 log.time = datetime.datetime.now().isoformat("T")
156 log.validate()
157
158 log.time = -1
159 with pytest.raises(ValidationError):
160 log.validate()
161 log.time = "ABC"
162 with pytest.raises(ValidationError):
163 log.validate()

Callers

nothing calls this directly

Calls 2

LogEntryClass · 0.70
validateMethod · 0.45

Tested by

no test coverage detected