Skip to content

Instantly share code, notes, and snippets.

@niwinz
Created January 19, 2013 23:44
Show Gist options
  • Save niwinz/4575855 to your computer and use it in GitHub Desktop.
Save niwinz/4575855 to your computer and use it in GitHub Desktop.
Support for patch method to django client.
from django.test import client
# Call this function on head of your test file.
def patch_request_factory():
def _method(self, path, data='', content_type='application/octet-stream', follow=False, **extra):
response = self.generic("PATCH", path, data, content_type, **extra)
if follow:
response = self._handle_redirects(response, **extra)
return response
if not hasattr(client, "_patched"):
client._patched = True
client.Client.patch = _method
@ratpik
Copy link

ratpik commented Oct 14, 2013

This is a good solution for django >= 1.5. self.generic doesn't exist in django <=1.4. So this throws an error. An alternative that works is this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment