Beispiel #1
0
def _make_req(environ,
              start_response,
              args={},
              arg_list=(),
              authname='admin',
              form_token='A' * 40,
              chrome={
                  'links': {},
                  'scripts': [],
                  'theme': 'theme.html',
                  'logo': '',
                  'nav': ''
              },
              perm=MockPerm(),
              tz=utc,
              locale=None,
              **kwargs):
    req = Request(environ, start_response)
    req.args = args
    req.arg_list = arg_list
    req.authname = authname
    req.form_token = form_token
    req.chrome = chrome
    req.perm = perm
    req.session = FakeSession()
    req.tz = tz
    req.locale = locale
    for name, value in kwargs.iteritems():
        setattr(req, name, value)
    return req
 def _create_request(self):
     languages = filter(None, [self.config.get('trac', 'default_language')])
     if languages:
         locale = _parse_locale(languages[0])
     else:
         locale = None
     tzname = self.config.get('trac', 'default_timezone')
     tz = get_timezone(tzname) or localtz
     environ = {'REQUEST_METHOD': 'POST', 'REMOTE_ADDR': '127.0.0.1',
                'SERVER_NAME': 'localhost', 'SERVER_PORT': '80',
                'wsgi.url_scheme': 'http',
                'trac.base_url': self.env.abs_href()}
     if languages:
         environ['HTTP_ACCEPT_LANGUAGE'] = ','.join(languages)
     req = Request(environ, lambda *args, **kwargs: None)
     req.arg_list = ()
     req.args = {}
     req.authname = 'anonymous'
     req.session = FakeSession({'dateinfo': 'absolute'})
     req.perm = MockPerm()
     req.href = req.abs_href
     req.locale = locale
     req.lc_time = locale
     req.tz = tz
     req.chrome = {'notices': [], 'warnings': []}
     return req
Beispiel #3
0
    def setUp(self):
        self._prepare_env()

        self._setup_test_log(self.global_env)
        formatter.WikiTestCase.setUp(self)
        if self.context.req:
            self.context.req.session = FakeSession()
        if self.mpctx:
            candidates = set(
                self.mpctx.get('load_products', []) +
                [self.mpctx.get('main_product')])
            candidates -= set(
                [self.default_product, None,
                 self.mpctx.get('setup_product')])
            for prefix in candidates:
                self._load_product_from_data(self.env, prefix)

            prefix = self.mpctx.get('main_product', NotImplemented)
            if prefix is None:
                self.env = self.global_env
            elif prefix is not NotImplemented \
                    and (self.env is self.global_env or
                         prefix != self.env.product.prefix):
                self.env = ProductEnvironment(self.global_env, prefix)
            # Enable multi-product components
            self.env.config.set('components', 'multiproduct.*', 'enabled')
Beispiel #4
0
def _make_req(environ,
              authname='admin',
              chrome=None,
              form_token='A' * 40,
              locale=None,
              perm=MockPerm(),
              tz=utc,
              use_xsendfile=False,
              xsendfile_header='X-Sendfile'):
    if chrome is None:
        chrome = {
            'links': {},
            'scripts': [],
            'theme': 'theme.html',
            'logo': '',
            'nav': ''
        }

    class RequestWithSentAttrs(Request):
        """Subclass of `Request` with "sent" attributes."""
        def __init__(self, environ):
            self.status_sent = []
            self.headers_sent = {}
            self._response_sent = io.BytesIO()

            def write(data):
                self._response_sent.write(data)

            def start_response(status, headers, exc_info=None):
                self.status_sent.append(status)
                self.headers_sent.update(dict(headers))
                return write

            super(RequestWithSentAttrs, self).__init__(environ, start_response)

        @property
        def response_sent(self):
            return self._response_sent.getvalue()

    req = RequestWithSentAttrs(environ)
    # Setup default callbacks.
    req.authname = authname
    req.chrome = chrome
    req.form_token = form_token
    req.locale = locale
    req.perm = perm
    req.session = FakeSession()
    req.tz = tz
    req.use_xsendfile = use_xsendfile
    req.xsendfile_header = xsendfile_header
    return req
Beispiel #5
0
    def _create_request(self, chrome):
        req = Request(
            {
                'REQUEST_METHOD': 'GET',
                'trac.base_url': self.env.abs_href(),
            }, lambda *args, **kwargs: None)
        req.arg_list = ()
        req.args = {}
        req.authname = 'anonymous'
        req.session = FakeSession({'dateinfo': 'absolute'})
        req.perm = PermissionCache(self.env, req.authname)
        req.href = req.abs_href
        req.callbacks.update({
            'chrome': chrome.prepare_request,
            'tz': self._get_tz,
            'locale': self._get_locale,
            'lc_time': lambda req: 'iso8601',
        })

        return req