From 5598064ed1984e2abf95678fbf531070183dcdcb Mon Sep 17 00:00:00 2001 From: Christophe de Vienne Date: Mon, 14 May 2012 23:29:54 +0200 Subject: [PATCH] Now test the tg1 adapter --- tests/test_tg1.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++ tox.ini | 18 +++++++++++++++- wsme/tg1.py | 2 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/test_tg1.py diff --git a/tests/test_tg1.py b/tests/test_tg1.py new file mode 100644 index 0000000..d3f0442 --- /dev/null +++ b/tests/test_tg1.py @@ -0,0 +1,55 @@ +import wsme.tg1 +from wsme import expose, validate, WSRoot + +from turbogears.controllers import RootController + +import unittest + +import simplejson + + +class WSController(WSRoot): + @expose(int) + @validate(int, int) + def multiply(self, a, b): + return a * b + + +class Root(RootController): + ws = wsme.tg1.adapt( + WSController(webpath='/ws', protocols=['restjson'])) + + +import cherrypy + +from turbogears import testutil, config, startup + + +class TestController(unittest.TestCase): + root = Root + + def setUp(self): + "Tests the output of the index method" + self.app = testutil.make_app(self.root) + print cherrypy.root + testutil.start_server() + + def tearDown(self): + # implementation copied from turbogears.testutil.stop_server. + # The only change is that cherrypy.root is set to None + # AFTER stopTurbogears has been called so that wsme.tg1 + # can correctly uninstall its filter. + if config.get("cp_started"): + cherrypy.server.stop() + config.update({"cp_started": False}) + + if config.get("server_started"): + startup.stopTurboGears() + config.update({"server_started": False}) + + def test_simplecall(self): + response = self.app.post("/ws/multiply", + simplejson.dumps({'a': 5, 'b': 10}), + {'Content-Type': 'application/json'}) + print response + assert simplejson.loads(response.body) == 50 diff --git a/tox.ini b/tox.ini index 92cf90b..a382bc8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,10 @@ # content of: tox.ini , put in same dir as setup.py [tox] -envlist = py27,py32,pypy,py25simplejson,coverage +envlist = py27,py32,pypy,py25simplejson,tg11,coverage +indexserver = + TG15 = http://www.turbogears.org/1.5/downloads/current/index + TG20 = http://www.turbogears.org/2.0/downloads/current/index + TG21 = http://www.turbogears.org/2.1/downloads/current/index [common] testtools = @@ -30,6 +34,18 @@ deps= simplejson transaction<=1.1.1 + +[testenv:tg11] +basepython=python2.5 +deps= + nose + webtest + coverage + simplejson +commands= + {envbindir}/easy_install -i http://www.turbogears.org/1.1/downloads/current/index/ 'TurboGears<1.1.99' + {envbindir}/coverage run -p {envbindir}/nosetests -w tests test_tg1.py --verbose {posargs} + [testenv:coverage] basepython=python deps= diff --git a/wsme/tg1.py b/wsme/tg1.py index 8afc2e3..8f813fc 100644 --- a/wsme/tg1.py +++ b/wsme/tg1.py @@ -45,5 +45,5 @@ def adapt(wsroot): controller._wsroot._webpath[len(filter_.webpath):] call_on_startup.append(install_filter) - call_on_shutdown.append(uninstall_filter) + call_on_shutdown.insert(0, uninstall_filter) return controller