To specify a context of a controller from WSGIApplication#register()
Before: wsgi.register(FooController) wsgi.registory[FooController.__name__] = controller_args After: wsgi.register(FooController, controller_args) Signed-off-by: Satoshi Kobayashi <satoshi-k@stratosphere.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
8df8cca872
commit
789fbb3a51
@ -93,7 +93,7 @@ class WSGIApplication(object):
|
|||||||
controller = match['controller'](req, link, data, **self.config)
|
controller = match['controller'](req, link, data, **self.config)
|
||||||
return controller(req)
|
return controller(req)
|
||||||
|
|
||||||
def register(self, controller):
|
def register(self, controller, data=None):
|
||||||
methods = inspect.getmembers(controller,
|
methods = inspect.getmembers(controller,
|
||||||
lambda v: inspect.ismethod(v) and
|
lambda v: inspect.ismethod(v) and
|
||||||
hasattr(v, 'routing_info'))
|
hasattr(v, 'routing_info'))
|
||||||
@ -111,6 +111,8 @@ class WSGIApplication(object):
|
|||||||
requirements=requirements,
|
requirements=requirements,
|
||||||
action=method_name,
|
action=method_name,
|
||||||
conditions=conditions)
|
conditions=conditions)
|
||||||
|
if data:
|
||||||
|
self.registory[controller.__name__] = data
|
||||||
|
|
||||||
|
|
||||||
class WSGIServer(hub.WSGIServer):
|
class WSGIServer(hub.WSGIServer):
|
||||||
|
@ -28,6 +28,10 @@ LOG = logging.getLogger('test_wsgi')
|
|||||||
|
|
||||||
class _TestController(ControllerBase):
|
class _TestController(ControllerBase):
|
||||||
|
|
||||||
|
def __init__(self, req, link, data, **config):
|
||||||
|
super(_TestController, self).__init__(req, link, data, **config)
|
||||||
|
eq_(data['test_param'], 'foo')
|
||||||
|
|
||||||
@route('test', '/test/{dpid}',
|
@route('test', '/test/{dpid}',
|
||||||
methods=['GET'], requirements={'dpid': dpidlib.DPID_PATTERN})
|
methods=['GET'], requirements={'dpid': dpidlib.DPID_PATTERN})
|
||||||
def test_get_dpid(self, req, dpid, **_kwargs):
|
def test_get_dpid(self, req, dpid, **_kwargs):
|
||||||
@ -44,8 +48,11 @@ class Test_wsgi(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
controller_data = {
|
||||||
|
'test_param': 'foo'
|
||||||
|
}
|
||||||
self.wsgi_app = WSGIApplication()
|
self.wsgi_app = WSGIApplication()
|
||||||
self.wsgi_app.register(_TestController)
|
self.wsgi_app.register(_TestController, controller_data)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user