Esempio n. 1
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)
Esempio n. 2
0
    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 DisabledFormResource(FormResource):
            form = None

        class MockView(View):
            resource = DisabledFormResource

        view = MockView()
        content = {'qwerty': 'uiop'}
        self.assertEqual(FormResource(view).get_bound_form(content), None)
Esempio n. 3
0
    def test_disabled_form_validator_returns_content_unchanged(self):
        """If the view's form attribute is None then FormValidator(view).validate_request(content, None)
        should just return the content unmodified."""
        class DisabledFormResource(FormResource):
            form = None

        class MockView(View):
            resource = DisabledFormResource

        view = MockView()
        content = {'qwerty': 'uiop'}
        self.assertEqual(
            FormResource(view).validate_request(content, None), content)