# -*- 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.env, '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 '''}) 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, (""" x x xxx
span
%(alt)s
""" % format_data).encode('utf8'))