0
我正在運行django上扭曲。我有一個特殊的變量,這是我的引擎被傳遞給每個請求。以一個loook下面的代碼:Django測試 - 我現在怎麼做?
# 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')))
注行「ENVIRON [‘引擎’] =發動機」 現在我感興趣的寫作測試所有我的Django的看法。我應該如何去做這件事?
樣品查看功能:
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}))
編輯: 只是爲了澄清一些疑惑: 我不認爲我能夠把發動機設置中,因爲發動機實際上是一個扭曲的服務器是監聽特定的端口