[ADD] tests for the root dispatcher, fix dispatching: start from the *end* of the url and walk backwards to try to find a dispatcher and its method
bzr revid: xmo@openerp.com-20110321170357-6k9f7qjww1s2wj3g
This commit is contained in:
parent
68e4357e47
commit
e49be016f3
|
@ -255,7 +255,7 @@ class Root(object):
|
|||
p = os.path.normpath(os.path.join(*l))
|
||||
return cherrypy.lib.static.serve_file(os.path.join(path_addons, p))
|
||||
elif len(l) > 1:
|
||||
for i in range(1, len(l) + 1):
|
||||
for i in range(len(l), 1, -1):
|
||||
ps = "/" + "/".join(l[0:i])
|
||||
if ps in controllers_path:
|
||||
c = controllers_path[ps]
|
||||
|
|
|
@ -20,7 +20,36 @@ class OpenERPModelTest(unittest2.TestCase):
|
|||
session.execute.assert_called_once_with(
|
||||
'a.b', 'read', [42])
|
||||
|
||||
class DispatcherTest(unittest2.case.TestCase):
|
||||
class FakeController(object):
|
||||
pass
|
||||
|
||||
class DispatcherTest(unittest2.TestCase):
|
||||
def setUp(self):
|
||||
controller = FakeController()
|
||||
self.mock_method = mock.Mock()
|
||||
controller.method = self.mock_method
|
||||
self.mock_method.exposed = True
|
||||
|
||||
self.mock_index = mock.Mock()
|
||||
controller.index = self.mock_index
|
||||
self.mock_index.exposed = True
|
||||
|
||||
self.patcher = mock.patch.dict(
|
||||
openerpweb.openerpweb.controllers_path,
|
||||
{'/some/controller/path': controller})
|
||||
self.patcher.start()
|
||||
|
||||
controller2 = FakeController()
|
||||
controller2.index = self.mock_index
|
||||
self.patcher2 = mock.patch.dict(
|
||||
openerpweb.openerpweb.controllers_path,
|
||||
{'/some/other/controller': FakeController(),
|
||||
'/some/other/controller/2': controller2})
|
||||
self.patcher2.start()
|
||||
def tearDown(self):
|
||||
self.patcher2.stop()
|
||||
self.patcher.stop()
|
||||
|
||||
def test_default_redirect(self):
|
||||
self.assertRaises(
|
||||
cherrypy.HTTPRedirect,
|
||||
|
@ -30,9 +59,23 @@ class DispatcherTest(unittest2.case.TestCase):
|
|||
cherrypy.NotFound,
|
||||
openerpweb.openerpweb.Root().default,
|
||||
'does-not-exist', 'static', 'bar')
|
||||
|
||||
def test_serve_controller_missing(self):
|
||||
self.assertRaises(
|
||||
cherrypy.NotFound,
|
||||
openerpweb.openerpweb.Root().default,
|
||||
'controller', 'does', 'not', 'exist')
|
||||
|
||||
def test_find_controller_method(self):
|
||||
openerpweb.openerpweb.Root().default(
|
||||
'some', 'controller', 'path', 'method')
|
||||
self.mock_method.assert_called_once_with()
|
||||
def test_find_controller_index(self):
|
||||
openerpweb.openerpweb.Root().default(
|
||||
'some', 'controller', 'path')
|
||||
self.mock_index.assert_called_once_with()
|
||||
|
||||
def test_nested_paths(self):
|
||||
openerpweb.openerpweb.Root().default(
|
||||
'some', 'other', 'controller', '2')
|
||||
self.mock_index.assert_called_once_with()
|
||||
|
|
Loading…
Reference in New Issue