[MOV] website, test_website: move test using data file to test_website
When the QWeb `<template>` loading test was introduced at [1], the `test_website` module did not exist yet, see [2]. This commit moves that test and its related data file to `test_website` to remove the `fake data` noise from the `website` module. That's one of the two purpose of this `test_website` module: - Avoid noising the website module with test only data & code - Encapsulate in a lighter module the module operations tests, but it's not really the case anymore as those tests are now standalone tests. See manifest for more details. [1]: https://github.com/odoo/odoo/commit/9cd982bcc811cacb42f5c08db139043d2734b891 [2]: https://github.com/odoo/odoo/commit/ef03db9edd9472201cb2c08a32d20ff0f33a5fdf closes odoo/odoo#109349 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
@@ -24,6 +24,15 @@ models which only purpose is to run tests.""",
|
||||
],
|
||||
'installable': True,
|
||||
'assets': {
|
||||
'test_website.test_bundle': [
|
||||
'/web/static/lib/qweb/qweb2.js',
|
||||
'http://test.external.link/javascript1.js',
|
||||
'/web/static/lib/jquery.ui/jquery-ui.css',
|
||||
'http://test.external.link/style1.css',
|
||||
'/web/static/src/boot.js',
|
||||
'http://test.external.link/javascript2.js',
|
||||
'http://test.external.link/style2.css',
|
||||
],
|
||||
'web.assets_frontend': [
|
||||
'test_website/static/src/js/test_error.js',
|
||||
],
|
||||
|
||||
@@ -11,6 +11,7 @@ from . import test_media
|
||||
from . import test_multi_company
|
||||
from . import test_page
|
||||
from . import test_performance
|
||||
from . import test_qweb
|
||||
from . import test_redirect
|
||||
from . import test_reset_views
|
||||
from . import test_session
|
||||
|
||||
+4
-4
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<template id="website.test_template" name="test template 2">
|
||||
<template id="test_website.test_template" name="test template 2">
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<t t-call-assets="website.test_bundle" t-js="False"/>
|
||||
<t t-call-assets="test_website.test_bundle" t-js="False"/>
|
||||
<meta/>
|
||||
<t t-call-assets="website.test_bundle" t-css="False"/>
|
||||
<t t-call-assets="test_website.test_bundle" t-css="False"/>
|
||||
</head>
|
||||
<body>
|
||||
<img src="http://test.external.link/img.png"/>
|
||||
<img src="/website/static/img.png"/>
|
||||
<img src="/test_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>
|
||||
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from lxml import etree
|
||||
import re
|
||||
|
||||
from odoo import tools
|
||||
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo
|
||||
from odoo.modules.module import get_module_resource
|
||||
|
||||
|
||||
class TestQweb(TransactionCaseWithUserDemo):
|
||||
def _load(self, module, *args):
|
||||
tools.convert_file(
|
||||
self.cr, 'test_website',
|
||||
get_module_resource(module, *args),
|
||||
{}, 'init', False, 'test'
|
||||
)
|
||||
|
||||
def test_qweb_cdn(self):
|
||||
self._load('test_website', 'tests', 'template_qweb_test.xml')
|
||||
|
||||
website = self.env.ref('website.default_website')
|
||||
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('test_website.test_template', {"user": demo}, website_id=website.id)
|
||||
asset_data = etree.HTML(html).xpath('//*[@data-asset-bundle]')[0]
|
||||
asset_xmlid = asset_data.attrib.get('data-asset-bundle')
|
||||
asset_version = asset_data.attrib.get('data-asset-version')
|
||||
|
||||
html = html.strip()
|
||||
html = re.sub(r'\?unique=[^"]+', '', html).encode('utf8')
|
||||
|
||||
attachments = demo_env['ir.attachment'].search([('url', '=like', '/web/assets/%-%/test_website.test_bundle.%')])
|
||||
self.assertEqual(len(attachments), 2)
|
||||
|
||||
format_data = {
|
||||
"js": attachments[0].url,
|
||||
"css": attachments[1].url,
|
||||
"user_id": demo.id,
|
||||
"filename": "Marc%20Demo",
|
||||
"alt": "Marc Demo",
|
||||
"asset_xmlid": asset_xmlid,
|
||||
"asset_version": asset_version,
|
||||
}
|
||||
self.assertHTMLEqual(html, ("""<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link type="text/css" rel="stylesheet" href="http://test.external.link/style1.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="http://test.external.link/style2.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="http://test.cdn%(css)s" data-asset-bundle="%(asset_xmlid)s" data-asset-version="%(asset_version)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" data-asset-bundle="%(asset_xmlid)s" data-asset-version="%(asset_version)s"></script>
|
||||
</head>
|
||||
<body>
|
||||
<img src="http://test.external.link/img.png" loading="lazy"/>
|
||||
<img src="http://test.cdn/test_website/static/img.png" loading="lazy"/>
|
||||
<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" loading="lazy">
|
||||
</span></div>
|
||||
<div widget="image"><img src="http://test.cdn/web/image/res.users/%(user_id)s/avatar_1920/%(filename)s" class="img img-fluid" alt="%(alt)s" loading="lazy"/></div>
|
||||
</body>
|
||||
</html>""" % format_data).encode('utf8'))
|
||||
@@ -287,15 +287,6 @@
|
||||
# Don't include dark mode files in light mode
|
||||
('remove', 'website/static/src/components/dialog/*.dark.scss'),
|
||||
],
|
||||
'website.test_bundle': [
|
||||
'/web/static/lib/qweb/qweb2.js',
|
||||
'http://test.external.link/javascript1.js',
|
||||
'/web/static/lib/jquery.ui/jquery-ui.css',
|
||||
'http://test.external.link/style1.css',
|
||||
'/web/static/src/boot.js',
|
||||
'http://test.external.link/javascript2.js',
|
||||
'http://test.external.link/style2.css',
|
||||
],
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from lxml import etree
|
||||
import re
|
||||
|
||||
from odoo import http, tools
|
||||
from odoo import http
|
||||
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo
|
||||
from odoo.addons.website.tools import MockRequest
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestQweb(TransactionCaseWithUserDemo):
|
||||
def _load(self, module, *args):
|
||||
tools.convert_file(self.cr, 'website',
|
||||
get_module_resource(module, *args),
|
||||
{}, 'init', False, 'test')
|
||||
|
||||
def test_qweb_post_processing_att(self):
|
||||
website = self.env.ref('website.default_website')
|
||||
t = self.env['ir.ui.view'].create({
|
||||
@@ -34,66 +25,6 @@ class TestQweb(TransactionCaseWithUserDemo):
|
||||
rendered = self.env['ir.qweb']._render(t.id, {'url': 'http://test.external.img/img2.png'}, website_id=website.id)
|
||||
self.assertEqual(rendered.strip(), result.strip())
|
||||
|
||||
def test_qweb_cdn(self):
|
||||
self._load('website', 'tests', 'template_qweb_test.xml')
|
||||
|
||||
website = self.env.ref('website.default_website')
|
||||
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)
|
||||
asset_data = etree.HTML(html).xpath('//*[@data-asset-bundle]')[0]
|
||||
asset_xmlid = asset_data.attrib.get('data-asset-bundle')
|
||||
asset_version = asset_data.attrib.get('data-asset-version')
|
||||
|
||||
html = html.strip()
|
||||
html = re.sub(r'\?unique=[^"]+', '', html).encode('utf8')
|
||||
|
||||
attachments = demo_env['ir.attachment'].search([('url', '=like', '/web/assets/%-%/website.test_bundle.%')])
|
||||
self.assertEqual(len(attachments), 2)
|
||||
|
||||
format_data = {
|
||||
"js": attachments[0].url,
|
||||
"css": attachments[1].url,
|
||||
"user_id": demo.id,
|
||||
"filename": "Marc%20Demo",
|
||||
"alt": "Marc Demo",
|
||||
"asset_xmlid": asset_xmlid,
|
||||
"asset_version": asset_version,
|
||||
}
|
||||
self.assertHTMLEqual(html, ("""<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link type="text/css" rel="stylesheet" href="http://test.external.link/style1.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="http://test.external.link/style2.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="http://test.cdn%(css)s" data-asset-bundle="%(asset_xmlid)s" data-asset-version="%(asset_version)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" data-asset-bundle="%(asset_xmlid)s" data-asset-version="%(asset_version)s"></script>
|
||||
</head>
|
||||
<body>
|
||||
<img src="http://test.external.link/img.png" loading="lazy"/>
|
||||
<img src="http://test.cdn/website/static/img.png" loading="lazy"/>
|
||||
<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" loading="lazy">
|
||||
</span></div>
|
||||
<div widget="image"><img src="http://test.cdn/web/image/res.users/%(user_id)s/avatar_1920/%(filename)s" class="img img-fluid" alt="%(alt)s" loading="lazy"/></div>
|
||||
</body>
|
||||
</html>""" % format_data).encode('utf8'))
|
||||
|
||||
|
||||
class TestQwebProcessAtt(TransactionCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user