开发者

How do I run django test case?

I am using twisted to pass in a variable into my django开发者_高级运维 environment so I have to run the twisted server. Hence when I am testing my django app I really need to run the twisted code

it runs something like this:

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

wsgi_root = wsgi_resource()
reactor.listenTCP(DJANGO_PORT, server.Site(wsgi_root))

How do I even begin testing for this piece of code? I have to run twisted because my views uses something like this:

blockingCallFromThread( reactor, engine.push_message, user_hexid, room_hexid, message)

to call the variable that I passed into it.


You can write tests with Twisted's built-in test runner, trial, assuming that you start your WSGI threadpool before each test and stop it afterwards (in setUp and tearDown).

The upcoming 11.1 release includes new documentation for doing test-driven development with Twisted using Trial. Until that's available in the official location, here's a temporary link to a buildbot build of our the documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜