From a9df917d10e5f84090074e11213eb6d550c174cc Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 11 Apr 2011 15:03:49 +0100 Subject: Lots of validator tests passing after refactor --- djangorestframework/tests/validators.py | 250 ++++++++++++++++++-------------- 1 file changed, 140 insertions(+), 110 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index b5d2d566..f7d2d529 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -2,7 +2,7 @@ from django import forms from django.db import models from django.test import TestCase from djangorestframework.compat import RequestFactory -from djangorestframework.validators import ValidatorMixin, FormValidatorMixin, ModelFormValidatorMixin +from djangorestframework.validators import BaseValidator, FormValidator, ModelFormValidator from djangorestframework.response import ResponseException @@ -11,59 +11,68 @@ class TestValidatorMixinInterfaces(TestCase): def test_validator_mixin_interface(self): """Ensure the ValidatorMixin base class interface is as expected.""" - self.assertRaises(NotImplementedError, ValidatorMixin().validate, None) + self.assertRaises(NotImplementedError, BaseValidator(None).validate, None) - def test_form_validator_mixin_interface(self): - """Ensure the FormValidatorMixin interface is as expected.""" - self.assertTrue(issubclass(FormValidatorMixin, ValidatorMixin)) - getattr(FormValidatorMixin, 'form') - getattr(FormValidatorMixin, 'validate') + #def test_form_validator_mixin_interface(self): + # """Ensure the FormValidatorMixin interface is as expected.""" + # self.assertTrue(issubclass(FormValidator, BaseValidator)) + # getattr(FormValidator, 'form') + # getattr(FormValidator, 'validate') - def test_model_form_validator_mixin_interface(self): - """Ensure the ModelFormValidatorMixin interface is as expected.""" - self.assertTrue(issubclass(ModelFormValidatorMixin, FormValidatorMixin)) - getattr(ModelFormValidatorMixin, 'model') - getattr(ModelFormValidatorMixin, 'form') - getattr(ModelFormValidatorMixin, 'fields') - getattr(ModelFormValidatorMixin, 'exclude_fields') - getattr(ModelFormValidatorMixin, 'validate') + #def test_model_form_validator_mixin_interface(self): + # """Ensure the ModelFormValidatorMixin interface is as expected.""" + # self.assertTrue(issubclass(ModelFormValidator, FormValidator)) + # getattr(ModelFormValidator, 'model') + # getattr(ModelFormValidator, 'form') + # getattr(ModelFormValidator, 'fields') + # getattr(ModelFormValidator, 'exclude_fields') + # getattr(ModelFormValidator, 'validate') class TestDisabledValidations(TestCase): - """Tests on Validator Mixins with validation disabled by setting form to None""" + """Tests on FormValidator with validation disabled by setting form to None""" def test_disabled_form_validator_returns_content_unchanged(self): - """If the form attribute is None on FormValidatorMixin then validate(content) should just return the content unmodified.""" - class DisabledFormValidator(FormValidatorMixin): + """If the view's form attribute is None then FormValidator(view).validate(content) + should just return the content unmodified.""" + class DisabledFormView(object): form = None + view = DisabledFormView() content = {'qwerty':'uiop'} - self.assertEqual(DisabledFormValidator().validate(content), content) + self.assertEqual(FormValidator(view).validate(content), content) def test_disabled_form_validator_get_bound_form_returns_none(self): - """If the form attribute is None on FormValidatorMixin then get_bound_form(content) should just return None.""" - class DisabledFormValidator(FormValidatorMixin): + """If the view's form attribute is None on then + FormValidator(view).get_bound_form(content) should just return None.""" + class DisabledFormView(object): form = None - content = {'qwerty':'uiop'} - self.assertEqual(DisabledFormValidator().get_bound_form(content), None) + view = DisabledFormView() + content = {'qwerty':'uiop'} + self.assertEqual(FormValidator(view).get_bound_form(content), None) + def test_disabled_model_form_validator_returns_content_unchanged(self): - """If the form attribute is None on FormValidatorMixin then validate(content) should just return the content unmodified.""" - class DisabledModelFormValidator(ModelFormValidatorMixin): + """If the view's form and model attributes are None then + ModelFormValidator(view).validate(content) should just return the content unmodified.""" + class DisabledModelFormView(object): form = None + model = None + view = DisabledModelFormView() content = {'qwerty':'uiop'} - self.assertEqual(DisabledModelFormValidator().validate(content), content) + self.assertEqual(ModelFormValidator(view).get_bound_form(content), None)# def test_disabled_model_form_validator_get_bound_form_returns_none(self): """If the form attribute is None on FormValidatorMixin then get_bound_form(content) should just return None.""" - class DisabledModelFormValidator(ModelFormValidatorMixin): + class DisabledModelFormView(object): form = None - - content = {'qwerty':'uiop'} - self.assertEqual(DisabledModelFormValidator().get_bound_form(content), None) - + model = None + + view = DisabledModelFormView() + content = {'qwerty':'uiop'} + self.assertEqual(ModelFormValidator(view).get_bound_form(content), None)# class TestNonFieldErrors(TestCase): """Tests against form validation errors caused by non-field errors. (eg as might be caused by some custom form validation)""" @@ -80,12 +89,13 @@ class TestNonFieldErrors(TestCase): raise forms.ValidationError(self.ERROR_TEXT) return self.cleaned_data #pragma: no cover - class MockValidator(FormValidatorMixin): + class MockView(object): form = MockForm + view = MockView() content = {'field1': 'example1', 'field2': 'example2'} try: - MockValidator().validate(content) + FormValidator(view).validate(content) except ResponseException, exc: self.assertEqual(exc.response.raw_content, {'errors': [MockForm.ERROR_TEXT]}) else: @@ -95,19 +105,21 @@ class TestNonFieldErrors(TestCase): class TestFormValidation(TestCase): """Tests which check basic form validation. Also includes the same set of tests with a ModelFormValidator for which the form has been explicitly set. - (ModelFormValidatorMixin should behave as FormValidatorMixin if form is set rather than relying on the default ModelForm)""" + (ModelFormValidator should behave as FormValidator if a form is set rather than relying on the default ModelForm)""" def setUp(self): class MockForm(forms.Form): qwerty = forms.CharField(required=True) - class MockFormValidator(FormValidatorMixin): + class MockFormView(object): form = MockForm - - class MockModelFormValidator(ModelFormValidatorMixin): + validators = (FormValidator,) + + class MockModelFormView(object): form = MockForm - - self.MockFormValidator = MockFormValidator - self.MockModelFormValidator = MockModelFormValidator + validators = (ModelFormValidator,) + + self.MockFormView = MockFormView + self.MockModelFormView = MockModelFormView def validation_returns_content_unchanged_if_already_valid_and_clean(self, validator): @@ -181,111 +193,129 @@ class TestFormValidation(TestCase): # Tests on FormValidtionMixin def test_form_validation_returns_content_unchanged_if_already_valid_and_clean(self): - self.validation_returns_content_unchanged_if_already_valid_and_clean(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_returns_content_unchanged_if_already_valid_and_clean(validator) def test_form_validation_failure_raises_response_exception(self): - self.validation_failure_raises_response_exception(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_failure_raises_response_exception(validator) def test_validation_does_not_allow_extra_fields_by_default(self): - self.validation_does_not_allow_extra_fields_by_default(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_does_not_allow_extra_fields_by_default(validator) def test_validation_allows_extra_fields_if_explicitly_set(self): - self.validation_allows_extra_fields_if_explicitly_set(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_allows_extra_fields_if_explicitly_set(validator) def test_validation_does_not_require_extra_fields_if_explicitly_set(self): - self.validation_does_not_require_extra_fields_if_explicitly_set(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_does_not_require_extra_fields_if_explicitly_set(validator) def test_validation_failed_due_to_no_content_returns_appropriate_message(self): - self.validation_failed_due_to_no_content_returns_appropriate_message(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_failed_due_to_no_content_returns_appropriate_message(validator) def test_validation_failed_due_to_field_error_returns_appropriate_message(self): - self.validation_failed_due_to_field_error_returns_appropriate_message(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_failed_due_to_field_error_returns_appropriate_message(validator) def test_validation_failed_due_to_invalid_field_returns_appropriate_message(self): - self.validation_failed_due_to_invalid_field_returns_appropriate_message(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_failed_due_to_invalid_field_returns_appropriate_message(validator) def test_validation_failed_due_to_multiple_errors_returns_appropriate_message(self): - self.validation_failed_due_to_multiple_errors_returns_appropriate_message(self.MockFormValidator()) + validator = FormValidator(self.MockFormView()) + self.validation_failed_due_to_multiple_errors_returns_appropriate_message(validator) # Same tests on ModelFormValidtionMixin def test_modelform_validation_returns_content_unchanged_if_already_valid_and_clean(self): - self.validation_returns_content_unchanged_if_already_valid_and_clean(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_returns_content_unchanged_if_already_valid_and_clean(validator) def test_modelform_validation_failure_raises_response_exception(self): - self.validation_failure_raises_response_exception(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_failure_raises_response_exception(validator) def test_modelform_validation_does_not_allow_extra_fields_by_default(self): - self.validation_does_not_allow_extra_fields_by_default(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_does_not_allow_extra_fields_by_default(validator) def test_modelform_validation_allows_extra_fields_if_explicitly_set(self): - self.validation_allows_extra_fields_if_explicitly_set(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_allows_extra_fields_if_explicitly_set(validator) def test_modelform_validation_does_not_require_extra_fields_if_explicitly_set(self): - self.validation_does_not_require_extra_fields_if_explicitly_set(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_does_not_require_extra_fields_if_explicitly_set(validator) def test_modelform_validation_failed_due_to_no_content_returns_appropriate_message(self): - self.validation_failed_due_to_no_content_returns_appropriate_message(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_failed_due_to_no_content_returns_appropriate_message(validator) def test_modelform_validation_failed_due_to_field_error_returns_appropriate_message(self): - self.validation_failed_due_to_field_error_returns_appropriate_message(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_failed_due_to_field_error_returns_appropriate_message(validator) def test_modelform_validation_failed_due_to_invalid_field_returns_appropriate_message(self): - self.validation_failed_due_to_invalid_field_returns_appropriate_message(self.MockModelFormValidator()) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_failed_due_to_invalid_field_returns_appropriate_message(validator) def test_modelform_validation_failed_due_to_multiple_errors_returns_appropriate_message(self): - self.validation_failed_due_to_multiple_errors_returns_appropriate_message(self.MockModelFormValidator()) - - -class TestModelFormValidator(TestCase): - """Tests specific to ModelFormValidatorMixin""" - - def setUp(self): - """Create a validator for a model with two fields and a property.""" - class MockModel(models.Model): - qwerty = models.CharField(max_length=256) - uiop = models.CharField(max_length=256, blank=True) - - @property - def readonly(self): - return 'read only' - - class MockValidator(ModelFormValidatorMixin): - model = MockModel - - self.MockValidator = MockValidator - - - def test_property_fields_are_allowed_on_model_forms(self): - """Validation on ModelForms may include property fields that exist on the Model to be included in the input.""" - content = {'qwerty':'example', 'uiop': 'example', 'readonly': 'read only'} - self.assertEqual(self.MockValidator().validate(content), content) - - def test_property_fields_are_not_required_on_model_forms(self): - """Validation on ModelForms does not require property fields that exist on the Model to be included in the input.""" - content = {'qwerty':'example', 'uiop': 'example'} - self.assertEqual(self.MockValidator().validate(content), content) - - def test_extra_fields_not_allowed_on_model_forms(self): - """If some (otherwise valid) content includes fields that are not in the form then validation should fail. - It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up - broken clients more easily (eg submitting content with a misnamed field)""" - content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} - self.assertRaises(ResponseException, self.MockValidator().validate, content) - - def test_validate_requires_fields_on_model_forms(self): - """If some (otherwise valid) content includes fields that are not in the form then validation should fail. - It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up - broken clients more easily (eg submitting content with a misnamed field)""" - content = {'readonly': 'read only'} - self.assertRaises(ResponseException, self.MockValidator().validate, content) - - def test_validate_does_not_require_blankable_fields_on_model_forms(self): - """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" - content = {'qwerty':'example', 'readonly': 'read only'} - self.MockValidator().validate(content) - - def test_model_form_validator_uses_model_forms(self): - self.assertTrue(isinstance(self.MockValidator().get_bound_form(), forms.ModelForm)) + validator = ModelFormValidator(self.MockModelFormView()) + self.validation_failed_due_to_multiple_errors_returns_appropriate_message(validator) + + +# class TestModelFormValidator(TestCase): +# """Tests specific to ModelFormValidatorMixin""" +# +# def setUp(self): +# """Create a validator for a model with two fields and a property.""" +# class MockModel(models.Model): +# qwerty = models.CharField(max_length=256) +# uiop = models.CharField(max_length=256, blank=True) +# +# @property +# def readonly(self): +# return 'read only' +# +# class MockValidator(ModelFormValidatorMixin): +# model = MockModel +# +# self.MockValidator = MockValidator +# +# +# def test_property_fields_are_allowed_on_model_forms(self): +# """Validation on ModelForms may include property fields that exist on the Model to be included in the input.""" +# content = {'qwerty':'example', 'uiop': 'example', 'readonly': 'read only'} +# self.assertEqual(self.MockValidator().validate(content), content) +# +# def test_property_fields_are_not_required_on_model_forms(self): +# """Validation on ModelForms does not require property fields that exist on the Model to be included in the input.""" +# content = {'qwerty':'example', 'uiop': 'example'} +# self.assertEqual(self.MockValidator().validate(content), content) +# +# def test_extra_fields_not_allowed_on_model_forms(self): +# """If some (otherwise valid) content includes fields that are not in the form then validation should fail. +# It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up +# broken clients more easily (eg submitting content with a misnamed field)""" +# content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} +# self.assertRaises(ResponseException, self.MockValidator().validate, content) +# +# def test_validate_requires_fields_on_model_forms(self): +# """If some (otherwise valid) content includes fields that are not in the form then validation should fail. +# It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up +# broken clients more easily (eg submitting content with a misnamed field)""" +# content = {'readonly': 'read only'} +# self.assertRaises(ResponseException, self.MockValidator().validate, content) +# +# def test_validate_does_not_require_blankable_fields_on_model_forms(self): +# """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" +# content = {'qwerty':'example', 'readonly': 'read only'} +# self.MockValidator().validate(content) +# +# def test_model_form_validator_uses_model_forms(self): +# self.assertTrue(isinstance(self.MockValidator().get_bound_form(), forms.ModelForm)) -- cgit v1.2.3 From 29db0a60fb88686f721da75dc058222c922ffdeb Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 11 Apr 2011 15:06:29 +0100 Subject: Even more validator tests passing after refactor --- djangorestframework/tests/validators.py | 100 ++++++++++++++++---------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index f7d2d529..1f14f710 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -267,55 +267,55 @@ class TestFormValidation(TestCase): self.validation_failed_due_to_multiple_errors_returns_appropriate_message(validator) -# class TestModelFormValidator(TestCase): -# """Tests specific to ModelFormValidatorMixin""" -# -# def setUp(self): -# """Create a validator for a model with two fields and a property.""" -# class MockModel(models.Model): -# qwerty = models.CharField(max_length=256) -# uiop = models.CharField(max_length=256, blank=True) -# -# @property -# def readonly(self): -# return 'read only' -# -# class MockValidator(ModelFormValidatorMixin): -# model = MockModel -# -# self.MockValidator = MockValidator -# -# -# def test_property_fields_are_allowed_on_model_forms(self): -# """Validation on ModelForms may include property fields that exist on the Model to be included in the input.""" -# content = {'qwerty':'example', 'uiop': 'example', 'readonly': 'read only'} -# self.assertEqual(self.MockValidator().validate(content), content) -# -# def test_property_fields_are_not_required_on_model_forms(self): -# """Validation on ModelForms does not require property fields that exist on the Model to be included in the input.""" -# content = {'qwerty':'example', 'uiop': 'example'} -# self.assertEqual(self.MockValidator().validate(content), content) -# -# def test_extra_fields_not_allowed_on_model_forms(self): -# """If some (otherwise valid) content includes fields that are not in the form then validation should fail. -# It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up -# broken clients more easily (eg submitting content with a misnamed field)""" -# content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} -# self.assertRaises(ResponseException, self.MockValidator().validate, content) -# -# def test_validate_requires_fields_on_model_forms(self): -# """If some (otherwise valid) content includes fields that are not in the form then validation should fail. -# It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up -# broken clients more easily (eg submitting content with a misnamed field)""" -# content = {'readonly': 'read only'} -# self.assertRaises(ResponseException, self.MockValidator().validate, content) -# -# def test_validate_does_not_require_blankable_fields_on_model_forms(self): -# """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" -# content = {'qwerty':'example', 'readonly': 'read only'} -# self.MockValidator().validate(content) -# -# def test_model_form_validator_uses_model_forms(self): -# self.assertTrue(isinstance(self.MockValidator().get_bound_form(), forms.ModelForm)) +class TestModelFormValidator(TestCase): + """Tests specific to ModelFormValidatorMixin""" + + def setUp(self): + """Create a validator for a model with two fields and a property.""" + class MockModel(models.Model): + qwerty = models.CharField(max_length=256) + uiop = models.CharField(max_length=256, blank=True) + + @property + def readonly(self): + return 'read only' + + class MockView(object): + model = MockModel + + self.validator = ModelFormValidator(MockView) + + + def test_property_fields_are_allowed_on_model_forms(self): + """Validation on ModelForms may include property fields that exist on the Model to be included in the input.""" + content = {'qwerty':'example', 'uiop': 'example', 'readonly': 'read only'} + self.assertEqual(self.validator.validate(content), content) + + def test_property_fields_are_not_required_on_model_forms(self): + """Validation on ModelForms does not require property fields that exist on the Model to be included in the input.""" + content = {'qwerty':'example', 'uiop': 'example'} + self.assertEqual(self.validator.validate(content), content) + + def test_extra_fields_not_allowed_on_model_forms(self): + """If some (otherwise valid) content includes fields that are not in the form then validation should fail. + It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up + broken clients more easily (eg submitting content with a misnamed field)""" + content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} + self.assertRaises(ResponseException, self.validator.validate, content) + + def test_validate_requires_fields_on_model_forms(self): + """If some (otherwise valid) content includes fields that are not in the form then validation should fail. + It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up + broken clients more easily (eg submitting content with a misnamed field)""" + content = {'readonly': 'read only'} + self.assertRaises(ResponseException, self.validator.validate, content) + + def test_validate_does_not_require_blankable_fields_on_model_forms(self): + """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" + content = {'qwerty':'example', 'readonly': 'read only'} + self.validator.validate(content) + + def test_model_form_validator_uses_model_forms(self): + self.assertTrue(isinstance(self.validator.get_bound_form(), forms.ModelForm)) -- cgit v1.2.3 From a1ed565081779e3f50e9f0ff280a813a46f3613d Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 11 Apr 2011 15:09:52 +0100 Subject: Cleanup --- djangorestframework/tests/validators.py | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index 1f14f710..a091cf29 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -13,21 +13,6 @@ class TestValidatorMixinInterfaces(TestCase): """Ensure the ValidatorMixin base class interface is as expected.""" self.assertRaises(NotImplementedError, BaseValidator(None).validate, None) - #def test_form_validator_mixin_interface(self): - # """Ensure the FormValidatorMixin interface is as expected.""" - # self.assertTrue(issubclass(FormValidator, BaseValidator)) - # getattr(FormValidator, 'form') - # getattr(FormValidator, 'validate') - - #def test_model_form_validator_mixin_interface(self): - # """Ensure the ModelFormValidatorMixin interface is as expected.""" - # self.assertTrue(issubclass(ModelFormValidator, FormValidator)) - # getattr(ModelFormValidator, 'model') - # getattr(ModelFormValidator, 'form') - # getattr(ModelFormValidator, 'fields') - # getattr(ModelFormValidator, 'exclude_fields') - # getattr(ModelFormValidator, 'validate') - class TestDisabledValidations(TestCase): """Tests on FormValidator with validation disabled by setting form to None""" -- cgit v1.2.3 From 349ffcaf5f03b55d8ffe92999814ba97da5ca870 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 11 Apr 2011 16:38:00 +0100 Subject: Rename mixins into Mixin class, rename ResponseException to ErrorResponse, remove NoContent --- djangorestframework/tests/validators.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index a091cf29..b6563db6 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -3,7 +3,7 @@ from django.db import models from django.test import TestCase from djangorestframework.compat import RequestFactory from djangorestframework.validators import BaseValidator, FormValidator, ModelFormValidator -from djangorestframework.response import ResponseException +from djangorestframework.response import ErrorResponse class TestValidatorMixinInterfaces(TestCase): @@ -81,7 +81,7 @@ class TestNonFieldErrors(TestCase): content = {'field1': 'example1', 'field2': 'example2'} try: FormValidator(view).validate(content) - except ResponseException, exc: + except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'errors': [MockForm.ERROR_TEXT]}) else: self.fail('ResourceException was not raised') #pragma: no cover @@ -115,14 +115,14 @@ class TestFormValidation(TestCase): def validation_failure_raises_response_exception(self, validator): """If form validation fails a ResourceException 400 (Bad Request) should be raised.""" content = {} - self.assertRaises(ResponseException, validator.validate, content) + self.assertRaises(ErrorResponse, validator.validate, content) def validation_does_not_allow_extra_fields_by_default(self, validator): """If some (otherwise valid) content includes fields that are not in the form then validation should fail. It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up broken clients more easily (eg submitting content with a misnamed field)""" content = {'qwerty': 'uiop', 'extra': 'extra'} - self.assertRaises(ResponseException, validator.validate, content) + self.assertRaises(ErrorResponse, validator.validate, content) def validation_allows_extra_fields_if_explicitly_set(self, validator): """If we include an allowed_extra_fields paramater on _validate, then allow fields with those names.""" @@ -139,7 +139,7 @@ class TestFormValidation(TestCase): content = {} try: validator.validate(content) - except ResponseException, exc: + except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'qwerty': ['This field is required.']}}) else: self.fail('ResourceException was not raised') #pragma: no cover @@ -149,7 +149,7 @@ class TestFormValidation(TestCase): content = {'qwerty': ''} try: validator.validate(content) - except ResponseException, exc: + except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'qwerty': ['This field is required.']}}) else: self.fail('ResourceException was not raised') #pragma: no cover @@ -159,7 +159,7 @@ class TestFormValidation(TestCase): content = {'qwerty': 'uiop', 'extra': 'extra'} try: validator.validate(content) - except ResponseException, exc: + except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'extra': ['This field does not exist.']}}) else: self.fail('ResourceException was not raised') #pragma: no cover @@ -169,7 +169,7 @@ class TestFormValidation(TestCase): content = {'qwerty': '', 'extra': 'extra'} try: validator.validate(content) - except ResponseException, exc: + except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'qwerty': ['This field is required.'], 'extra': ['This field does not exist.']}}) else: @@ -286,14 +286,14 @@ class TestModelFormValidator(TestCase): It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up broken clients more easily (eg submitting content with a misnamed field)""" content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} - self.assertRaises(ResponseException, self.validator.validate, content) + self.assertRaises(ErrorResponse, self.validator.validate, content) def test_validate_requires_fields_on_model_forms(self): """If some (otherwise valid) content includes fields that are not in the form then validation should fail. It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up broken clients more easily (eg submitting content with a misnamed field)""" content = {'readonly': 'read only'} - self.assertRaises(ResponseException, self.validator.validate, content) + self.assertRaises(ErrorResponse, self.validator.validate, content) def test_validate_does_not_require_blankable_fields_on_model_forms(self): """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" -- cgit v1.2.3 From d373b3a067796b8e181be9368fa24e89c572c45e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 4 May 2011 09:21:17 +0100 Subject: Decouple views and resources --- djangorestframework/tests/validators.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index b6563db6..52a675d2 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -4,6 +4,8 @@ from django.test import TestCase from djangorestframework.compat import RequestFactory from djangorestframework.validators import BaseValidator, FormValidator, ModelFormValidator from djangorestframework.response import ErrorResponse +from djangorestframework.views import BaseView +from djangorestframework.resource import Resource class TestValidatorMixinInterfaces(TestCase): @@ -20,7 +22,7 @@ class TestDisabledValidations(TestCase): def test_disabled_form_validator_returns_content_unchanged(self): """If the view's form attribute is None then FormValidator(view).validate(content) should just return the content unmodified.""" - class DisabledFormView(object): + class DisabledFormView(BaseView): form = None view = DisabledFormView() @@ -30,7 +32,7 @@ class TestDisabledValidations(TestCase): def test_disabled_form_validator_get_bound_form_returns_none(self): """If the view's form attribute is None on then FormValidator(view).get_bound_form(content) should just return None.""" - class DisabledFormView(object): + class DisabledFormView(BaseView): form = None view = DisabledFormView() @@ -39,11 +41,10 @@ class TestDisabledValidations(TestCase): def test_disabled_model_form_validator_returns_content_unchanged(self): - """If the view's form and model attributes are None then + """If the view's form is None and does not have a Resource with a model set then ModelFormValidator(view).validate(content) should just return the content unmodified.""" - class DisabledModelFormView(object): + class DisabledModelFormView(BaseView): form = None - model = None view = DisabledModelFormView() content = {'qwerty':'uiop'} @@ -51,13 +52,12 @@ class TestDisabledValidations(TestCase): def test_disabled_model_form_validator_get_bound_form_returns_none(self): """If the form attribute is None on FormValidatorMixin then get_bound_form(content) should just return None.""" - class DisabledModelFormView(object): - form = None + class DisabledModelFormView(BaseView): model = None view = DisabledModelFormView() content = {'qwerty':'uiop'} - self.assertEqual(ModelFormValidator(view).get_bound_form(content), None)# + self.assertEqual(ModelFormValidator(view).get_bound_form(content), None) class TestNonFieldErrors(TestCase): """Tests against form validation errors caused by non-field errors. (eg as might be caused by some custom form validation)""" @@ -84,7 +84,7 @@ class TestNonFieldErrors(TestCase): except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'errors': [MockForm.ERROR_TEXT]}) else: - self.fail('ResourceException was not raised') #pragma: no cover + self.fail('ErrorResponse was not raised') #pragma: no cover class TestFormValidation(TestCase): @@ -95,11 +95,11 @@ class TestFormValidation(TestCase): class MockForm(forms.Form): qwerty = forms.CharField(required=True) - class MockFormView(object): + class MockFormView(BaseView): form = MockForm validators = (FormValidator,) - class MockModelFormView(object): + class MockModelFormView(BaseView): form = MockForm validators = (ModelFormValidator,) @@ -264,9 +264,12 @@ class TestModelFormValidator(TestCase): @property def readonly(self): return 'read only' - - class MockView(object): + + class MockResource(Resource): model = MockModel + + class MockView(BaseView): + resource = MockResource self.validator = ModelFormValidator(MockView) -- cgit v1.2.3 From b5b231a874c7d8d54b1d3849cb95337f15bac9c6 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 12 May 2011 15:11:14 +0100 Subject: yet more API cleanup --- djangorestframework/tests/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index 52a675d2..fb09c5ba 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -5,7 +5,7 @@ from djangorestframework.compat import RequestFactory from djangorestframework.validators import BaseValidator, FormValidator, ModelFormValidator from djangorestframework.response import ErrorResponse from djangorestframework.views import BaseView -from djangorestframework.resource import Resource +from djangorestframework.resources import Resource class TestValidatorMixinInterfaces(TestCase): -- cgit v1.2.3 From 3039f6f6c29d0b469810adcd6ba450361f2a16de Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 16 May 2011 16:52:39 +0100 Subject: validators tests -> resources tests --- djangorestframework/tests/validators.py | 139 +++++++++++++++++--------------- 1 file changed, 74 insertions(+), 65 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index fb09c5ba..32fb1002 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -2,62 +2,62 @@ from django import forms from django.db import models from django.test import TestCase from djangorestframework.compat import RequestFactory -from djangorestframework.validators import BaseValidator, FormValidator, ModelFormValidator +from djangorestframework.resources import Resource, FormResource, ModelResource from djangorestframework.response import ErrorResponse from djangorestframework.views import BaseView from djangorestframework.resources import Resource -class TestValidatorMixinInterfaces(TestCase): - """Basic tests to ensure that the ValidatorMixin classes expose the expected interfaces""" - - def test_validator_mixin_interface(self): - """Ensure the ValidatorMixin base class interface is as expected.""" - self.assertRaises(NotImplementedError, BaseValidator(None).validate, None) - class TestDisabledValidations(TestCase): """Tests on FormValidator with validation disabled by setting form to None""" def test_disabled_form_validator_returns_content_unchanged(self): - """If the view's form attribute is None then FormValidator(view).validate(content) + """If the view's form attribute is None then FormValidator(view).validate_request(content, None) should just return the content unmodified.""" - class DisabledFormView(BaseView): + class DisabledFormResource(FormResource): form = None - view = DisabledFormView() + class MockView(BaseView): + resource = DisabledFormResource + + view = MockView() content = {'qwerty':'uiop'} - self.assertEqual(FormValidator(view).validate(content), content) + self.assertEqual(FormResource(view).validate_request(content, None), content) def test_disabled_form_validator_get_bound_form_returns_none(self): """If the view's form attribute is None on then FormValidator(view).get_bound_form(content) should just return None.""" - class DisabledFormView(BaseView): + class DisabledFormResource(FormResource): form = None - view = DisabledFormView() + class MockView(BaseView): + resource = DisabledFormResource + + view = MockView() content = {'qwerty':'uiop'} - self.assertEqual(FormValidator(view).get_bound_form(content), None) + self.assertEqual(FormResource(view).get_bound_form(content), None) def test_disabled_model_form_validator_returns_content_unchanged(self): """If the view's form is None and does not have a Resource with a model set then - ModelFormValidator(view).validate(content) should just return the content unmodified.""" + ModelFormValidator(view).validate_request(content, None) should just return the content unmodified.""" + class DisabledModelFormView(BaseView): - form = None + resource = ModelResource view = DisabledModelFormView() content = {'qwerty':'uiop'} - self.assertEqual(ModelFormValidator(view).get_bound_form(content), None)# + self.assertEqual(ModelResource(view).get_bound_form(content), None)# def test_disabled_model_form_validator_get_bound_form_returns_none(self): """If the form attribute is None on FormValidatorMixin then get_bound_form(content) should just return None.""" class DisabledModelFormView(BaseView): - model = None + resource = ModelResource view = DisabledModelFormView() content = {'qwerty':'uiop'} - self.assertEqual(ModelFormValidator(view).get_bound_form(content), None) + self.assertEqual(ModelResource(view).get_bound_form(content), None) class TestNonFieldErrors(TestCase): """Tests against form validation errors caused by non-field errors. (eg as might be caused by some custom form validation)""" @@ -74,13 +74,16 @@ class TestNonFieldErrors(TestCase): raise forms.ValidationError(self.ERROR_TEXT) return self.cleaned_data #pragma: no cover - class MockView(object): + class MockResource(FormResource): form = MockForm + class MockView(BaseView): + pass + view = MockView() content = {'field1': 'example1', 'field2': 'example2'} try: - FormValidator(view).validate(content) + MockResource(view).validate_request(content, None) except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'errors': [MockForm.ERROR_TEXT]}) else: @@ -95,14 +98,20 @@ class TestFormValidation(TestCase): class MockForm(forms.Form): qwerty = forms.CharField(required=True) - class MockFormView(BaseView): + class MockFormResource(FormResource): + form = MockForm + + class MockModelResource(ModelResource): form = MockForm - validators = (FormValidator,) + + class MockFormView(BaseView): + resource = MockFormResource class MockModelFormView(BaseView): - form = MockForm - validators = (ModelFormValidator,) - + resource = MockModelResource + + self.MockFormResource = MockFormResource + self.MockModelResource = MockModelResource self.MockFormView = MockFormView self.MockModelFormView = MockModelFormView @@ -110,35 +119,35 @@ class TestFormValidation(TestCase): def validation_returns_content_unchanged_if_already_valid_and_clean(self, validator): """If the content is already valid and clean then validate(content) should just return the content unmodified.""" content = {'qwerty':'uiop'} - self.assertEqual(validator.validate(content), content) + self.assertEqual(validator.validate_request(content, None), content) def validation_failure_raises_response_exception(self, validator): """If form validation fails a ResourceException 400 (Bad Request) should be raised.""" - content = {} - self.assertRaises(ErrorResponse, validator.validate, content) + content = {} + self.assertRaises(ErrorResponse, validator.validate_request, content, None) def validation_does_not_allow_extra_fields_by_default(self, validator): """If some (otherwise valid) content includes fields that are not in the form then validation should fail. It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up broken clients more easily (eg submitting content with a misnamed field)""" content = {'qwerty': 'uiop', 'extra': 'extra'} - self.assertRaises(ErrorResponse, validator.validate, content) + self.assertRaises(ErrorResponse, validator.validate_request, content, None) def validation_allows_extra_fields_if_explicitly_set(self, validator): """If we include an allowed_extra_fields paramater on _validate, then allow fields with those names.""" content = {'qwerty': 'uiop', 'extra': 'extra'} - validator._validate(content, allowed_extra_fields=('extra',)) + validator._validate(content, None, allowed_extra_fields=('extra',)) 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'} - self.assertEqual(validator._validate(content, allowed_extra_fields=('extra',)), content) + self.assertEqual(validator._validate(content, None, allowed_extra_fields=('extra',)), content) def validation_failed_due_to_no_content_returns_appropriate_message(self, validator): """If validation fails due to no content, ensure the response contains a single non-field error""" content = {} try: - validator.validate(content) + validator.validate_request(content, None) except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'qwerty': ['This field is required.']}}) else: @@ -148,7 +157,7 @@ class TestFormValidation(TestCase): """If validation fails due to a field error, ensure the response contains a single field error""" content = {'qwerty': ''} try: - validator.validate(content) + validator.validate_request(content, None) except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'qwerty': ['This field is required.']}}) else: @@ -158,7 +167,7 @@ class TestFormValidation(TestCase): """If validation fails due to an invalid field, ensure the response contains a single field error""" content = {'qwerty': 'uiop', 'extra': 'extra'} try: - validator.validate(content) + validator.validate_request(content, None) except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'extra': ['This field does not exist.']}}) else: @@ -168,87 +177,87 @@ class TestFormValidation(TestCase): """If validation for multiple reasons, ensure the response contains each error""" content = {'qwerty': '', 'extra': 'extra'} try: - validator.validate(content) + validator.validate_request(content, None) except ErrorResponse, exc: self.assertEqual(exc.response.raw_content, {'field-errors': {'qwerty': ['This field is required.'], 'extra': ['This field does not exist.']}}) else: self.fail('ResourceException was not raised') #pragma: no cover - # Tests on FormValidtionMixin + # Tests on FormResource def test_form_validation_returns_content_unchanged_if_already_valid_and_clean(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_returns_content_unchanged_if_already_valid_and_clean(validator) def test_form_validation_failure_raises_response_exception(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_failure_raises_response_exception(validator) def test_validation_does_not_allow_extra_fields_by_default(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_does_not_allow_extra_fields_by_default(validator) def test_validation_allows_extra_fields_if_explicitly_set(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_allows_extra_fields_if_explicitly_set(validator) def test_validation_does_not_require_extra_fields_if_explicitly_set(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_does_not_require_extra_fields_if_explicitly_set(validator) def test_validation_failed_due_to_no_content_returns_appropriate_message(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_failed_due_to_no_content_returns_appropriate_message(validator) def test_validation_failed_due_to_field_error_returns_appropriate_message(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_failed_due_to_field_error_returns_appropriate_message(validator) def test_validation_failed_due_to_invalid_field_returns_appropriate_message(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_failed_due_to_invalid_field_returns_appropriate_message(validator) def test_validation_failed_due_to_multiple_errors_returns_appropriate_message(self): - validator = FormValidator(self.MockFormView()) + validator = self.MockFormResource(self.MockFormView()) self.validation_failed_due_to_multiple_errors_returns_appropriate_message(validator) - # Same tests on ModelFormValidtionMixin + # Same tests on ModelResource def test_modelform_validation_returns_content_unchanged_if_already_valid_and_clean(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_returns_content_unchanged_if_already_valid_and_clean(validator) def test_modelform_validation_failure_raises_response_exception(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_failure_raises_response_exception(validator) def test_modelform_validation_does_not_allow_extra_fields_by_default(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_does_not_allow_extra_fields_by_default(validator) def test_modelform_validation_allows_extra_fields_if_explicitly_set(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_allows_extra_fields_if_explicitly_set(validator) def test_modelform_validation_does_not_require_extra_fields_if_explicitly_set(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_does_not_require_extra_fields_if_explicitly_set(validator) def test_modelform_validation_failed_due_to_no_content_returns_appropriate_message(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_failed_due_to_no_content_returns_appropriate_message(validator) def test_modelform_validation_failed_due_to_field_error_returns_appropriate_message(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_failed_due_to_field_error_returns_appropriate_message(validator) def test_modelform_validation_failed_due_to_invalid_field_returns_appropriate_message(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_failed_due_to_invalid_field_returns_appropriate_message(validator) def test_modelform_validation_failed_due_to_multiple_errors_returns_appropriate_message(self): - validator = ModelFormValidator(self.MockModelFormView()) + validator = self.MockModelResource(self.MockModelFormView()) self.validation_failed_due_to_multiple_errors_returns_appropriate_message(validator) @@ -265,43 +274,43 @@ class TestModelFormValidator(TestCase): def readonly(self): return 'read only' - class MockResource(Resource): + class MockResource(ModelResource): model = MockModel class MockView(BaseView): resource = MockResource - self.validator = ModelFormValidator(MockView) + self.validator = MockResource(MockView) def test_property_fields_are_allowed_on_model_forms(self): """Validation on ModelForms may include property fields that exist on the Model to be included in the input.""" content = {'qwerty':'example', 'uiop': 'example', 'readonly': 'read only'} - self.assertEqual(self.validator.validate(content), content) + self.assertEqual(self.validator.validate_request(content, None), content) def test_property_fields_are_not_required_on_model_forms(self): """Validation on ModelForms does not require property fields that exist on the Model to be included in the input.""" content = {'qwerty':'example', 'uiop': 'example'} - self.assertEqual(self.validator.validate(content), content) + self.assertEqual(self.validator.validate_request(content, None), content) def test_extra_fields_not_allowed_on_model_forms(self): """If some (otherwise valid) content includes fields that are not in the form then validation should fail. It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up broken clients more easily (eg submitting content with a misnamed field)""" - content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} - self.assertRaises(ErrorResponse, self.validator.validate, content) + content = {'qwerty': 'example', 'uiop':'example', 'readonly': 'read only', 'extra': 'extra'} + self.assertRaises(ErrorResponse, self.validator.validate_request, content, None) def test_validate_requires_fields_on_model_forms(self): """If some (otherwise valid) content includes fields that are not in the form then validation should fail. It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up broken clients more easily (eg submitting content with a misnamed field)""" content = {'readonly': 'read only'} - self.assertRaises(ErrorResponse, self.validator.validate, content) + self.assertRaises(ErrorResponse, self.validator.validate_request, content, None) def test_validate_does_not_require_blankable_fields_on_model_forms(self): """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" content = {'qwerty':'example', 'readonly': 'read only'} - self.validator.validate(content) + self.validator.validate_request(content, None) def test_model_form_validator_uses_model_forms(self): self.assertTrue(isinstance(self.validator.get_bound_form(), forms.ModelForm)) -- cgit v1.2.3 From 370274f5640d55ef71422f7a2440710a43ff900e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 24 May 2011 10:27:24 +0100 Subject: Allow views to return HttpResponses. Add initial() hook method --- djangorestframework/tests/validators.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'djangorestframework/tests/validators.py') diff --git a/djangorestframework/tests/validators.py b/djangorestframework/tests/validators.py index 32fb1002..a1e5d2d7 100644 --- a/djangorestframework/tests/validators.py +++ b/djangorestframework/tests/validators.py @@ -4,7 +4,7 @@ from django.test import TestCase from djangorestframework.compat import RequestFactory from djangorestframework.resources import Resource, FormResource, ModelResource from djangorestframework.response import ErrorResponse -from djangorestframework.views import BaseView +from djangorestframework.views import View from djangorestframework.resources import Resource @@ -18,7 +18,7 @@ class TestDisabledValidations(TestCase): class DisabledFormResource(FormResource): form = None - class MockView(BaseView): + class MockView(View): resource = DisabledFormResource view = MockView() @@ -31,7 +31,7 @@ class TestDisabledValidations(TestCase): class DisabledFormResource(FormResource): form = None - class MockView(BaseView): + class MockView(View): resource = DisabledFormResource view = MockView() @@ -43,7 +43,7 @@ class TestDisabledValidations(TestCase): """If the view's form is None and does not have a Resource with a model set then ModelFormValidator(view).validate_request(content, None) should just return the content unmodified.""" - class DisabledModelFormView(BaseView): + class DisabledModelFormView(View): resource = ModelResource view = DisabledModelFormView() @@ -52,7 +52,7 @@ class TestDisabledValidations(TestCase): def test_disabled_model_form_validator_get_bound_form_returns_none(self): """If the form attribute is None on FormValidatorMixin then get_bound_form(content) should just return None.""" - class DisabledModelFormView(BaseView): + class DisabledModelFormView(View): resource = ModelResource view = DisabledModelFormView() @@ -77,7 +77,7 @@ class TestNonFieldErrors(TestCase): class MockResource(FormResource): form = MockForm - class MockView(BaseView): + class MockView(View): pass view = MockView() @@ -104,10 +104,10 @@ class TestFormValidation(TestCase): class MockModelResource(ModelResource): form = MockForm - class MockFormView(BaseView): + class MockFormView(View): resource = MockFormResource - class MockModelFormView(BaseView): + class MockModelFormView(View): resource = MockModelResource self.MockFormResource = MockFormResource @@ -277,7 +277,7 @@ class TestModelFormValidator(TestCase): class MockResource(ModelResource): model = MockModel - class MockView(BaseView): + class MockView(View): resource = MockResource self.validator = MockResource(MockView) -- cgit v1.2.3