Fix IntField assignment unit tests

This commit is contained in:
Thomas Steinacher 2013-06-18 18:31:11 -07:00
commit 2a93a69085
3 changed files with 6 additions and 13 deletions

View file

@ -20,6 +20,7 @@ Differences between Mongomallard and Mongoengine
* `Document.save()` supports `full=True` keyword argument to force saving all model fields. * `Document.save()` supports `full=True` keyword argument to force saving all model fields.
* `_get_changed_fields()` / `_changed_fields` returns a set * `_get_changed_fields()` / `_changed_fields` returns a set
* Simplified `EmailField` email regex to be more compatible * Simplified `EmailField` email regex to be more compatible
* Assigning invalid types (e.g. an invalid string to `IntField`) raises immediately a `ValueError`
Untested / not implemented yet: Untested / not implemented yet:
----- -----

View file

@ -134,13 +134,8 @@ class ValidatorErrorTest(unittest.TestCase):
self.assertTrue('e' in keys) self.assertTrue('e' in keys)
self.assertTrue('id' in keys) self.assertTrue('id' in keys)
doc.e.val = "OK" with self.assertRaises(ValueError):
try: doc.e.val = "OK"
doc.save()
except ValidationError, e:
self.assertTrue("Doc:test" in e.message)
self.assertEqual(e.to_dict(), {
"e": {'val': 'OK could not be converted to int'}})
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -342,8 +342,8 @@ class FieldTest(unittest.TestCase):
self.assertRaises(ValidationError, person.validate) self.assertRaises(ValidationError, person.validate)
person.age = 120 person.age = 120
self.assertRaises(ValidationError, person.validate) self.assertRaises(ValidationError, person.validate)
person.age = 'ten' with self.assertRaises(ValueError):
self.assertRaises(ValidationError, person.validate) person.age = 'ten'
def test_float_validation(self): def test_float_validation(self):
"""Ensure that invalid values cannot be assigned to float fields. """Ensure that invalid values cannot be assigned to float fields.
@ -871,11 +871,8 @@ class FieldTest(unittest.TestCase):
e.mapping = [1] e.mapping = [1]
e.save() e.save()
def create_invalid_mapping(): with self.assertRaises(ValueError):
e.mapping = ["abc"] e.mapping = ["abc"]
e.save()
self.assertRaises(ValidationError, create_invalid_mapping)
Simple.drop_collection() Simple.drop_collection()