Пример #1
0
def fake_request(form_data=None,
                 query_string=None,
                 method='GET',
                 content_type=None):
    data = urllib.parse.urlencode(form_data or {})
    query_string = query_string or ''
    content_type = content_type or 'application/x-www-form-urlencoded'
    # werkzeug request
    w_req = Request.from_values(query_string=query_string,
                                content_length=len(data),
                                input_stream=StringIO(data),
                                content_type=content_type,
                                method=method)
    w_req.session = mock.MagicMock()
    # odoo request
    o_req = http.HttpRequest(w_req)
    o_req.website = mock.MagicMock()
    o_req.csrf_token = mock.MagicMock()
    o_req.httprequest = w_req
    o_req.__testing__ = True
    return o_req
Пример #2
0
 def _fetch_image(self, path):
     public_user = self.env.ref('base.public_user')
     session_store = root_wsgi.session_store
     session = session_store.new()
     session.update({
         'db': threading.current_thread().dbname,
         'login': public_user.login,
         'uid': public_user.id,
         'context': self.env.context,
     })
     werkzeug_env = EnvironBuilder(path).get_environ()
     werkzeug_request = WerkzeugRequest(werkzeug_env)
     werkzeug_request.session = session
     # construct an odoo request with this werkzeug request.
     request = http.HttpRequest(werkzeug_request)
     with request:
         request._env = self.env(user=public_user)
         endpoint, arguments = http.routing_map(
             self.env.registry._init_modules, False,
             self.env['ir.http']._get_converters()).bind_to_environ(
                 werkzeug_env).match(return_rule=False, )
         yield endpoint, arguments
Пример #3
0
 def get_request(self, httprequest):
     if path_re.match(httprequest.path):
         return http.HttpRequest(httprequest)
     return orig_get_request(self, httprequest)