summaryrefslogtreecommitdiff
path: root/addons/website/tests
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-06-28 19:01:52 +0200
committerChristophe Simonis <chs@odoo.com>2018-06-28 19:01:52 +0200
commitc8bb02141d2801c243ae65ba6800b07f090bb5c6 (patch)
tree2d099c5577df4783a6db3d853cf0141bf41c1aa9 /addons/website/tests
parent4e2733e83a1f42773fb28f66431a0d6fb0393be9 (diff)
parent3cdcbce93cbde548d2d24426ee8de1d93f06706e (diff)
[MERGE] forward port branch saas-11.3 up to 3cdcbce93cb
Diffstat (limited to 'addons/website/tests')
-rw-r--r--addons/website/tests/__init__.py1
-rw-r--r--addons/website/tests/template_qweb_test.xml36
-rw-r--r--addons/website/tests/test_qweb.py65
3 files changed, 102 insertions, 0 deletions
diff --git a/addons/website/tests/__init__.py b/addons/website/tests/__init__.py
index 121eff4ff44..a4415acbb7d 100644
--- a/addons/website/tests/__init__.py
+++ b/addons/website/tests/__init__.py
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_converter
+from . import test_qweb
from . import test_crawl
from . import test_ui
from . import test_views
diff --git a/addons/website/tests/template_qweb_test.xml b/addons/website/tests/template_qweb_test.xml
new file mode 100644
index 00000000000..423c8d3212e
--- /dev/null
+++ b/addons/website/tests/template_qweb_test.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <template id="website.test_bundle">
+ <script type="text/javascript" src="/web/static/lib/qweb/qweb2.js"></script>
+ <script type="text/javascript" src="http://test.external.link/javascript1.js"></script>
+
+ <link rel="stylesheet" type="text/css" href="/web/static/lib/jquery.ui/jquery-ui.css"/>
+ <link rel="stylesheet" href="http://test.external.link/style1.css"/>
+
+ <script type="text/javascript" src="/web/static/src/js/boot.js"></script>
+ <script type="text/javascript" src="http://test.external.link/javascript2.js"></script>
+
+ <link rel="stylesheet" href="http://test.external.link/style2.css"/>
+ </template>
+
+ <template id="website.test_template" name="test template 2">
+&lt;!DOCTYPE html&gt;
+<html>
+ <head>
+ <t t-call-assets="website.test_bundle" t-js="False"/>
+ <meta/>
+ <t t-call-assets="website.test_bundle" t-css="False"/>
+ </head>
+ <body>
+ <img src="http://test.external.link/img.png"/>
+ <img src="/website/static/img.png"/>
+ <a href="http://test.external.link/link">x</a>
+ <a href="/web/content/local_link">x</a>
+ <span t-attf-style="background-image: url('/web/image/2')" t-att-empty="False">xxx</span>
+ <div widget="html" t-field="user.signature"/>
+ <div widget="image" t-field="user.image" t-options="{'widget': 'image'}"/>
+ </body>
+</html>
+ </template>
+
+</odoo> \ No newline at end of file
diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py
new file mode 100644
index 00000000000..e73083a66b2
--- /dev/null
+++ b/addons/website/tests/test_qweb.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import re
+
+from odoo import tools
+from odoo.modules.module import get_module_resource
+from odoo.tests.common import TransactionCase
+
+
+class TestQweb(TransactionCase):
+ def _load(self, module, *args):
+ tools.convert_file(self.cr, 'website',
+ get_module_resource(module, *args),
+ {}, 'init', False, 'test', self.registry._assertion_report)
+
+ def test_qweb_cdn(self):
+ self._load('website', 'tests', 'template_qweb_test.xml')
+
+ website = self.env['website'].browse(1)
+ website.write({
+ "cdn_activated": True,
+ "cdn_url": "http://test.cdn"
+ })
+
+ demo = self.env['res.users'].search([('login', '=', 'demo')])[0]
+ demo.write({"signature": '''<span class="toto">
+ span<span class="fa"></span><img src="/web/image/1"/>
+ </span>'''})
+
+ demo_env = self.env(user=demo)
+
+ html = demo_env['ir.qweb'].render('website.test_template', {"user": demo}, website_id= website.id)
+ html = html.strip().decode('utf8')
+ html = re.sub(r'\?unique=[^"]+', '', html).encode('utf8')
+
+ attachments = demo_env['ir.attachment'].search([('url', '=like', '/web/content/%-%/website.test_bundle.%')])
+ self.assertEqual(len(attachments), 2)
+ self.assertEqual(html, ("""<!DOCTYPE html>
+<html>
+ <head>
+ <link rel="stylesheet" href="http://test.external.link/style1.css"/>
+ <link rel="stylesheet" href="http://test.external.link/style2.css"/>
+ <link type="text/css" rel="stylesheet" href="http://test.cdn%(css)s"/>
+ <meta/>
+ <script type="text/javascript" src="http://test.external.link/javascript1.js"></script>
+ <script type="text/javascript" src="http://test.external.link/javascript2.js"></script>
+ <script type="text/javascript" src="http://test.cdn%(js)s"></script>
+ </head>
+ <body>
+ <img src="http://test.external.link/img.png"/>
+ <img src="http://test.cdn/website/static/img.png"/>
+ <a href="http://test.external.link/link">x</a>
+ <a href="http://test.cdn/web/content/local_link">x</a>
+ <span style="background-image: url('http://test.cdn/web/image/2')">xxx</span>
+ <div widget="html"><span class="toto">
+ span<span class="fa"></span><img src="http://test.cdn/web/image/1">
+ </span></div>
+ <div widget="image"><img src="http://test.cdn/web/image/res.users/%(user_id)s/image" class="img img-responsive"/></div>
+ </body>
+</html>""" % {
+ "js": attachments[0].url,
+ "css": attachments[1].url,
+ "user_id": demo.id,
+ }).encode('utf8'))