aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/validators.py
diff options
context:
space:
mode:
Diffstat (limited to 'djangorestframework/tests/validators.py')
-rw-r--r--djangorestframework/tests/validators.py12
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())