コード例 #1
0
ファイル: test_proutes.py プロジェクト: bishwa3141/movie
    def test_single_route_one_view_registered_with_factory(self):
        from zope.interface import Interface
        from pyramid.interfaces import IRouteRequest
        from pyramid.interfaces import IViewClassifier
        from pyramid.interfaces import IView
        registry = self._makeRegistry()

        def view():
            pass

        class IMyRoot(Interface):
            pass

        class IMyRoute(Interface):
            pass

        registry.registerAdapter(view, (IViewClassifier, IMyRoute, IMyRoot),
                                 IView, '')
        registry.registerUtility(IMyRoute, IRouteRequest, name='a')
        command = self._makeOne()

        def factory(request):
            pass

        route = dummy.DummyRoute('a', '/a', factory=factory)
        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)
        self.assertEqual(L[-1].split()[:3], ['a', '/a', '<unknown>'])
コード例 #2
0
ファイル: test_proutes.py プロジェクト: bmonteiro00/geru
    def test_single_route_one_view_registered(self):
        from zope.interface import Interface
        from pyramid.interfaces import IRouteRequest
        from pyramid.interfaces import IViewClassifier
        from pyramid.interfaces import IView
        registry = self._makeRegistry()

        def view():pass
        class IMyRoute(Interface):
            pass
        registry.registerAdapter(view,
                                 (IViewClassifier, IMyRoute, Interface),
                                 IView, '')
        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']
        )
コード例 #3
0
ファイル: test_proutes.py プロジェクト: ronnix/pyramid
 def test_no_routes(self):
     command = self._makeOne()
     mapper = dummy.DummyMapper()
     command._get_mapper = lambda *arg: mapper
     L = []
     command.out = L.append
     result = command.run()
     self.assertEqual(result, None)
     self.assertEqual(L, [])
コード例 #4
0
    def test_bad_args(self):
        cmd = self._getTargetClass()([])
        cmd.bootstrap = (dummy.DummyBootstrap(), )
        cmd.args = ('/foo/bar/myapp.ini#myapp', 'a')
        route = dummy.DummyRoute('a', '/a')
        mapper = dummy.DummyMapper(route)
        cmd._get_mapper = lambda *arg: mapper

        self.assertRaises(ValueError, cmd.run)
コード例 #5
0
 def test__find_multi_routes_none_match(self):
     command = self._makeOne()
     def factory(request): pass
     routes = [dummy.DummyRoute('a', '/a', factory=factory),
               dummy.DummyRoute('b', '/a', factory=factory)]
     mapper = dummy.DummyMapper(*routes)
     request = dummy.DummyRequest({'PATH_INFO':'/a'})
     result = command._find_multi_routes(mapper, request)
     self.assertEqual(result, [])
コード例 #6
0
 def test__find_multi_routes_all_match(self):
     command = self._makeOne()
     def factory(request): pass
     routes = [dummy.DummyRoute('a', '/a', factory=factory, matchdict={}),
               dummy.DummyRoute('b', '/a', factory=factory, matchdict={})]
     mapper = dummy.DummyMapper(*routes)
     request = dummy.DummyRequest({'PATH_INFO':'/a'})
     result = command._find_multi_routes(mapper, request)
     self.assertEqual(result, [{'match':{}, 'route':routes[0]},
                               {'match':{}, 'route':routes[1]}])
コード例 #7
0
ファイル: test_proutes.py プロジェクト: ronnix/pyramid
 def test_route_with_no_slash_prefix(self):
     command = self._makeOne()
     route = dummy.DummyRoute('a', 'a')
     mapper = dummy.DummyMapper(route)
     command._get_mapper = lambda *arg: mapper
     L = []
     command.out = L.append
     result = command.run()
     self.assertEqual(result, None)
     self.assertEqual(len(L), 3)
     self.assertEqual(L[-1].split(), ['a', '/a', '<unknown>'])
コード例 #8
0
 def test_single_route_no_route_registered(self):
     command = self._makeOne()
     route = dummy.DummyRoute('a', '/a')
     mapper = dummy.DummyMapper(route)
     command._get_mapper = lambda *arg: mapper
     L = []
     command.out = L.append
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(len(L), 3)
     self.assertEqual(L[-1].split(), ['a', '/a', '<unknown>'])
コード例 #9
0
ファイル: test_proutes.py プロジェクト: bmonteiro00/geru
    def test_bad_args(self):
        cmd = self._getTargetClass()([])
        cmd.bootstrap = dummy.DummyBootstrap()
        cmd.get_config_loader = dummy.DummyLoader()
        cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'
        cmd.args.config_vars = ('a',)
        route = dummy.DummyRoute('a', '/a')
        mapper = dummy.DummyMapper(route)
        cmd._get_mapper = lambda *arg: mapper

        self.assertRaises(ValueError, cmd.run)
コード例 #10
0
ファイル: test_proutes.py プロジェクト: cghnassia/Roki_Rakat
 def test_good_args(self):
     cmd = self._getTargetClass()([])
     cmd.bootstrap = (dummy.DummyBootstrap(),)
     cmd.args = ('/foo/bar/myapp.ini#myapp', 'a=1')
     route = dummy.DummyRoute('a', '/a')
     mapper = dummy.DummyMapper(route)
     cmd._get_mapper = lambda *arg: mapper
     L = []
     cmd.out = lambda msg: L.append(msg)
     cmd.run()
     self.assertTrue('<unknown>' in ''.join(L))
コード例 #11
0
 def test_route_with_no_slash_prefix(self):
     command = self._makeOne()
     route = dummy.DummyRoute('a', 'a')
     mapper = dummy.DummyMapper(route)
     command._get_mapper = lambda *arg: mapper
     L = []
     command.out = L.append
     registry = self._makeRegistry()
     command.bootstrap = (dummy.DummyBootstrap(registry=registry), )
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(len(L), 3)
     self.assertEqual(L[-1].split(), ['a', '/a', '<unknown>', '*'])
コード例 #12
0
ファイル: test_proutes.py プロジェクト: bmonteiro00/geru
 def test_good_args(self):
     cmd = self._getTargetClass()([])
     cmd.bootstrap = dummy.DummyBootstrap()
     cmd.get_config_loader = dummy.DummyLoader()
     cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'
     cmd.args.config_args = ('a=1',)
     route = dummy.DummyRoute('a', '/a')
     mapper = dummy.DummyMapper(route)
     cmd._get_mapper = lambda *arg: mapper
     registry = self._makeRegistry()
     cmd.bootstrap = dummy.DummyBootstrap(registry=registry)
     L = []
     cmd.out = lambda msg: L.append(msg)
     cmd.run()
     self.assertTrue('<unknown>' in ''.join(L))
コード例 #13
0
    def test_single_route_multiview_registered(self):
        from zope.interface import Interface
        from pyramid.interfaces import IRouteRequest
        from pyramid.interfaces import IViewClassifier
        from pyramid.interfaces import IMultiView

        registry = self._makeRegistry()

        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]
        view_module = 'pyramid.tests.test_scripts.dummy'
        view_str = '<pyramid.tests.test_scripts.dummy.DummyMultiView'
        final = '%s.%s' % (view_module, view_str)

        self.assertEqual(
            compare_to,
            ['a', '/a', final]
        )
コード例 #14
0
    def test_single_route_no_views_registered(self):
        from zope.interface import Interface
        from pyramid.interfaces import IRouteRequest
        registry = self._makeRegistry()

        def view():pass
        class IMyRoute(Interface):
            pass
        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)
        self.assertEqual(L[-1].split()[:3], ['a', '/a', '<unknown>'])
コード例 #15
0
ファイル: test_pviews.py プロジェクト: bennihepp/sandbox
 def _register_mapper(self, registry, routes):
     from pyramid.interfaces import IRoutesMapper
     mapper = dummy.DummyMapper(*routes)
     registry.registerUtility(mapper, IRoutesMapper)