Skip to content

Instantly share code, notes, and snippets.

@jacob414
Created November 14, 2011 11:02
Show Gist options
  • Save jacob414/1363730 to your computer and use it in GitHub Desktop.
Save jacob414/1363730 to your computer and use it in GitHub Desktop.
Fake a Django HTTP request for simpler testing purposes
from StringIO import StringIO
from django.core.handlers.wsgi import WSGIRequest
def fake_get(path='/', user=None):
req = WSGIRequest({
'REQUEST_METHOD': 'GET',
'PATH_INFO': path,
'wsgi.input': StringIO()})
from django.contrib.auth.models import AnonymousUser
req.user = AnonymousUser() if user is None else user
return req
@davidcp90
Copy link

Thanks man it was super useful

@mokgadirasekgala
Copy link

thanks a mil :)

@ivermac
Copy link

ivermac commented Jul 18, 2018

Thanks!!

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