diff options
| author | Alen Mujezinovic | 2012-01-17 10:58:42 +0000 |
|---|---|---|
| committer | Alen Mujezinovic | 2012-01-17 11:01:32 +0000 |
| commit | 0a167a54fdbf9ceba2a1513636a50bf4c89efa66 (patch) | |
| tree | ed9dcdcb6cc5d968ee9c597efb32792e6d8f663f /djangorestframework/tests/validators.py | |
| parent | 5f4096ca28d6c0b9ea98f43278789b38cf0d37bb (diff) | |
| download | django-rest-framework-0a167a54fdbf9ceba2a1513636a50bf4c89efa66.tar.bz2 | |
Added an additional attribute `unknown_form_fields` to `FormResource`
If the attribute is set to `True`, the validation method will not
raise an `ErrorResponse` with status 400 but silently strip out
unexpected fields on the form and only return the validated data.
Diffstat (limited to 'djangorestframework/tests/validators.py')
| -rw-r--r-- | djangorestframework/tests/validators.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index 18c8c313..c316f209 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -138,6 +138,14 @@ class TestFormValidation(TestCase): content = {'qwerty': 'uiop', 'extra': 'extra'} validator._validate(content, None, allowed_extra_fields=('extra',)) + def validation_allows_unknown_fields_if_explicitly_allowed(self, validator): + """If we set ``unknown_form_fields`` on the form resource, then don't + raise errors on unexpected request data""" + content = {'qwerty': 'uiop', 'extra': 'extra'} + validator.unknown_form_fields = True + self.assertDictEqual({'qwerty': u'uiop'}, validator.validate_request(content, None), "Resource didn't accept unknown fields.") + validator.unknown_form_fields = False + def validation_does_not_require_extra_fields_if_explicitly_set(self, validator): """If we include an allowed_extra_fields paramater on _validate, then do not fail if we do not have fields with those names.""" content = {'qwerty': 'uiop'} @@ -201,6 +209,10 @@ class TestFormValidation(TestCase): def test_validation_allows_extra_fields_if_explicitly_set(self): validator = self.MockFormResource(self.MockFormView()) self.validation_allows_extra_fields_if_explicitly_set(validator) + + def test_validation_allows_unknown_fields_if_explicitly_allowed(self): + validator = self.MockFormResource(self.MockFormView()) + self.validation_allows_unknown_fields_if_explicitly_allowed(validator) def test_validation_does_not_require_extra_fields_if_explicitly_set(self): validator = self.MockFormResource(self.MockFormView()) |
