If you ever need to create a Django request for testing purposes you can use this:
import urllib
from urlparse import urlparse, urlunparse, urlsplit
from django.test.client import FakePayload
from django.conf import settings
from django.conf.urls.defaults import *
from django.http import HttpRequest, HttpResponse
from django.utils.http import urlencode
from django.core.handlers.wsgi import WSGIRequest
from django.http import SimpleCookie
def create_request(path, data={}, method="GET"):
parsed = urlparse(path)
environ = {
'HTTP_COOKIE': SimpleCookie().output(header='', sep='; '),
'REMOTE_ADDR': '127.0.0.1',
'SCRIPT_NAME': '',
'SERVER_NAME': 'testserver',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.1',
'wsgi.version': (1,0),
'wsgi.url_scheme': 'http',
'wsgi.errors': None,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'CONTENT_TYPE': 'text/html; charset=utf-8',
'PATH_INFO': urllib.unquote(parsed[2]),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': method,
'wsgi.input': FakePayload('')
}
return WSGIRequest(environ)
It is pretty much a copy&paste from different parts of Django source code. Once you get this dummy request you can invoke actions directly (functions from your views.py)