Beispiel #1
0
    def test_views_command_multiview_with_predicates(self):
        from pyramid.registry import Registry
        registry = Registry()
        command = self._makeOne(registry=registry)
        L = []
        command.out = L.append

        def predicate():
            pass

        predicate.__text__ = "predicate = x"
        view = dummy.DummyView(context='context')
        view.__name__ = 'view'
        view.__view_attr__ = 'call'
        view.__predicates__ = [predicate]
        multiview = dummy.DummyMultiView(view,
                                         context='context',
                                         view_name='a')
        command._find_view = lambda arg1, arg2: multiview
        command.args = ('/foo/bar/myapp.ini#myapp', '/a')
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(L[1], 'URL = /a')
        self.assertEqual(L[3], '    context: context')
        self.assertEqual(L[4], '    view name: a')
        self.assertEqual(L[8],
                         '    pyramid.tests.test_scripts.dummy.view.call')
        self.assertEqual(L[9], '    view predicates (predicate = x)')
Beispiel #2
0
 def test_views_command_multi_view_nested(self):
     from pyramid.registry import Registry
     registry = Registry()
     command = self._makeOne(registry=registry)
     L = []
     command.out = L.append
     view1 = dummy.DummyView(context='context', view_name='a1')
     view1.__name__ = 'view1'
     view1.__view_attr__ = 'call'
     multiview1 = dummy.DummyMultiView(view1,
                                       context='context',
                                       view_name='a1')
     multiview2 = dummy.DummyMultiView(multiview1,
                                       context='context',
                                       view_name='a')
     command._find_view = lambda arg1, arg2: multiview2
     command.args = ('/foo/bar/myapp.ini#myapp', '/a')
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(L[1], 'URL = /a')
     self.assertEqual(L[3], '    context: context')
     self.assertEqual(L[4], '    view name: a')
     self.assertEqual(
         L[8], '    pyramid.tests.test_scripts.dummy.DummyMultiView')
     self.assertEqual(
         L[12], '        pyramid.tests.test_scripts.dummy.view1.call')
Beispiel #3
0
    def test_views_command_single_view_route_with_route_predicates(self):
        from pyramid.registry import Registry
        registry = Registry()
        command = self._makeOne(registry=registry)
        L = []
        command.out = L.append

        def predicate():
            pass

        predicate.__text__ = "predicate = x"
        route = dummy.DummyRoute('a', '/a', matchdict={}, predicate=predicate)
        view = dummy.DummyView(context='context',
                               view_name='a',
                               matched_route=route,
                               subpath='')
        command._find_view = lambda arg1, arg2: view
        command.args = ('/foo/bar/myapp.ini#myapp', '/a')
        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(L[1], 'URL = /a')
        self.assertEqual(L[3], '    context: context')
        self.assertEqual(L[4], '    view name: a')
        self.assertEqual(L[6], '    Route:')
        self.assertEqual(L[8], '    route name: a')
        self.assertEqual(L[9], '    route pattern: /a')
        self.assertEqual(L[10], '    route path: /a')
        self.assertEqual(L[11], '    subpath: ')
        self.assertEqual(L[12], '    route predicates (predicate = x)')
        self.assertEqual(L[16],
                         '        pyramid.tests.test_scripts.dummy.DummyView')
Beispiel #4
0
 def test_views_command_single_view_route(self):
     from pyramid.registry import Registry
     registry = Registry()
     command = self._makeOne(registry=registry)
     L = []
     command.out = L.append
     route = dummy.DummyRoute('a', '/a', matchdict={})
     view = dummy.DummyView(context='context',
                            view_name='a',
                            matched_route=route,
                            subpath='')
     command._find_view = lambda arg1: view
     command.args.config_uri = '/foo/bar/myapp.ini#myapp'
     command.args.url = '/a'
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(L[1], 'URL = /a')
     self.assertEqual(L[3], '    context: context')
     self.assertEqual(L[4], '    view name: a')
     self.assertEqual(L[6], '    Route:')
     self.assertEqual(L[8], '    route name: a')
     self.assertEqual(L[9], '    route pattern: /a')
     self.assertEqual(L[10], '    route path: /a')
     self.assertEqual(L[11], '    subpath: ')
     self.assertEqual(L[15],
                      '        pyramid.tests.test_scripts.dummy.DummyView')
Beispiel #5
0
 def test_views_command_single_view_traversal(self):
     from pyramid.registry import Registry
     registry = Registry()
     command = self._makeOne(registry=registry)
     L = []
     command.out = L.append
     view = dummy.DummyView(context='context', view_name='a')
     command._find_view = lambda arg1, arg2: view
     command.args = ('/foo/bar/myapp.ini#myapp', '/a')
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(L[1], 'URL = /a')
     self.assertEqual(L[3], '    context: context')
     self.assertEqual(L[4], '    view name: a')
     self.assertEqual(L[8],
                      '    pyramid.tests.test_scripts.dummy.DummyView')
Beispiel #6
0
 def test_views_command_single_view_traversal_with_permission(self):
     from pyramid.registry import Registry
     registry = Registry()
     command = self._makeOne(registry=registry)
     L = []
     command.out = L.append
     view = dummy.DummyView(context='context', view_name='a')
     view.__permission__ = 'test'
     command._find_view = lambda arg1: view
     command.args.config_uri = '/foo/bar/myapp.ini#myapp'
     command.args.url = '/a'
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(L[1], 'URL = /a')
     self.assertEqual(L[3], '    context: context')
     self.assertEqual(L[4], '    view name: a')
     self.assertEqual(L[8],
                      '    pyramid.tests.test_scripts.dummy.DummyView')
     self.assertEqual(L[9], '    required permission = test')
Beispiel #7
0
 def test_views_command_single_view_traversal_with_predicates(self):
     from pyramid.registry import Registry
     registry = Registry()
     command = self._makeOne(registry=registry)
     L = []
     command.out = L.append
     def predicate(): pass
     predicate.text = lambda *arg: "predicate = x"
     view = dummy.DummyView(context='context', view_name='a')
     view.__predicates__ = [predicate]
     command._find_view = lambda arg1: view
     command.args = ('/foo/bar/myapp.ini#myapp', '/a')
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(L[1], 'URL = /a')
     self.assertEqual(L[3], '    context: context')
     self.assertEqual(L[4], '    view name: a')
     self.assertEqual(L[8],
                      '    pyramid.tests.test_scripts.dummy.DummyView')
     self.assertEqual(L[9], '    view predicates (predicate = x)')
Beispiel #8
0
 def test_views_command_multiview_with_permission(self):
     from pyramid.registry import Registry
     registry = Registry()
     command = self._makeOne(registry=registry)
     L = []
     command.out = L.append
     view = dummy.DummyView(context='context')
     view.__name__ = 'view'
     view.__view_attr__ = 'call'
     view.__permission__ = 'test'
     multiview = dummy.DummyMultiView(view, context='context', view_name='a')
     command._find_view = lambda arg1: multiview
     command.args = ('/foo/bar/myapp.ini#myapp', '/a')
     result = command.run()
     self.assertEqual(result, 0)
     self.assertEqual(L[1], 'URL = /a')
     self.assertEqual(L[3], '    context: context')
     self.assertEqual(L[4], '    view name: a')
     self.assertEqual(L[8],
                    '    pyramid.tests.test_scripts.dummy.view.call')
     self.assertEqual(L[9], '    required permission = test')