Created
November 28, 2012 21:08
-
-
Save majgis/4164503 to your computer and use it in GitHub Desktop.
Fake Django WSGIRequest Object
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 django.core.handlers.wsgi import WSGIRequest | |
from StringIO import StringIO | |
from django.contrib.auth.models import AnonymousUser | |
def GetFakeRequest(path='/', user=None): | |
""" Construct a fake request(WSGIRequest) object""" | |
req = WSGIRequest({ | |
'REQUEST_METHOD': 'GET', | |
'PATH_INFO': path, | |
'wsgi.input': StringIO()}) | |
req.user = AnonymousUser() if user is None else user | |
return req |
Thanks
*py 3: from io import StringIO
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great! Thank you so much!