Skip to content

Commit 27859c8

Browse files
committed
Resource.build_response() throws a NotImplementedError by default
1 parent a4994eb commit 27859c8

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

Diff for: restless/dj.py

-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ def as_detail(self, *args, **kwargs):
2727
return csrf_exempt(super(DjangoResource, self).as_detail(*args, **kwargs))
2828

2929
def is_debug(self):
30-
# By default, Django-esque.
3130
return settings.DEBUG
3231

3332
def build_response(self, data, status=200):
34-
# By default, Django-esque.
3533
resp = HttpResponse(data, content_type='application/json')
3634
resp.status_code = status
3735
return resp

Diff for: restless/resources.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .constants import OK, CREATED, ACCEPTED, NO_CONTENT
55
from .data import Data
66
from .exceptions import MethodNotImplemented, Unauthorized
7-
from .preparers import Preparer, FieldsPreparer
7+
from .preparers import Preparer
88
from .serializers import JSONSerializer
99
from .utils import format_traceback
1010

@@ -145,9 +145,8 @@ def request_method(self):
145145
"""
146146
Returns the HTTP method for the current request.
147147
148-
The default implementation is Django-specific, so if you're integrating
149-
with a new web framework, you'll need to override this method within
150-
your subclass.
148+
If you're integrating with a new web framework, you might need to
149+
override this method within your subclass.
151150
152151
:returns: The HTTP method in uppercase
153152
:rtype: string
@@ -161,9 +160,8 @@ def request_body(self):
161160
162161
Useful for deserializing the content the user sent (typically JSON).
163162
164-
The default implementation is Django-specific, so if you're integrating
165-
with a new web framework, you'll need to override this method within
166-
your subclass.
163+
If you're integrating with a new web framework, you might need to
164+
override this method within your subclass.
167165
168166
:returns: The body of the request
169167
:rtype: string
@@ -175,9 +173,8 @@ def build_response(self, data, status=200):
175173
"""
176174
Given some data, generates an HTTP response.
177175
178-
The default implementation is Django-specific, so if you're integrating
179-
with a new web framework, you'll need to override this method within
180-
your subclass.
176+
If you're integrating with a new web framework, you **MUST**
177+
override this method within your subclass.
181178
182179
:param data: The body of the response to send
183180
:type data: string
@@ -188,13 +185,7 @@ def build_response(self, data, status=200):
188185
189186
:returns: A response object
190187
"""
191-
# TODO: Remove the Django.
192-
# This should be plain old WSGI by default, if possible.
193-
# By default, Django-esque.
194-
from django.http import HttpResponse
195-
resp = HttpResponse(data, content_type='application/json')
196-
resp.status_code = status
197-
return resp
188+
raise NotImplementedError()
198189

199190
def build_error(self, err):
200191
"""

Diff for: tests/test_resources.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
from .fakes import FakeHttpRequest, FakeHttpResponse
1010

1111

12-
class NonDjangoResource(Resource):
13-
# Because the default implementation is a tiny-bit Django-specific,
14-
# we're faking some things here.
12+
class GenericResource(Resource):
1513
def build_response(self, data, status=200):
1614
resp = FakeHttpResponse(data, content_type='application/json')
1715
resp.status_code = status
@@ -21,11 +19,11 @@ def build_response(self, data, status=200):
2119
def is_authenticated(self):
2220
if self.endpoint == 'list':
2321
return False
24-
return super(NonDjangoResource, self).is_authenticated()
22+
return super(GenericResource, self).is_authenticated()
2523

2624

2725
class ResourceTestCase(unittest.TestCase):
28-
resource_class = NonDjangoResource
26+
resource_class = GenericResource
2927

3028
def setUp(self):
3129
super(ResourceTestCase, self).setUp()

0 commit comments

Comments
 (0)