jeudi 28 avril 2016

how to do unit test on tornado

The tornado testing subject doc is so simple, I am not quite sure how to do a unit test on tornado. like that:

here is a api.py:

import tornado
import logging
from tornado.web import RequestHandler
import time


class AnalyticsBWSpecificHour(RequestHandler):
    def get(self):
        return self.write({'message':'no get method'})


class Application(tornado.web.Application):
    def __init__(self,**kwargs):
        api_handlers = [
            (r"/", AnalyticsBWSpecificHour),
        ]

        logging.debug(api_handlers)

        super(Application, self).__init__(api_handlers, **kwargs)

and the test_tornado.py :

from api import Application

from tornado.testing import AsyncHTTPTestCase
import tornado
import logging
logging.basicConfig(level=logging.DEBUG)
import unittest

class ApiTestCase(AsyncHTTPTestCase):
   def get_app(self):
        self.app = Application(debug=True)
        return self.app

    def test_status(self):
        print(self.get_url('/'))
        response = self.fetch(self.get_url('/'),method='GET')
        self.assertEqual(response.code,200)

if __name__ == '__main__':
    unittest.main()

even this is quite simple example, I also get the 599 error. please help me.

Aucun commentaire:

Enregistrer un commentaire