diff --git a/DIFFERENCES.md b/DIFFERENCES.md index d25f6ca..4b51bd7 100644 --- a/DIFFERENCES.md +++ b/DIFFERENCES.md @@ -20,6 +20,7 @@ Differences between Mongomallard and Mongoengine * `Document.save()` supports `full=True` keyword argument to force saving all model fields. * `_get_changed_fields()` / `_changed_fields` returns a set * 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: ----- diff --git a/tests/document/validation.py b/tests/document/validation.py index b8480a9..4637dee 100644 --- a/tests/document/validation.py +++ b/tests/document/validation.py @@ -134,13 +134,8 @@ class ValidatorErrorTest(unittest.TestCase): self.assertTrue('e' in keys) self.assertTrue('id' in keys) - doc.e.val = "OK" - try: - 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'}}) + with self.assertRaises(ValueError): + doc.e.val = "OK" if __name__ == '__main__': diff --git a/tests/fields/fields.py b/tests/fields/fields.py index e6a1a37..1eea2ac 100644 --- a/tests/fields/fields.py +++ b/tests/fields/fields.py @@ -342,8 +342,8 @@ class FieldTest(unittest.TestCase): self.assertRaises(ValidationError, person.validate) person.age = 120 self.assertRaises(ValidationError, person.validate) - person.age = 'ten' - self.assertRaises(ValidationError, person.validate) + with self.assertRaises(ValueError): + person.age = 'ten' def test_float_validation(self): """Ensure that invalid values cannot be assigned to float fields. @@ -871,11 +871,8 @@ class FieldTest(unittest.TestCase): e.mapping = [1] e.save() - def create_invalid_mapping(): + with self.assertRaises(ValueError): e.mapping = ["abc"] - e.save() - - self.assertRaises(ValidationError, create_invalid_mapping) Simple.drop_collection()