Created
November 14, 2011 11:02
-
-
Save jacob414/1363730 to your computer and use it in GitHub Desktop.
Fake a Django HTTP request for simpler testing purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
thanks a mil :)
Thanks!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man it was super useful