summaryrefslogtreecommitdiff
path: root/addons/website/tools.py
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-15 07:07:48 +0000
committerMartin Trigaux <mat@odoo.com>2019-07-15 08:12:26 +0000
commitfd15ca19183a765e1307c4d197bf0dda30b73ab7 (patch)
tree896042073ebc752e8bcf535f21696320c69bbe13 /addons/website/tools.py
parent6b8a0beda65dce688ecd0ee34828097b67a13dab (diff)
parent1f5a4649a67908ecb6acfec37673c8149de0471f (diff)
[MERGE] Forward port of saas-12.4 to master up to 1f5a4649a67908
closes odoo/odoo#34850 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'addons/website/tools.py')
-rw-r--r--addons/website/tools.py60
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()