Ejemplo n.º 1
0
 def test_path_translation_args_skipped(self):
     req = MockRequest('/with.args/para.meter1/para.meter2.json')
     state = DispatchState(req, mock_dispatcher_with_no_default_or_index, path_translator=True)
     state = state.resolve()
     assert state.method.__name__ == 'with_args', state.method
     assert 'para.meter1' in state.remainder, state.remainder
     assert 'para.meter2' in state.remainder, state.remainder
Ejemplo n.º 2
0
 def test_delete_hacky(self):
     req = MockRequest('/asdf/sub', params={'_method':'delete'}, method='post')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.method.__name__ == 'post_delete', state.method
     assert state.controller.__class__.__name__ == 'MockDispatcher', state.controller
     assert state.params == {}, state.params
Ejemplo n.º 3
0
 def test_get_one(self):
     req = MockRequest('/asdf')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.method.__name__ == 'get_one'
     assert state.params == {}, state.params
     assert state.remainder == ['asdf'], state.remainder
Ejemplo n.º 4
0
 def test_rest_security_check_only_once(self):
     req = MockRequest('/rest/25')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.controller.__class__.__name__ == 'rest', state.controller
     assert state.method.__name__ == 'get', state.method
     assert len(self.security_tracing) == 1, self.security_tracing
Ejemplo n.º 5
0
    def test_controller_method_with_args_missing_args_index_disabled(self):
        req = MockRequest('/with_args/a')
        state = DispatchState(req, mock_dispatcher_with_index_with_argvars)

        try:
            mock_dispatcher_with_index_with_argvars._use_index_fallback = False
            state = state.resolve()
        finally:
            mock_dispatcher_with_index_with_argvars._use_index_fallback = True
Ejemplo n.º 6
0
    def test_path_translation_sub_controller(self):
        req = MockRequest('/sub.child/with.args/para.meter1/para.meter2.json')
        state = DispatchState(req, mock_dispatcher_with_no_default, path_translator=True)
        state = state.resolve()

        path_pieces = [piece[0] for piece in state.controller_path]
        assert 'sub_child' in path_pieces
        assert state.method.__name__ == 'with_args', state.method
        assert 'para.meter1' in state.remainder, state.remainder
        assert 'para.meter2' in state.remainder, state.remainder
Ejemplo n.º 7
0
    def test_call_twice(self):
        req = MockRequest('/')
        state = DispatchState(req, self.dispatcher)
        state = state.resolve()

        try:
            state = state.resolve()
        except RuntimeError:
            assert state.method.__name__ == 'index', state.method
        else:
            assert False, 'Should have raised RuntimeError'
Ejemplo n.º 8
0
    def _get_dispatchable(self, context, url_path):
        """
        Returns a tuple (controller, remainder, params)

        :Parameters:
          url
            url as string
        """
        req = context.request
        conf = context.config

        enable_request_extensions = not conf.get('disable_request_extensions',
                                                 False)
        dispatch_path_translator = conf.get('dispatch_path_translator', True)

        state = DispatchState(weakref.proxy(req),
                              self,
                              req.args_params,
                              url_path.split('/'),
                              conf.get('ignore_parameters', []),
                              strip_extension=enable_request_extensions,
                              path_translator=dispatch_path_translator)

        if enable_request_extensions:
            try:
                mimetypes = conf['mimetypes']
            except KeyError:
                mimetypes = default_mimetypes

            ext = state.extension
            if ext is not None:
                ext = '.' + ext
                mime_type, encoding = mimetypes.guess_type('file' + ext)
                req._fast_setattr('_response_type', mime_type)
            req._fast_setattr('_response_ext', ext)

        state = state.resolve()

        # Save the dispatch state for possible use within the controller methods
        req._fast_setattr('_controller_state', state)

        if conf.get('enable_routing_args', False):
            state.routing_args.update(state.params)
            if hasattr(state.root_dispatcher, '_setup_wsgiorg_routing_args'):
                state.root_dispatcher._setup_wsgiorg_routing_args(
                    state.path, state.remainder, state.routing_args)

        return state
Ejemplo n.º 9
0
    def _get_dispatchable(self, context, url_path):
        """
        Returns a tuple (controller, remainder, params)

        :Parameters:
          url
            url as string
        """
        req = context.request
        conf = context.config
        
        enable_request_extensions = not conf.get('disable_request_extensions', False)
        dispatch_path_translator = conf.get('dispatch_path_translator', True)

        state = DispatchState(weakref.proxy(req), self, req.args_params, url_path.split('/'),
                              conf.get('ignore_parameters', []),
                              strip_extension=enable_request_extensions,
                              path_translator=dispatch_path_translator)

        if enable_request_extensions:
            try:
                mimetypes = conf['mimetypes']
            except KeyError:
                mimetypes = default_mimetypes

            ext = state.extension
            if ext is not None:
                ext = '.' + ext
                mime_type, encoding = mimetypes.guess_type('file'+ext)
                req._fast_setattr('_response_type', mime_type)
            req._fast_setattr('_response_ext', ext)

        state = state.resolve()

        # Save the dispatch state for possible use within the controller methods
        req._fast_setattr('_controller_state', state)

        if conf.get('enable_routing_args', False):
            state.routing_args.update(state.params)
            if hasattr(state.root_dispatcher, '_setup_wsgiorg_routing_args'):
                state.root_dispatcher._setup_wsgiorg_routing_args(state.path, state.remainder,
                                                                  state.routing_args)

        return state
Ejemplo n.º 10
0
    def _get_dispatchable(self, url_path):
        """Return a tuple (controller, remainder, params).

        :Parameters:
          url
            url as string

        """
        if not pylons.config.get('disable_request_extensions', False):
            pylons.request.response_type = None
            pylons.request.response_ext = None
            if url_path and '.' in url_path[-1]:
                last_remainder = url_path[-1]
                mime_type, encoding = mimetypes.guess_type(last_remainder)
                if mime_type:
                    extension_spot = last_remainder.rfind('.')
                    extension = last_remainder[extension_spot:]
                    url_path[-1] = last_remainder[:extension_spot]
                    pylons.request.response_type = mime_type
                    pylons.request.response_ext = extension

        params = pylons.request.params.mixed()

        state = DispatchState(pylons.request,
            self, params, url_path, pylons.config.get('ignore_parameters', []))
        state = state.controller._dispatch(state, url_path)

        pylons.tmpl_context.controller_url = '/'.join(
            url_path[:-len(state.remainder)])

        state.routing_args.update(params)
        if hasattr(state.dispatcher, '_setup_wsgiorg_routing_args'):
            state.dispatcher._setup_wsgiorg_routing_args(
                url_path, state.remainder, state.routing_args)

        #save the controller state for possible use within the controller methods
        pylons.request.controller_state = state

        return state.method, state.controller, state.remainder, params
Ejemplo n.º 11
0
    def _get_dispatchable(self, thread_locals, url_path):
        """
        Returns a tuple (controller, remainder, params)

        :Parameters:
          url
            url as string
        """
        req = thread_locals.request
        conf = thread_locals.config

        params = req.args_params
        state = DispatchState(req, self, params, url_path,
                              conf.get('ignore_parameters', []))

        if not conf.get('disable_request_extensions', False):
            ext = state.extension
            if ext is not None:
                ext = '.' + ext
                mime_type, encoding = mimetypes.guess_type('file' + ext)
                req._fast_setattr('_response_type', mime_type)
            req._fast_setattr('_response_ext', ext)

        state = state.controller._dispatch(state, url_path)
        thread_locals.tmpl_context.controller_url = '/'.join(
            url_path[:-len(state.remainder)])

        if conf.get('enable_routing_args', False):
            state.routing_args.update(params)
            if hasattr(state.dispatcher, '_setup_wsgiorg_routing_args'):
                state.dispatcher._setup_wsgiorg_routing_args(
                    url_path, state.remainder, state.routing_args)

        #save the controller state for possible use within the controller methods
        req._fast_setattr('_controller_state', state)

        return state.method, state.controller, state.remainder, params
Ejemplo n.º 12
0
 def test_sub_dispatcher_bad_remainder_call_parent_default(self):
     req = MockRequest('/sub/a')
     state = DispatchState(req, self.dispatcher) 
     state = state.resolve()
     assert state.method.__name__ == '_default', state.method
Ejemplo n.º 13
0
 def test_sub_dispatcher(self):
     req = MockRequest('/sub')
     state = DispatchState(req, self.dispatcher) 
     state = state.resolve()
     assert state.method.__name__ == 'index', state.method
     assert state.controller.__class__.__name__ == 'MockSubDispatcher', state.controller
Ejemplo n.º 14
0
 def test_check_security(self):
     req = MockRequest('/with_args/a')
     state = DispatchState(req, mock_dispatcher_with_check_security)
     state = state.resolve()
Ejemplo n.º 15
0
 def test_get_url(self):
     req = MockRequest('/custom')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.method.__name__ == 'get_custom', state.method
Ejemplo n.º 16
0
 def test_check_security_with_lookup(self):
     req = MockRequest('/direct/a')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
Ejemplo n.º 17
0
 def test_post_hacky(self):
     req = MockRequest('/', params={'_method':'custom'}, method='post')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.method.__name__ == 'post_custom', state.method
Ejemplo n.º 18
0
 def test_path_translation_no_extension(self):
     req = MockRequest('/no.args')
     state = DispatchState(req, mock_dispatcher_with_no_default_or_index,
                           strip_extension=False, path_translator=True)
     state = state.resolve()
     assert state.method.__name__ == 'no_args', state.method
Ejemplo n.º 19
0
 def test_lookup_dispatch(self):
     req = MockRequest('/get_here')
     state = DispatchState(req, mock_lookup_dispatcher_with_args)
     state = state.resolve()
     assert state.method.__name__ == 'get_here', state.method
     assert state.controller.__class__.__name__ == 'MockLookupHelperWithArgs', state.controller
Ejemplo n.º 20
0
 def test_sub_dispatcher_bad_params_call_parent_default(self):
     req = MockRequest('/sub', params={'a':1})
     state = DispatchState(req, self.dispatcher) 
     state = state.resolve()
     assert state.method.__name__ == '_default', state.method
Ejemplo n.º 21
0
 def test_call(self):
     req = MockRequest('/')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.method.__name__ == 'index', state.method
Ejemplo n.º 22
0
 def test_check_security_with_nested_lookup(self):
     req = MockRequest('/nested/withsec/a')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
Ejemplo n.º 23
0
 def test_get_url(self):
     req = MockRequest('/sub', params={'_method':'custom'}, method='get')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.method.__name__ == 'get_custom', state.method
Ejemplo n.º 24
0
 def test_rest_lookup_doesnt_mess_with_subcontroller(self):
     req = MockRequest('/rest/sub/method')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.controller.__class__.__name__ == 'sub', state.controller
     assert state.method.__name__ == 'method', state.method
Ejemplo n.º 25
0
 def test_rest_with_lookup(self):
     req = MockRequest('/rest/somethingelse/method')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()
     assert state.controller.__class__.__name__ == 'sub', state.controller
     assert state.method.__name__ == 'method', state.method
Ejemplo n.º 26
0
 def test_sub_dispatcher_override_dispatch(self):
     req = MockRequest('/override_dispatch', params={'a':1})
     state = DispatchState(req, self.dispatcher) 
     state = state.resolve()
     assert state.method.__name__ == 'wacky', state.method
Ejemplo n.º 27
0
 def test_dispatch_default_with_unicode(self):
     req = MockRequest('/', params={u('å'):u('ß')})
     state = DispatchState(req, self.dispatcher) 
     state = state.resolve()
     assert state.method.__name__ == '_default', state.method
Ejemplo n.º 28
0
 def test_lookup_dispatch_bad_params(self):
     req = MockRequest('/get_here', params={'a':1})
     state = DispatchState(req, mock_lookup_dispatcher_with_args)
     state = state.resolve()
Ejemplo n.º 29
0
 def test_controller_method_with_args(self):
     req = MockRequest('/with_args/a/b')
     state = DispatchState(req, self.dispatcher) 
     state = state.resolve()
     assert state.method.__name__ == 'with_args', state.method
Ejemplo n.º 30
0
 def test_disabled_path_translation_no_extension(self):
     req = MockRequest('/no.args')
     state = DispatchState(req, mock_dispatcher_with_no_default_or_index,
                           strip_extension=False, path_translator=None)
     state = state.resolve()
Ejemplo n.º 31
0
 def test_controller_method_with_args_missing_args_404_no_default(self):
     req = MockRequest('/with_args/a')
     state = DispatchState(req, mock_dispatcher_with_no_default)
     state = state.resolve()
     assert state.method.__name__ == '_default', state.method
Ejemplo n.º 32
0
 def test_controller_method_with_args_missing_args_index(self):
     req = MockRequest('/with_args/a')
     state = DispatchState(req, mock_dispatcher_with_index_with_argvars)
     state = state.resolve()
     assert state.method.__name__ == 'index', state.method
Ejemplo n.º 33
0
 def test_get_not_found(self):
     req = MockRequest('/sub', method='get')
     state = DispatchState(req, self.dispatcher)
     state = state.resolve()