tags:

views:

36

answers:

0

Hi everyone, I am running django on twisted. I have a special variable which is my engine being passed to each request. Take a loook at the following code:

# Django setup
sys.path.append("shoout_web")
os.environ['DJANGO_SETTINGS_MODULE'] = 'shoout_web.settings'
from django.core.handlers.wsgi import WSGIHandler

def wsgi_resource():
    pool = threadpool.ThreadPool()
    pool.start()
    # Allow Ctrl-C to get you out cleanly:
    reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)

    generic = WSGIHandler()
    def wrapper(environ, start_response):
        environ['engine'] = engine
        return generic(environ, start_response)

    wsgi_resource = wsgi.WSGIResource(reactor, pool, wrapper)
    return wsgi_resource

wsgi_root = wsgi_resource()

reactor.listenTCP(DJANGO_PORT, server.Site(wsgi_root, logPath=os.path.join(log_dir, '.django.log')))

Note the line " environ['engine'] = engine " Right now I am interested in writing test all my django views. How should I go about doing this?

Sample view function:

def push_message(request):
    engine = request.META['engine'] 
    if request.method == "POST":
        user_hexid = request.session['user_hexid']
        room_hexid = request.POST['room_hexid']
        message_body = request.POST['message_body']
        ret = blockingCallFromThread( reactor, engine.push_public_message, user_hexid, room_hexid, message_body)
        return HttpResponse(cjson.encode( {'thread_hexid':ret} ))

EDIT: Just to clear up some doubts: I don't think I am able to put that engine within settings because the engine is actually a twisted server which is listening on a specific port