Commits

Ben Bangert committed 8c02609 Merge

merge

Comments (0)

Files changed (3)

pylons/configuration.py

         self.registry.helpers = module_ref
     
     def add_sessions(self, settings=None, exception_abort=True, **fallback):
-        """Add's session support to the WSGI app
+        """Adds session support to the Pylons application.
         
         The ``settings`` argument should be a dict, usually the same
         settings dict that the :class:`Configurator` was instantiated
         ``route_name`` is the name of the route (to be used later in
         URL generation).
 
-        ``pattern`` is the matching pattern, e.g. ``'/blog/{action}'``
+        ``pattern`` is the matching pattern,
+        e.g. ``'/blog/{action}'``.  ``pattern`` may be ``None``, in
+        which case the pattern of an existing route named the same as
+        ``route_name`` is used.  If ``pattern`` is ``None`` and no
+        route named ``route_name`` exists, a ``ConfigurationError`` is
+        raised.
         
         ``handler`` is a dotted name of (or direct reference to) a
         Python handler class,
         This method returns the result of add_route."""
         handler = self.maybe_dotted(handler)
 
-        route = self.add_route(route_name, pattern, **kw)
+        if pattern is not None:
+            route = self.add_route(route_name, pattern, **kw)
+        else:
+            mapper = self.get_routes_mapper()
+            route = mapper.get_route(route_name)
+            if route is None:
+                raise ConfigurationError(
+                    'The "pattern" parameter may only be "None" when a route '
+                    'with the route_name argument was previously registered. '
+                    'No such route named %r exists'  % route_name)
+                                         
+            pattern = route.pattern
 
         path_has_action = ':action' in pattern or '{action}' in pattern
 

tests/test_units/test_configuration.py

         self.assertRaises(ConfigurationError, config.add_handler, 
                           'name', '/{action}', DummyHandler, action='abc')
 
-    def test_with_explicit_action(self):
+    def test_add_handler_with_explicit_action(self):
         config = self._makeOne()
         class DummyHandler(object):
             def index(self): pass
         self.assertEqual(view['route_name'], 'name')
         self.assertEqual(view['view'], DummyHandler)
 
-    def test_with_implicit_action(self):
+    def test_add_handler_with_implicit_action(self):
         config = self._makeOne()
         class DummyHandler(object):
             def __call__(self): pass
         self.assertEqual(view['route_name'], 'name')
         self.assertEqual(view['view'], DummyHandler)
     
-    def test_with_multiple_action(self):
+    def test_add_handler_with_multiple_action(self):
         config = self._makeOne()
         class DummyHandler(object):
             def index(self): pass
         view = views[1]
         self.assertEqual(view['attr'], 'index')
 
-    def test_string_handler(self):
+    def test_add_handler_string(self):
         import pylons
         views = []
         config = self._makeOne()
         view = views[0]
         self.assertEqual(view['view'], pylons)
 
+    def test_add_handler_pattern_None_no_previous_route(self):
+        from repoze.bfg.exceptions import ConfigurationError
+        config = self._makeOne()
+        self.assertRaises(ConfigurationError, config.add_handler,
+                          'name', None, 'pylons')
+
+    def test_add_handler_pattern_None_with_previous_route(self):
+        import pylons
+        config = self._makeOne()
+        config.add_route('name', ':def')
+        views = []
+        def dummy_add_view(**kw):
+            views.append(kw)
+        config.add_view = dummy_add_view
+        config.add_route = None # shouldn't be called
+        config.add_handler('name', None, 'pylons')
+        self.assertEqual(len(views), 1)
+        view = views[0]
+        self.assertEqual(view['view'], pylons)
+
     def test_add_helpers_string(self):
         import pylons
         config = self._makeOne()

tests/test_units/test_views.py

         response = view(request)
         self.assertEqual(response, dummyapp)
 
-class Test_expose(unittest.TestCase):
+class Test_action(unittest.TestCase):
     def _makeOne(self, **kw):
         from pylons.views import action
         return action(**kw)
 
-    def test_call(self):
+    def test_call_no_previous__exposed__(self):
         inst = self._makeOne(a=1, b=2)
         def wrapped():
             """ """
         self.failUnless(result is wrapped)
         self.assertEqual(result.__exposed__, [{'a':1, 'b':2}])
 
+    def test_call_with_previous__exposed__(self):
+        inst = self._makeOne(a=1, b=2)
+        def wrapped():
+            """ """
+        wrapped.__exposed__ = [None]
+        result = inst(wrapped)
+        self.failUnless(result is wrapped)
+        self.assertEqual(result.__exposed__, [None, {'a':1, 'b':2}])
+
 def dummyapp(environ, start_response):
     """ """