Skip to content

Instantly share code, notes, and snippets.

@marsam
Created May 2, 2013 20:36
Show Gist options
  • Select an option

  • Save marsam/5505214 to your computer and use it in GitHub Desktop.

Select an option

Save marsam/5505214 to your computer and use it in GitHub Desktop.
from django import http
from django.conf import settings
from django.utils.importlib import import_module
class DummyRequest(http.HttpRequest):
def __init__(self, POST=None):
super(DummyRequest, self).__init__()
self.method = POST and "POST" or "GET"
if POST is not None:
self.POST.update(POST)
self.session = {}
self._dont_enforce_csrf_checks = True
def get_request(*args, **kwargs):
request = DummyRequest(*args, **kwargs)
engine = import_module(settings.SESSION_ENGINE)
request.session = engine.SessionStore(None)
return request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment