mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
Remove last bits of ParserMixin
This commit is contained in:
parent
92b5a455da
commit
941742593c
|
@ -24,10 +24,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from cgi import parse_qs
|
from cgi import parse_qs
|
||||||
|
|
||||||
class ParserMixin(object):
|
|
||||||
parsers = ()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseParser(object):
|
class BaseParser(object):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.http.multipartparser import LimitBytes
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
class RequestMixin(object):
|
class RequestMixin(object):
|
||||||
"""Delegate class that supplements an HttpRequest object with additional behaviour."""
|
"""Mixin behaviour to deal with requests."""
|
||||||
|
|
||||||
USE_FORM_OVERLOADING = True
|
USE_FORM_OVERLOADING = True
|
||||||
METHOD_PARAM = "_method"
|
METHOD_PARAM = "_method"
|
||||||
|
|
|
@ -3,7 +3,6 @@ from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from djangorestframework.compat import View
|
from djangorestframework.compat import View
|
||||||
from djangorestframework.emitters import EmitterMixin
|
from djangorestframework.emitters import EmitterMixin
|
||||||
from djangorestframework.parsers import ParserMixin
|
|
||||||
from djangorestframework.authenticators import AuthenticatorMixin
|
from djangorestframework.authenticators import AuthenticatorMixin
|
||||||
from djangorestframework.validators import FormValidatorMixin
|
from djangorestframework.validators import FormValidatorMixin
|
||||||
from djangorestframework.response import Response, ResponseException
|
from djangorestframework.response import Response, ResponseException
|
||||||
|
@ -19,7 +18,7 @@ from djangorestframework import emitters, parsers, authenticators, status
|
||||||
__all__ = ['Resource']
|
__all__ = ['Resource']
|
||||||
|
|
||||||
|
|
||||||
class Resource(EmitterMixin, ParserMixin, AuthenticatorMixin, FormValidatorMixin, RequestMixin, View):
|
class Resource(EmitterMixin, AuthenticatorMixin, FormValidatorMixin, RequestMixin, View):
|
||||||
"""Handles incoming requests and maps them to REST operations,
|
"""Handles incoming requests and maps them to REST operations,
|
||||||
performing authentication, input deserialization, input validation, output serialization."""
|
performing authentication, input deserialization, input validation, output serialization."""
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
# TODO: finish off the refactoring
|
"""
|
||||||
|
Tests for content parsing, and form-overloaded content parsing.
|
||||||
|
"""
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from djangorestframework.compat import RequestFactory
|
from djangorestframework.compat import RequestFactory
|
||||||
from djangorestframework.request import RequestMixin
|
from djangorestframework.request import RequestMixin
|
||||||
|
@ -9,27 +11,6 @@ class TestContentParsing(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.req = RequestFactory()
|
self.req = RequestFactory()
|
||||||
|
|
||||||
# # Interface tests
|
|
||||||
#
|
|
||||||
# def test_content_mixin_interface(self):
|
|
||||||
# """Ensure the ContentMixin interface is as expected."""
|
|
||||||
# self.assertRaises(NotImplementedError, ContentMixin().determine_content, None)
|
|
||||||
#
|
|
||||||
# def test_standard_content_mixin_interface(self):
|
|
||||||
# """Ensure the OverloadedContentMixin interface is as expected."""
|
|
||||||
# self.assertTrue(issubclass(StandardContentMixin, ContentMixin))
|
|
||||||
# getattr(StandardContentMixin, 'determine_content')
|
|
||||||
#
|
|
||||||
# def test_overloaded_content_mixin_interface(self):
|
|
||||||
# """Ensure the OverloadedContentMixin interface is as expected."""
|
|
||||||
# self.assertTrue(issubclass(OverloadedContentMixin, ContentMixin))
|
|
||||||
# getattr(OverloadedContentMixin, 'CONTENT_PARAM')
|
|
||||||
# getattr(OverloadedContentMixin, 'CONTENTTYPE_PARAM')
|
|
||||||
# getattr(OverloadedContentMixin, 'determine_content')
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# # Common functionality to test with both StandardContentMixin and OverloadedContentMixin
|
|
||||||
#
|
|
||||||
def ensure_determines_no_content_GET(self, view):
|
def ensure_determines_no_content_GET(self, view):
|
||||||
"""Ensure view.RAW_CONTENT returns None for GET request with no content."""
|
"""Ensure view.RAW_CONTENT returns None for GET request with no content."""
|
||||||
view.request = self.req.get('/')
|
view.request = self.req.get('/')
|
||||||
|
@ -85,28 +66,6 @@ class TestContentParsing(TestCase):
|
||||||
"""Ensure view.RAW_CONTENT returns content for PUT request with non-form content."""
|
"""Ensure view.RAW_CONTENT returns content for PUT request with non-form content."""
|
||||||
self.ensure_determines_non_form_content_PUT(RequestMixin())
|
self.ensure_determines_non_form_content_PUT(RequestMixin())
|
||||||
|
|
||||||
# # OverloadedContentMixin behavioural tests
|
|
||||||
#
|
|
||||||
# def test_overloaded_behaviour_determines_no_content_GET(self):
|
|
||||||
# """Ensure StandardContentMixin.determine_content(request) returns None for GET request with no content."""
|
|
||||||
# self.ensure_determines_no_content_GET(OverloadedContentMixin())
|
|
||||||
#
|
|
||||||
# def test_overloaded_behaviour_determines_form_content_POST(self):
|
|
||||||
# """Ensure StandardContentMixin.determine_content(request) returns content for POST request with content."""
|
|
||||||
# self.ensure_determines_form_content_POST(OverloadedContentMixin())
|
|
||||||
#
|
|
||||||
# def test_overloaded_behaviour_determines_non_form_content_POST(self):
|
|
||||||
# """Ensure StandardContentMixin.determine_content(request) returns (content type, content) for POST request with content."""
|
|
||||||
# self.ensure_determines_non_form_content_POST(OverloadedContentMixin())
|
|
||||||
#
|
|
||||||
# def test_overloaded_behaviour_determines_form_content_PUT(self):
|
|
||||||
# """Ensure StandardContentMixin.determine_content(request) returns content for PUT request with content."""
|
|
||||||
# self.ensure_determines_form_content_PUT(OverloadedContentMixin())
|
|
||||||
#
|
|
||||||
# def test_overloaded_behaviour_determines_non_form_content_PUT(self):
|
|
||||||
# """Ensure StandardContentMixin.determine_content(request) returns (content type, content) for PUT request with content."""
|
|
||||||
# self.ensure_determines_non_form_content_PUT(OverloadedContentMixin())
|
|
||||||
#
|
|
||||||
def test_overloaded_behaviour_allows_content_tunnelling(self):
|
def test_overloaded_behaviour_allows_content_tunnelling(self):
|
||||||
"""Ensure request.RAW_CONTENT returns content for overloaded POST request"""
|
"""Ensure request.RAW_CONTENT returns content for overloaded POST request"""
|
||||||
content = 'qwerty'
|
content = 'qwerty'
|
||||||
|
@ -118,9 +77,3 @@ class TestContentParsing(TestCase):
|
||||||
view.parsers = (PlainTextParser,)
|
view.parsers = (PlainTextParser,)
|
||||||
view.perform_form_overloading()
|
view.perform_form_overloading()
|
||||||
self.assertEqual(view.RAW_CONTENT, content)
|
self.assertEqual(view.RAW_CONTENT, content)
|
||||||
|
|
||||||
# def test_overloaded_behaviour_allows_content_tunnelling_content_type_not_set(self):
|
|
||||||
# """Ensure determine_content(request) returns (None, content) for overloaded POST request with content type not set"""
|
|
||||||
# content = 'qwerty'
|
|
||||||
# request = self.req.post('/', {OverloadedContentMixin.CONTENT_PARAM: content})
|
|
||||||
# self.assertEqual(OverloadedContentMixin().determine_content(request), (None, content))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user