diff options
| author | Michael Merickel <michael@merickel.org> | 2014-11-17 02:14:53 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2014-11-17 02:14:53 -0600 |
| commit | c0f1fc8d31df45371d5ae6689d3e0a39c058c3ac (patch) | |
| tree | 5f498472996e2811136410dcc1d18486f7a974a2 | |
| parent | 1d298deae192918a994423c3fc4ee9cd4bf7e7ca (diff) | |
| parent | 8ad4fa89c3a69f709a4d713557846da198bf9cdb (diff) | |
| download | pyramid-c0f1fc8d31df45371d5ae6689d3e0a39c058c3ac.tar.gz pyramid-c0f1fc8d31df45371d5ae6689d3e0a39c058c3ac.tar.bz2 pyramid-c0f1fc8d31df45371d5ae6689d3e0a39c058c3ac.zip | |
Merge pull request #1460 from sontek/fix_proutes_coverage
Added coverage for MultiView and long names in proutes
| -rw-r--r-- | pyramid/scripts/proutes.py | 6 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/test_proutes.py | 83 |
2 files changed, 87 insertions, 2 deletions
diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 792030a74..d0c1aa13e 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -4,7 +4,6 @@ import textwrap from pyramid.paster import bootstrap from pyramid.scripts.common import parse_vars -from pyramid.config.views import MultiView PAD = 3 @@ -58,6 +57,8 @@ class PRoutesCommand(object): from pyramid.interfaces import IRouteRequest from pyramid.interfaces import IViewClassifier from pyramid.interfaces import IView + from pyramid.interfaces import IMultiView + from zope.interface import Interface config_uri = self.args[0] @@ -72,6 +73,7 @@ class PRoutesCommand(object): max_view = len('View') routes = mapper.get_routes() + if not routes: return 0 @@ -97,7 +99,7 @@ class PRoutesCommand(object): IView, name='', default=None) if view_callable is not None: - if isinstance(view_callable, MultiView): + if IMultiView.providedBy(view_callable): view_callables = [ x[1] for x in view_callable.views ] diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index 45ab57d3a..32202af4b 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -128,6 +128,48 @@ class TestPRoutesCommand(unittest.TestCase): ['a', '/a', 'pyramid.tests.test_scripts.test_proutes.view'] ) + def test_one_route_with_long_name_one_view_registered(self): + from zope.interface import Interface + from pyramid.registry import Registry + from pyramid.interfaces import IRouteRequest + from pyramid.interfaces import IViewClassifier + from pyramid.interfaces import IView + registry = Registry() + def view():pass + + class IMyRoute(Interface): + pass + + registry.registerAdapter( + view, + (IViewClassifier, IMyRoute, Interface), + IView, '' + ) + + registry.registerUtility(IMyRoute, IRouteRequest, + name='very_long_name_123') + + command = self._makeOne() + route = dummy.DummyRoute( + 'very_long_name_123', + '/and_very_long_pattern_as_well' + ) + mapper = dummy.DummyMapper(route) + command._get_mapper = lambda *arg: mapper + L = [] + command.out = L.append + command.bootstrap = (dummy.DummyBootstrap(registry=registry),) + result = command.run() + self.assertEqual(result, 0) + self.assertEqual(len(L), 3) + compare_to = L[-1].split()[:3] + self.assertEqual( + compare_to, + ['very_long_name_123', + '/and_very_long_pattern_as_well', + 'pyramid.tests.test_scripts.test_proutes.view'] + ) + def test_single_route_one_view_registered_with_factory(self): from zope.interface import Interface from pyramid.registry import Registry @@ -157,6 +199,47 @@ class TestPRoutesCommand(unittest.TestCase): self.assertEqual(len(L), 3) self.assertEqual(L[-1].split()[:3], ['a', '/a', '<unknown>']) + def test_single_route_multiview_registered(self): + from zope.interface import Interface + from pyramid.registry import Registry + from pyramid.interfaces import IRouteRequest + from pyramid.interfaces import IViewClassifier + from pyramid.interfaces import IMultiView + + registry = Registry() + + def view(): pass + + class IMyRoute(Interface): + pass + + multiview1 = dummy.DummyMultiView( + view, context='context', + view_name='a1' + ) + + registry.registerAdapter( + multiview1, + (IViewClassifier, IMyRoute, Interface), + IMultiView, '' + ) + registry.registerUtility(IMyRoute, IRouteRequest, name='a') + command = self._makeOne() + route = dummy.DummyRoute('a', '/a') + mapper = dummy.DummyMapper(route) + command._get_mapper = lambda *arg: mapper + L = [] + command.out = L.append + command.bootstrap = (dummy.DummyBootstrap(registry=registry),) + result = command.run() + self.assertEqual(result, 0) + self.assertEqual(len(L), 3) + compare_to = L[-1].split()[:3] + self.assertEqual( + compare_to, + ['a', '/a', 'pyramid.tests.test_scripts.test_proutes.view'] + ) + def test__get_mapper(self): from pyramid.registry import Registry from pyramid.urldispatch import RoutesMapper |
