Skip to content

Commit 2fd6bfe

Browse files
committed
validate_update() is deprecated.
Use validate() with 'update=True' instead. Closes pyeve#21.
1 parent 2173713 commit 2fd6bfe

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

CHANGES

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Version 0.4.0
88

99
Not released yet.
1010

11+
- 'validate_update' is deprecated and will be removed with next release. Use
12+
'validate' with 'update=True' instead. Closes #21.
1113
- Fixed a minor encoding issue which made installing on Windows/Python3
1214
impossible. Closes #19 (Arsh Singh).
1315
- Fix documentation typo (Daniele Pizzolli).
@@ -32,14 +34,14 @@ Released on July 9 2013.
3234
Version 0.2.0
3335
-------------
3436

35-
Released on April 18 2013.
37+
Released on April 18 2013.
3638

3739
- 'allow_unknown' option added.
3840

3941
Version 0.1.0
4042
-------------
4143

42-
Released on March 15 2013.
44+
Released on March 15 2013.
4345
Codename: 'Claw'.
4446

4547
- entering beta phase.
@@ -56,7 +58,7 @@ Version 0.0.3
5658

5759
Released on January 29 2013
5860

59-
- when a list item fails, its offset is now returned along with the list name
61+
- when a list item fails, its offset is now returned along with the list name.
6062
- 'transparent_schema_rules' option added.
6163
- 'empty' rule for string fields.
6264
- 'schema' rule on lists of arbitrary lenght (Martjin Vermaat).

cerberus/cerberus.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ class SchemaError(ValueError):
3434

3535

3636
class Validator(object):
37-
""" Validator class. Validates any Python dict
38-
against a validation schema, which is provided as an argument at
39-
class instantiation, or upon calling the :func:`validate` or
40-
:func:`validate_update` methods.
37+
""" Validator class. Validates any Python dict against a validation schema,
38+
which is provided as an argument at class instantiation, or upon calling
39+
the :func:`validate` method.
4140
4241
:param schema: optional validation schema.
4342
:param transparent_schema_rules: if ``True`` unknown schema rules will be
@@ -55,9 +54,11 @@ class instantiation, or upon calling the :func:`validate` or
5554
field error' un validation.
5655
5756
.. versionchanged:: 0.4.0
58-
'type' validation is always performed first (only exception being
59-
'nullable'). On failure, it blocks other rules on the same field. Closes
60-
#18.
57+
:func:`validate_update` is deprecated. Use :func:`validate` with
58+
``update=True`` instead.
59+
Type validation is always performed first (only exception being
60+
``nullable``). On failure, it blocks other rules on the same field.
61+
Closes #18.
6162
6263
.. versionadded:: 0.2.0
6364
`self.errors` returns an empty list when validate() has not been called.
@@ -87,8 +88,7 @@ def __init__(self, schema=None, transparent_schema_rules=False,
8788
def errors(self):
8889
"""
8990
:rtype: a list of validation errors. Will be empty if no errors
90-
were found during. Resets after each call to :func:`validate`
91-
or :func:`validate_update`.
91+
were found during. Resets after each call to :func:`validate`.
9292
"""
9393
return self._errors
9494

@@ -102,21 +102,29 @@ def validate_update(self, document, schema=None):
102102
class instantation.
103103
:return: True if validation succeeds, False otherwise. Check the
104104
:func:`errors` property for a list of validation errors.
105+
106+
.. deprecated:: 0.4.0
107+
Use :func:`validate` with ``update=True`` instead.
105108
"""
106109
return self._validate(document, schema, update=True)
107110

108-
def validate(self, document, schema=None):
111+
def validate(self, document, schema=None, update=False):
109112
""" Validates a Python dictionary against a validation schema.
110113
111114
:param document: the dict to validate.
112115
:param schema: the validation schema. Defaults to ``None``. If not
113116
provided here, the schema must have been provided at
114117
class instantation.
118+
:param update: If ``True`` validation of required fields won't be
119+
performed.
115120
116121
:return: True if validation succeeds, False otherwise. Check the
117122
:func:`errors` property for a list of validation errors.
123+
124+
.. versionchanged:: 0.4.0
125+
Support for update mode.
118126
"""
119-
return self._validate(document, schema, update=False)
127+
return self._validate(document, schema, update=update)
120128

121129
def _validate(self, document, schema=None, update=False):
122130

cerberus/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def assertFail(self, document, schema=None, validator=None):
111111
def assertSuccess(self, document, schema=None, validator=None):
112112
if validator is None:
113113
validator = self.validator
114-
self.assertTrue(validator.validate_update(document, schema))
114+
self.assertTrue(validator.validate(document, schema, update=True))
115115

116116
def assertError(self, error, validator=None):
117117
if validator is None:

cerberus/tests/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def test_string_unallowed(self):
190190
self.assertError(errors.ERROR_UNALLOWED_VALUE % (value, field))
191191

192192
def test_validate_update(self):
193-
self.assertTrue(self.validator.validate_update({'an_integer': 100}))
193+
self.assertTrue(self.validator.validate({'an_integer': 100},
194+
update=True))
194195

195196
def test_string(self):
196197
self.assertSuccess({'a_required_string': 'john doe'})

docs/index.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ You define a validation schema and pass it to an instance of the
2020
>>> schema = {'name': {'type': 'string'}}
2121
>>> v = Validator(schema)
2222

23-
Then you simply invoke the :func:`~cerberus.Validator.validate` or
24-
:func:`~cerberus.Validator.validate_update` methods to validate a dictionary
25-
against the schema. If validation succeeds, ``True`` is returned: ::
23+
Then you simply invoke the :func:`~cerberus.Validator.validate` to validate
24+
a dictionary against the schema. If validation succeeds, ``True`` is returned:
25+
26+
::
2627

2728
>>> document = {'name': 'john doe'}
2829
>>> v.validate(document)
@@ -189,10 +190,11 @@ You can extend this list and support custom types, see :ref:`new-types`.
189190

190191
required
191192
''''''''
192-
If ``True`` the key/value pair is mandatory and validation will fail when
193-
:func:`~cerberus.Validator.validate` is called. Validation will still succeed
194-
if the value is missing and :func:`~cerberus.Validator.validate_update` is
195-
called instead.::
193+
If ``True`` the key/value pair is mandatory. Validation will fail when it is
194+
missing, unless :func:`~cerberus.Validator.validate` is called with
195+
``update=True``:
196+
197+
::
196198

197199
>>> schema = {'name': {'required': True, 'type': 'string'}, 'age': {'type': 'integer'}}
198200
>>> v = Validator(schema)
@@ -202,7 +204,7 @@ called instead.::
202204
>>> v.errors
203205
["required field(s) are missing: 'name'"]
204206

205-
>>> v.validate_update(document)
207+
>>> v.validate(document, update=True)
206208
True
207209

208210
.. note::

0 commit comments

Comments
 (0)