diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-07-05 11:13:53 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-07-05 11:13:53 +0200 |
| commit | 039e6bae9916aaa9d82bc558817a7ed7d0ea3c68 (patch) | |
| tree | fa0f0e71de1c077db86593704eb83fc1b2115e87 /addons/website/tools.py | |
| parent | 50d21df1561f660c184329cfc4cb567ea5d79ace (diff) | |
| parent | 9c742d0c656412beba7201085abd4cecc81f5d27 (diff) | |
[MERGE] forward port branch 12.0 up to 9c742d0c656
Diffstat (limited to 'addons/website/tools.py')
| -rw-r--r-- | addons/website/tools.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/addons/website/tools.py b/addons/website/tools.py new file mode 100644 index 00000000000..e634db9d603 --- /dev/null +++ b/addons/website/tools.py @@ -0,0 +1,63 @@ +# -*- encoding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import odoo +import werkzeug + +from odoo.tools import DotDict + + +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, + 'debug': False, + 'env': env, + 'httprequest': { + 'path': '/hello/', + 'app': app, + }, + 'redirect': werkzeug.utils.redirect, + 'session': { + 'geoip': { + 'country_code': kw.get('country_code'), + }, + '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() |
