Introduce an adapter for tg 1.5 + unittest. It needs more realistic tests though.
--HG-- rename : tests/test_tg1.py => tests/test_tg15.py rename : wsme/tg1.py => wsme/tg15.py
This commit is contained in:
parent
c3ea49a3b0
commit
4c798215c9
@ -67,6 +67,19 @@ Turbogears 1.x
|
|||||||
|
|
||||||
.. module:: wsme.tg1
|
.. module:: wsme.tg1
|
||||||
|
|
||||||
|
.. class:: Controller(wsroot)
|
||||||
|
|
||||||
|
A TG1 Controller that publish a :class:`wsme.WSRoot`.
|
||||||
|
|
||||||
|
.. function:: adapt
|
||||||
|
|
||||||
|
Returns a :class:`Controller` that publish a :class:`wsme.WSRoot`.
|
||||||
|
|
||||||
|
:mod:`wsme.tg15` -- TG 1.5 adapter
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. module:: wsme.tg15
|
||||||
|
|
||||||
.. class:: Controller(wsroot)
|
.. class:: Controller(wsroot)
|
||||||
|
|
||||||
A TG1 Controller that publish a :class:`wsme.WSRoot`.
|
A TG1 Controller that publish a :class:`wsme.WSRoot`.
|
||||||
|
55
tests/test_tg15.py
Normal file
55
tests/test_tg15.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import wsme.tg15
|
||||||
|
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.tg15.adapt(
|
||||||
|
WSController(webpath='/ws', protocols=['restjson']))
|
||||||
|
|
||||||
|
|
||||||
|
import cherrypy
|
||||||
|
|
||||||
|
from turbogears import testutil, config, startup
|
||||||
|
|
||||||
|
|
||||||
|
class TestController(testutil.TGTest):
|
||||||
|
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.tg15
|
||||||
|
# # 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
|
15
tox.ini
15
tox.ini
@ -1,6 +1,6 @@
|
|||||||
# content of: tox.ini , put in same dir as setup.py
|
# content of: tox.ini , put in same dir as setup.py
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py27,py32,pypy,py25simplejson,tg11,coverage
|
envlist = py27,py32,pypy,py25simplejson,tg11,tg15,coverage
|
||||||
indexserver =
|
indexserver =
|
||||||
TG15 = http://www.turbogears.org/1.5/downloads/current/index
|
TG15 = http://www.turbogears.org/1.5/downloads/current/index
|
||||||
TG20 = http://www.turbogears.org/2.0/downloads/current/index
|
TG20 = http://www.turbogears.org/2.0/downloads/current/index
|
||||||
@ -44,7 +44,18 @@ deps=
|
|||||||
simplejson
|
simplejson
|
||||||
commands=
|
commands=
|
||||||
{envbindir}/easy_install -i http://www.turbogears.org/1.1/downloads/current/index/ 'TurboGears<1.1.99'
|
{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}
|
{envbindir}/coverage run -p {envbindir}/nosetests tests/test_tg1.py --verbose {posargs}
|
||||||
|
|
||||||
|
[testenv:tg15]
|
||||||
|
basepython=python2.5
|
||||||
|
deps=
|
||||||
|
nose
|
||||||
|
webtest
|
||||||
|
coverage
|
||||||
|
simplejson
|
||||||
|
commands=
|
||||||
|
{envbindir}/easy_install -i http://www.turbogears.org/1.5/downloads/current/index/ 'TurboGears<1.5.99'
|
||||||
|
{envbindir}/coverage run -p {envbindir}/nosetests tests/test_tg15.py --verbose {posargs}
|
||||||
|
|
||||||
[testenv:coverage]
|
[testenv:coverage]
|
||||||
basepython=python
|
basepython=python
|
||||||
|
21
wsme/tg15.py
Normal file
21
wsme/tg15.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import cherrypy
|
||||||
|
import webob
|
||||||
|
from turbogears import expose
|
||||||
|
|
||||||
|
|
||||||
|
class Controller(object):
|
||||||
|
def __init__(self, wsroot):
|
||||||
|
self._wsroot = wsroot
|
||||||
|
|
||||||
|
@expose()
|
||||||
|
def default(self, *args, **kw):
|
||||||
|
req = webob.Request(cherrypy.request.wsgi_environ)
|
||||||
|
res = self._wsroot._handle_request(req)
|
||||||
|
cherrypy.response.header_list = res.headerlist
|
||||||
|
cherrypy.response.status = res.status
|
||||||
|
return res.body
|
||||||
|
|
||||||
|
|
||||||
|
def adapt(wsroot):
|
||||||
|
controller = Controller(wsroot)
|
||||||
|
return controller
|
Loading…
x
Reference in New Issue
Block a user