You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/19 20:43:27 UTC

[45/50] git commit: [#4334] ticket:158 Add unit test for DispatchIndex mixin

[#4334] ticket:158 Add unit test for DispatchIndex mixin


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/8591088b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/8591088b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/8591088b

Branch: refs/heads/master
Commit: 8591088bb06eac4efa2992a5389c055cfcda42ce
Parents: 6a83d74
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Sep 3 13:44:16 2012 +0300
Committer: Dave Brondsema <db...@geek.net>
Committed: Thu Sep 6 19:36:55 2012 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/__init__.py              |    2 +-
 Allura/allura/controllers/base.py                  |    4 ++-
 .../tests/unit/controllers/test_dispatch_index.py  |   24 +++++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8591088b/Allura/allura/controllers/__init__.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/__init__.py b/Allura/allura/controllers/__init__.py
index 1ca31ae..df369fe 100644
--- a/Allura/allura/controllers/__init__.py
+++ b/Allura/allura/controllers/__init__.py
@@ -2,4 +2,4 @@
 """Controllers for the allura application."""
 from .discuss import DiscussionController, AppDiscussionController, ThreadController, PostController, ModerationController
 from .discuss import AppDiscussionRestController
-from .base import BaseController
+from .base import BaseController, DispatchIndex

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8591088b/Allura/allura/controllers/base.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/base.py b/Allura/allura/controllers/base.py
index 45b6162..b7f540b 100644
--- a/Allura/allura/controllers/base.py
+++ b/Allura/allura/controllers/base.py
@@ -23,8 +23,10 @@ class DispatchIndex(object):
     Use this class as a mixin to controller that needs such behaviour.
     (see allura.controllers.repository.TreeBrowser for an example)
     """
+    dispatcher = ObjectDispatcher()
+
     def _dispatch(self, state, remainder):
-        dispatcher = ObjectDispatcher()
+        dispatcher = self.dispatcher
         if remainder and remainder[0] == 'index':
             controller, new_remainder = self._lookup(*remainder)
             state.add_controller(controller.__class__.__name__, controller)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8591088b/Allura/allura/tests/unit/controllers/test_dispatch_index.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/controllers/test_dispatch_index.py b/Allura/allura/tests/unit/controllers/test_dispatch_index.py
new file mode 100644
index 0000000..cc5d11b
--- /dev/null
+++ b/Allura/allura/tests/unit/controllers/test_dispatch_index.py
@@ -0,0 +1,24 @@
+from mock import Mock
+from allura.controllers.base import DispatchIndex, BaseController
+
+
+def test_dispatch_index():
+    controller = Mock(BaseController)
+    d = DispatchIndex()
+    d._lookup = lambda self, *remainder: (controller, remainder)
+
+    d.dispatcher = Mock()
+    state = Mock()
+    d._dispatch(state, ['index'])
+    state.add_controller.assert_called_with('BaseController', controller)
+    d.dispatcher._dispatch.assert_called_with(state, ())
+
+    state = Mock()
+    d._dispatch(state, ['index', 'next'])
+    state.add_controller.assert_called_with('BaseController', controller)
+    d.dispatcher._dispatch.assert_called_with(state, ('next', ))
+
+    state = Mock()
+    d._dispatch(state, ['index2'])
+    assert not state.add_controller.called
+    d.dispatcher._dispatch.assert_called_with(state, ['index2'])