コード例 #1
0
    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(View):
            resource = ModelResource

        view = DisabledModelFormView()
        content = {'qwerty': 'uiop'}
        self.assertEqual(ModelResource(view).get_bound_form(content), None)
コード例 #2
0
    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_request(content, None) should just return the content unmodified."""
        class DisabledModelFormView(View):
            resource = ModelResource

        view = DisabledModelFormView()
        content = {'qwerty': 'uiop'}
        self.assertEqual(ModelResource(view).get_bound_form(content), None)
コード例 #3
0
 def _resource(self):
     if self.resource:
         return self.resource(self)
     elif getattr(self, 'model', None):
         return ModelResource(self)
     elif getattr(self, 'form', None):
         return FormResource(self)
     elif getattr(self, '%s_form' % self.method.lower(), None):
         return FormResource(self)
     return Resource(self)