openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #04440
lp:~openerp-dev/openobject-client-web/proto61-dispatcher-tests-xmo into lp:~openerp-dev/openobject-client-web/trunk-proto61
Xavier (Open ERP) has proposed merging lp:~openerp-dev/openobject-client-web/proto61-dispatcher-tests-xmo into lp:~openerp-dev/openobject-client-web/trunk-proto61.
Requested reviews:
OpenERP R&D Team (openerp-dev)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/proto61-dispatcher-tests-xmo/+merge/54242
Added a few tests for the root dispatcher, fixed 2 small issues.
--
https://code.launchpad.net/~openerp-dev/openobject-client-web/proto61-dispatcher-tests-xmo/+merge/54242
Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openobject-client-web/proto61-dispatcher-tests-xmo into lp:~openerp-dev/openobject-client-web/trunk-proto61.
=== modified file 'openerpweb/openerpweb.py'
--- openerpweb/openerpweb.py 2011-03-21 10:47:35 +0000
+++ openerpweb/openerpweb.py 2011-03-21 17:32:28 +0000
@@ -255,7 +255,7 @@
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]
@@ -265,7 +265,7 @@
if getattr(m, 'exposed', 0):
print "Calling", ps, c, meth, m
return m(**kw)
-
+ raise cherrypy.NotFound('/' + '/'.join(l))
else:
raise cherrypy.HTTPRedirect('/base/static/openerp/base.html', 301)
default.exposed = True
=== modified file 'openerpweb/tests/test_model.py'
--- openerpweb/tests/test_model.py 2011-03-21 12:14:47 +0000
+++ openerpweb/tests/test_model.py 2011-03-21 17:32:28 +0000
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import cherrypy
import mock
import unittest2
import openerpweb.openerpweb
@@ -18,3 +19,63 @@
Model.read([42])
session.execute.assert_called_once_with(
'a.b', 'read', [42])
+
+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,
+ openerpweb.openerpweb.Root().default)
+ def test_serve_static_missing(self):
+ self.assertRaises(
+ 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()
Follow ups