Skip to content

Instantly share code, notes, and snippets.

@ityoung
Last active March 15, 2018 03:49
Show Gist options
  • Save ityoung/7ad6a47b514886ce4f6707d1c8db3450 to your computer and use it in GitHub Desktop.
Save ityoung/7ad6a47b514886ce4f6707d1c8db3450 to your computer and use it in GitHub Desktop.
A code snippet of unittest in tornado and motorengine.
from tornado.web import Application
from tornado.testing import AsyncHTTPTestCase
from apps.account.handlers import CheckEnv
import unittest
import motorengine
class MyTestCase(AsyncHTTPTestCase):
def setUp(self, auto_connect=True):
super(MyTestCase, self).setUp()
if auto_connect:
self.db = motorengine.connect("test", host="192.168.3.158", port=27017, io_loop=self.io_loop)
def tearDown(self):
motorengine.connection.cleanup()
super(MyTestCase, self).tearDown()
def get_app(self):
return Application([(r"/account/check-env/", CheckEnv)])
def test_example(self):
res = self.fetch("/account/check-env/")
print(res.body)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment