Search code examples
pythonunit-testingmigrationtornadocyclone

How do I write tests for Cyclone in the style of Tornado?


I have been googling and asking on IRC to no avail. Cyclone is supposed to be a Tornado-like protocol for Twisted. But, there are no tests in the Cyclone repository and no-one has written up how to convert tornado.testing.AsyncHTTPTestCase tests to exercise code written against Cyclone.

  1. How do I start a server to test the web interface?
  2. Where is the self.fetch()?
  3. Where is the documentation in Cyclone to describe how to convert an existing Tornado app?

Solution

  • Unfortunately, there's nothing like tornado.testing.AsyncHTTPTestCase in cyclone at the moment. Your best bet would be to use Twisted Trial to write unit tests. One (slightly kludgy) approach would be explicitly call self.listener = reactor.listenTCP(<someport>, YourCycloneApplication()) in the setUp method inside your test case and call self.listener.stopListening() in the tearDown method.

    Then, inside your test methods, you could use cyclone.httpclient.fetch to fetch the pages. This is far from ideal. But as of now, this is the only way to go.