summaryrefslogtreecommitdiff
path: root/addons/website
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-12 13:09:45 +0000
committerMartin Trigaux <mat@odoo.com>2019-07-12 13:59:35 +0000
commit1f5a4649a67908ecb6acfec37673c8149de0471f (patch)
tree2a8ac12942b2e6227459a236309054982a01158f /addons/website
parent6532b8716520d8cddc23a1e42c5c602b0c9c3c88 (diff)
parent87fc1554d6a1823ac9061aab089adfd052190d21 (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')
-rw-r--r--addons/website/static/src/js/content/snippets.animation.js2
-rw-r--r--addons/website/static/tests/tours/rte.js2
-rw-r--r--addons/website/tests/test_qweb.py56
-rw-r--r--addons/website/tools.py60
4 files changed, 70 insertions, 50 deletions
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index 33e1e01ebcc..ab7f4218a5b 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -76,7 +76,7 @@ publicWidget.Widget.include({
this.editableMode = this.options.editableMode || false;
var extraEvents = this.editableMode ? this.edit_events : this.read_events;
if (extraEvents) {
- this.events = _.extend(this.events || {}, extraEvents);
+ this.events = _.extend({}, this.events || {}, extraEvents);
}
},
});
diff --git a/addons/website/static/tests/tours/rte.js b/addons/website/static/tests/tours/rte.js
index 716562389e7..7b2c8511fc3 100644
--- a/addons/website/static/tests/tours/rte.js
+++ b/addons/website/static/tests/tours/rte.js
@@ -176,7 +176,7 @@ tour.register('rte_translator', {
}, {
content: "check bis: content is translated",
trigger: '#wrap p font:first:contains(translated french text)',
- extra_trigger: 'body:not(:has(button[data-action=save]))',
+ extra_trigger: 'html[lang*="fr"] body:not(:has(button[data-action=save]))',
}, {
content: "check bis: placeholder translation",
trigger: 'input[placeholder="test french placeholder"]',
diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py
index 5ca9344aa32..8e2eb382a40 100644
--- a/addons/website/tests/test_qweb.py
+++ b/addons/website/tests/test_qweb.py
@@ -2,10 +2,9 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import re
-import werkzeug
-import odoo
from odoo import tools
+from odoo.addons.website.tools import MockRequest
from odoo.modules.module import get_module_resource
from odoo.tests.common import TransactionCase
@@ -68,45 +67,6 @@ class TestQweb(TransactionCase):
"alt": "Marc Demo",
}).encode('utf8'))
-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, website=None, context=None, multilang=True, routing=True):
- app = MockObject(routing={
- 'type': 'http',
- 'website': True,
- 'multilang': multilang,
- })
- app.get_db_router = app.bind = app.match = app
- if not routing:
- app.match = werkzeugRaiseNotFound
- self.request = MockObject(
- env=env, context=context or {}, db=None,
- session=MockObject(
- debug=False
- ),
- website=website, httprequest=MockObject(
- path='/hello/',
- app=app
- )
- )
- 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()
class TestQwebProcessAtt(TransactionCase):
def setUp(self):
@@ -134,7 +94,7 @@ class TestQwebProcessAtt(TransactionCase):
self._test_att('/a', {'href': '/a'})
def test_process_att_no_website(self):
- with MockRequest(self.env) as request:
+ with MockRequest(self.env):
# no website so URL rewriting
self._test_att('/', {'href': '/'})
self._test_att('/en_US/', {'href': '/en_US/'})
@@ -143,7 +103,7 @@ class TestQwebProcessAtt(TransactionCase):
self._test_att('/a', {'href': '/a'})
def test_process_att_monolang_route(self):
- with MockRequest(self.env, website=self.website, multilang=False) as request:
+ with MockRequest(self.env, website=self.website, multilang=False):
# lang not changed in URL but CDN enabled
self._test_att('/a', {'href': 'http://test.cdn/a'})
self._test_att('/en_US/a', {'href': 'http://test.cdn/en_US/a'})
@@ -151,19 +111,19 @@ class TestQwebProcessAtt(TransactionCase):
self._test_att('/en_US/b', {'href': '/en_US/b'})
def test_process_att_no_request_lang(self):
- with MockRequest(self.env, self.website) as request:
+ with MockRequest(self.env, website=self.website):
self._test_att('/', {'href': '/'})
self._test_att('/en_US/', {'href': '/'})
self._test_att('/fr_FR/', {'href': '/fr_FR/'})
def test_process_att_with_request_lang(self):
- with MockRequest(self.env, self.website, context={'lang': 'fr_FR'}) as request:
+ with MockRequest(self.env, website=self.website, context={'lang': 'fr_FR'}):
self._test_att('/', {'href': '/fr_FR/'})
self._test_att('/en_US/', {'href': '/'})
self._test_att('/fr_FR/', {'href': '/fr_FR/'})
def test_process_att_matching_cdn_and_lang(self):
- with MockRequest(self.env, self.website) as request:
+ with MockRequest(self.env, website=self.website):
# lang prefix is added before CDN
self._test_att('/a', {'href': 'http://test.cdn/a'})
self._test_att('/en_US/a', {'href': 'http://test.cdn/a'})
@@ -173,13 +133,13 @@ class TestQwebProcessAtt(TransactionCase):
self._test_att('/fr_FR/b', {'href': '/fr_FR/b'})
def test_process_att_no_route(self):
- with MockRequest(self.env, self.website, context={'lang': 'fr_FR'}, routing=False) as request:
+ with MockRequest(self.env, website=self.website, context={'lang': 'fr_FR'}, routing=False):
# default on multilang=True if route is not /{module}/static/
self._test_att('/web/static/hi', {'href': '/web/static/hi'})
self._test_att('/my-page', {'href': '/fr_FR/my-page'})
def test_process_att_url_crap(self):
- with MockRequest(self.env, self.website) as request:
+ with MockRequest(self.env, website=self.website) as request:
# #{fragment} is stripped from URL when testing route
self._test_att('/x#y?z', {'href': '/x#y?z'})
self.assertEqual(
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()