Merge pull request #957 from noirbizarre/metastrict

Allow to loads undeclared field with meta attribute (fix #934)
This commit is contained in:
Omer Katz
2015-04-29 19:32:26 +03:00
6 changed files with 145 additions and 6 deletions

View File

@@ -3195,7 +3195,7 @@ class FieldTest(unittest.TestCase):
def test_undefined_field_exception(self):
"""Tests if a `FieldDoesNotExist` exception is raised when trying to
set a value to a field that's not defined.
instanciate a document with a field that's not defined.
"""
class Doc(Document):
@@ -3206,6 +3206,21 @@ class FieldTest(unittest.TestCase):
self.assertRaises(FieldDoesNotExist, test)
def test_undefined_field_exception_with_strict(self):
"""Tests if a `FieldDoesNotExist` exception is raised when trying to
instanciate a document with a field that's not defined,
even when strict is set to False.
"""
class Doc(Document):
foo = StringField(db_field='f')
meta = {'strict': False}
def test():
Doc(bar='test')
self.assertRaises(FieldDoesNotExist, test)
class EmbeddedDocumentListFieldTestCase(unittest.TestCase):