diff options
| author | Tom Christie | 2012-01-19 10:55:31 -0800 |
|---|---|---|
| committer | Tom Christie | 2012-01-19 10:55:31 -0800 |
| commit | a8ed7f91890ca8213073327b07a44a121df66083 (patch) | |
| tree | 4bd6a45b68a539935db4da5b431bd8312e469c65 /djangorestframework/tests | |
| parent | 868f7bd7dc029ade432af22ba69cf2ff4e4a835c (diff) | |
| parent | 4e52ce4d333ec090304000bce0e71c78cacd73b5 (diff) | |
| download | django-rest-framework-a8ed7f91890ca8213073327b07a44a121df66083.tar.bz2 | |
Merge pull request #130 from flashingpumpkin/master
Added an additional attribute `unknown_form_fields` to `FormResource`
Diffstat (limited to 'djangorestframework/tests')
| -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..7b643272 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.allow_unknown_form_fields = True + self.assertDictEqual({'qwerty': u'uiop'}, validator.validate_request(content, None), "Resource didn't accept unknown fields.") + validator.allow_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()) |
