Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #74 from yunmanger1/x-http-method-override

Fixing #73
  • Loading branch information...
commit 03c1b1521a0a67081289e3940c2fb274263802a7 2 parents 1a7e291 + 2d4fba8
@danstovall danstovall authored
View
11 tastypie_mongoengine/resources.py
@@ -414,11 +414,18 @@ def _wrap_request(self, request, fun):
def dispatch(self, request_type, request, **kwargs):
# We process specially only requests with payload
+ if 'HTTP_X_HTTP_METHOD_OVERRIDE' in request.META:
+ the_method = request.META['HTTP_X_HTTP_METHOD_OVERRIDE'].lower()
+ if the_method == 'delete':
+ return super(MongoEngineResource, self).dispatch(request_type, request, **kwargs)
+ else:
+ the_method = request.method.lower()
+
if not request.body:
- assert request.method.lower() not in ('put', 'post', 'patch'), request.method
+ assert the_method not in ('put', 'post', 'patch'), the_method
return super(MongoEngineResource, self).dispatch(request_type, request, **kwargs)
- assert request.method.lower() in ('put', 'post', 'patch'), request.method
+ assert the_method in ('put', 'post', 'patch'), the_method + ":" + request.body
return self._wrap_request(request, lambda: super(MongoEngineResource, self).dispatch(request_type, request, **kwargs))
View
17 tests/test_project/test_app/tests/test_basic.py
@@ -484,6 +484,23 @@ def test_basic(self):
response = self.c.get(person1_uri)
self.assertEqual(response.status_code, 404)
+ # Testing x-override
+
+ response = self.c.post(self.resourceListURI('person'), '{"name": "Person X"}', content_type='application/json')
+ self.assertEqual(response.status_code, 201)
+
+ person2_uri = response['location']
+
+ # Testing PATCH with x-override
+
+ response = self.c.post(person2_uri, '{"name": "Person X PATCHED"}', HTTP_X_HTTP_METHOD_OVERRIDE='patch', content_type='application/json')
+ self.assertEqual(response.status_code, 202)
+
+ # Testing DELETE with x-override
+
+ response = self.c.post(person2_uri, HTTP_X_HTTP_METHOD_OVERRIDE='delete')
+ self.assertEqual(response.status_code, 204)
+
def test_objectclass(self):
response = self.c.get(self.resourceListURI('personobjectclass'))
Please sign in to comment.
Something went wrong with that request. Please try again.