diff options
| author | Martin Trigaux <mat@odoo.com> | 2019-07-12 13:09:45 +0000 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2019-07-12 13:59:35 +0000 |
| commit | 1f5a4649a67908ecb6acfec37673c8149de0471f (patch) | |
| tree | 2a8ac12942b2e6227459a236309054982a01158f /addons/website/tools.py | |
| parent | 6532b8716520d8cddc23a1e42c5c602b0c9c3c88 (diff) | |
| parent | 87fc1554d6a1823ac9061aab089adfd052190d21 (diff) | |
[MERGE] Forward port of saas-12.3 to saas-12.4 up to 87fc1554d6a1823
closes odoo/odoo#34820
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'addons/website/tools.py')
| -rw-r--r-- | addons/website/tools.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/addons/website/tools.py b/addons/website/tools.py index 2abe896afff..e3bb897ec52 100644 --- a/addons/website/tools.py +++ b/addons/website/tools.py @@ -1,7 +1,11 @@ # -*- encoding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import odoo import re +import werkzeug + +from odoo.tools import DotDict def get_video_embed_code(video_url): @@ -49,3 +53,59 @@ def get_video_embed_code(video_url): # We directly use the provided URL as it is embedUrl = video_url return '<iframe class="embed-responsive-item" src="%s" allowFullScreen="true" frameborder="0"></iframe>' % embedUrl + + +class MockObject(object): + _log_call = [] + + def __init__(self, *args, **kwargs): + self.__dict__ = kwargs + + def __call__(self, *args, **kwargs): + self._log_call.append((args, kwargs)) + return self + + def __getitem__(self, index): + return self + + +def werkzeugRaiseNotFound(*args, **kwargs): + raise werkzeug.exceptions.NotFound() + + +class MockRequest(object): + """ Class with context manager mocking odoo.http.request for tests """ + def __init__(self, env, **kw): + app = MockObject(routing={ + 'type': 'http', + 'website': True, + 'multilang': kw.get('multilang', True), + }) + app.get_db_router = app.bind = app.match = app + if not kw.get('routing', True): + app.match = werkzeugRaiseNotFound + self.request = DotDict({ + 'context': kw.get('context', {}), + 'db': None, + 'env': env, + 'httprequest': { + 'path': '/hello/', + 'app': app, + }, + 'redirect': werkzeug.utils.redirect, + 'session': { + 'geoip': { + 'country_code': kw.get('country_code'), + }, + 'debug': False, + 'sale_order_id': kw.get('sale_order_id'), + }, + 'website': kw.get('website'), + }) + odoo.http._request_stack.push(self.request) + + def __enter__(self): + return self.request + + def __exit__(self, exc_type, exc_value, traceback): + odoo.http._request_stack.pop() |
