Now test the tg1 adapter

This commit is contained in:
Christophe de Vienne 2012-05-14 23:29:54 +02:00
parent fb600003d6
commit 5598064ed1
3 changed files with 73 additions and 2 deletions

55
tests/test_tg1.py Normal file
View File

@ -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

18
tox.ini
View File

@ -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=

View File

@ -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