Example #1
0
    def theme_customize(self, enable, disable, get_bundle=False):
        """ enable or Disable lists of ``xml_id`` of the inherit templates
        """
        cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
        view = pool["ir.ui.view"]
        context = dict(request.context or {}, active_test=True)

        def set_active(ids, active):
            if ids:
                view.write(cr,
                           uid,
                           self.get_view_ids(ids), {'active': active},
                           context=context)

        set_active(disable, False)
        set_active(enable, True)

        if get_bundle:
            bundle = AssetsBundle('website.assets_frontend',
                                  cr=http.request.cr,
                                  uid=http.request.uid,
                                  context={},
                                  registry=http.request.registry)
            return bundle.to_html()

        return True
Example #2
0
 def _bundle(self, should_create, should_unlink):
     self.counter.clear()
     files, remains = self.env['ir.qweb']._get_asset_content(self.lessbundle_xmlid, {})
     asset = AssetsBundle(self.lessbundle_xmlid, files, remains, env=self.env)
     asset.to_html(debug='assets')
     self.assertEquals(self.counter['create'], int(should_create))
     self.assertEquals(self.counter['unlink'], int(should_unlink))
Example #3
0
 def test_08_paginated_css_generation3(self):
     # self.cssbundle_xlmid contains 3 rules
     self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                env=self.env,
                                max_css_rules=3)
     self.bundle.css()
     self.assertEquals(len(self._any_ira_for_bundle('css')), 1)
     self.assertEquals(len(self.bundle.get_attachments('css')), 1)
Example #4
0
    def test_13_paginated_css_order(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                   env=self.env,
                                   max_css_rules=1)
        stylesheets = self.bundle.css()

        self.assertTrue(stylesheets[0].url.endswith('.0.css'))
        self.assertTrue(stylesheets[1].url.endswith('.1.css'))
        self.assertTrue(stylesheets[2].url.endswith('.2.css'))
Example #5
0
    def test_05_debug(self):
        """ Checks that a bundle rendered in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        content = debug_bundle.to_html(debug=True)
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/js/test_jsfile1.js', content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)
Example #6
0
    def test_12_paginated_css_debug(self):
        """ Check that a bundle in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        content = debug_bundle.to_html(debug=True)
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/css/test_cssfile1.css', content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('css')), 0)
Example #7
0
    def test_05_debug(self):
        """ Checks that a bundle rendered in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.jsbundle_xmlid, env=self.env)
        content = debug_bundle.to_html(debug='assets')
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/js/test_jsfile1.js',
                      content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)
Example #8
0
 def test_08_paginated_css_generation3(self):
     # self.cssbundle_xlmid contains 3 rules
     self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                cr=self.cr,
                                uid=self.uid,
                                context={},
                                registry=self.registry,
                                max_css_rules=3)
     self.bundle.css()
     self.assertEquals(len(self._any_ira_for_bundle('css')), 1)
     self.assertEquals(len(self.bundle.get_attachments('css')), 1)
Example #9
0
 def css_bundle(self, xmlid, version=None, page=None, **kw):
     try:
         bundle = AssetsBundle(xmlid)
     except QWebTemplateNotFound:
         return request.not_found()
     e_tag = request.httprequest.headers.get('If-None-Match')
     if e_tag and e_tag == bundle.checksum:
         return werkzeug.wrappers.Response(status=304)
     else:
         response = request.make_response(bundle.css(page), [('Content-Type', 'text/css')])
         return make_conditional(response, bundle.last_modified, etag=bundle.checksum, max_age=BUNDLE_MAXAGE)
Example #10
0
 def test_06_paginated_css_generation1(self):
     """ Checks that a bundle creates enough ir.attachment records when its `css` method is called
     for the first time while the number of css rules exceed the limit.
     """
     # note: changing the max_css_rules of a bundle does not invalidate its attachments
     # self.cssbundle_xlmid contains 3 rules
     self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                env=self.env,
                                max_css_rules=1)
     self.bundle.css()
     self.assertEquals(len(self._any_ira_for_bundle('css')), 3)
     self.assertEquals(len(self.bundle.get_attachments('css')), 3)
Example #11
0
    def test_13_paginated_css_order(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                   cr=self.cr,
                                   uid=self.uid,
                                   context={},
                                   registry=self.registry,
                                   max_css_rules=1)
        stylesheets = self.bundle.css()

        self.assertTrue(stylesheets[0].url.endswith('.0.css'))
        self.assertTrue(stylesheets[1].url.endswith('.1.css'))
        self.assertTrue(stylesheets[2].url.endswith('.2.css'))
Example #12
0
    def test_12_paginated_css_debug(self):
        """ Check that a bundle in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.cssbundle_xmlid,
                                    env=self.env,
                                    max_css_rules=1)
        content = debug_bundle.to_html(debug='assets')
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/css/test_cssfile1.css',
                      content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('css')), 0)
Example #13
0
    def test_02_access(self):
        """ Checks that the bundle's cache is working, i.e. that the bundle creates only one
        ir.attachment record when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, env=self.env)
        bundle0.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('js')[0])
        date0 = ira0.create_date

        bundle1 = AssetsBundle(self.jsbundle_xmlid, env=self.env)
        bundle1.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version1 = bundle1.version
        ira1 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('js')[0])
        date1 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date1)
Example #14
0
    def test_03_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle0.js()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'js',
                                 'test_jsfile1.js')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle1.js()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version
        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
Example #15
0
    def test_10_paginated_css_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid,
                               env=self.env,
                               max_css_rules=1)
        bundle0.css()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'css',
                                 'test_cssfile1.css')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.cssbundle_xmlid,
                               env=self.env,
                               max_css_rules=1)
        bundle1.css()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version

        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)
Example #16
0
    def test_01_generation(self):
        """ Checks that a bundle creates an ir.attachment record when its `js` method is called
        for the first time.
        """
        self.bundle = AssetsBundle(self.jsbundle_xmlid, env=self.env)

        # there shouldn't be any attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)
        self.assertEquals(len(self.bundle.get_attachments('js')), 0)

        # trigger the first generation and, thus, the first save in database
        self.bundle.js()

        # there should be one attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
        self.assertEquals(len(self.bundle.get_attachments('js')), 1)
Example #17
0
File: main.py Project: zdlll/odoo
 def livechat_lib(self, ext, **kwargs):
     asset = AssetsBundle("im_livechat.external_lib")
     # can't use /web/content directly because we don't have attachment ids (attachments must be created)
     status, headers, content = binary_content(id=getattr(asset, ext)().id,
                                               unique=asset.checksum)
     content_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(content_base64)))
     return request.make_response(content_base64, headers)
Example #18
0
 def test_08_paginated_css_generation3(self):
     # self.cssbundle_xlmid contains 3 rules
     self.bundle = AssetsBundle(
         self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=3
     )
     self.bundle.css()
     self.assertEquals(len(self._any_ira_for_bundle("css")), 1)
     self.assertEquals(len(self.bundle.get_attachments("css")), 1)
Example #19
0
    def test_13_paginated_css_order(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        stylesheets = self.bundle.css()

        self.assertTrue(stylesheets[0].url.endswith('.0.css'))
        self.assertTrue(stylesheets[1].url.endswith('.1.css'))
        self.assertTrue(stylesheets[2].url.endswith('.2.css'))
Example #20
0
    def test_13_paginated_css_order(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid, env=self.env, max_css_rules=1)
        stylesheets = self.bundle.css()

        self.assertTrue(stylesheets[0].url.endswith('.0.css'))
        self.assertTrue(stylesheets[1].url.endswith('.1.css'))
        self.assertTrue(stylesheets[2].url.endswith('.2.css'))
Example #21
0
    def test_09_paginated_css_access(self):
        """ Checks that the bundle's cache is working, i.e. that a bundle creates only enough
        ir.attachment records when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle0.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[0])
        date0 = ira0.create_date
        ira1 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[1])
        date1 = ira1.create_date
        ira2 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[2])
        date2 = ira2.create_date

        bundle1 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle1.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version1 = bundle1.version
        ira3 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[0])
        date3 = ira1.create_date
        ira4 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[1])
        date4 = ira1.create_date
        ira5 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[2])
        date5 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date3)
        self.assertEquals(date1, date4)
        self.assertEquals(date2, date5)
Example #22
0
    def theme_customize(self, enable, disable, get_bundle=False):
        """ enable or Disable lists of ``xml_id`` of the inherit templates
        """
        cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
        view = pool["ir.ui.view"]
        context = dict(request.context or {}, active_test=True)

        def set_active(ids, active):
            if ids:
                view.write(cr, uid, self.get_view_ids(ids), {'active': active}, context=context)

        set_active(disable, False)
        set_active(enable, True)

        if get_bundle:
            bundle = AssetsBundle('website.assets_frontend', cr=http.request.cr, uid=http.request.uid, context={}, registry=http.request.registry)
            return bundle.to_html()

        return True
Example #23
0
 def test_06_paginated_css_generation1(self):
     """ Checks that a bundle creates enough ir.attachment records when its `css` method is called
     for the first time while the number of css rules exceed the limit.
     """
     # note: changing the max_css_rules of a bundle does not invalidate its attachments
     # self.cssbundle_xlmid contains 3 rules
     self.bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
     self.bundle.css()
     self.assertEquals(len(self._any_ira_for_bundle('css')), 3)
     self.assertEquals(len(self.bundle.get_attachments('css')), 3)
Example #24
0
 def livechat_lib(self, ext, **kwargs):
     asset = AssetsBundle("im_livechat.external_lib")
     mock_attachment = getattr(asset, ext)()
     if isinstance(mock_attachment, list):  # suppose that CSS asset will not required to be split in pages
         mock_attachment = mock_attachment[0]
     # can't use /web/content directly because we don't have attachment ids (attachments must be created)
     status, headers, content = binary_content(id=mock_attachment.id, unique=asset.checksum)
     content_base64 = base64.b64decode(content) if content else ''
     headers.append(('Content-Length', len(content_base64)))
     return request.make_response(content_base64, headers)
Example #25
0
 def _bundle(self, should_create, should_unlink):
     self.mock_ira_create.reset_mock()
     self.mock_ira_unlink.reset_mock()
     AssetsBundle(self.lessbundle_xmlid,
                  cr=self.cr,
                  uid=self.uid,
                  context={},
                  registry=self.registry).to_html(debug=True)
     self.assertEquals(self.mock_ira_create.call_count, int(should_create))
     self.assertEquals(self.mock_ira_unlink.call_count, int(should_unlink))
Example #26
0
    def test_09_paginated_css_access(self):
        """ Checks that the bundle's cache is working, i.e. that a bundle creates only enough
        ir.attachment records when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle0.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[0])
        date0 = ira0.create_date
        ira1 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[1])
        date1 = ira1.create_date
        ira2 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[2])
        date2 = ira2.create_date

        bundle1 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle1.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version1 = bundle1.version
        ira3 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[0])
        date3 = ira1.create_date
        ira4 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[1])
        date4 = ira1.create_date
        ira5 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[2])
        date5 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date3)
        self.assertEquals(date1, date4)
        self.assertEquals(date2, date5)
Example #27
0
    def test_10_paginated_css_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(
            self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1
        )
        bundle0.css()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path("test_assetsbundle", "static", "src", "css", "test_cssfile1.css")
        utime(path, None)  # touch

        bundle1 = AssetsBundle(
            self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1
        )
        bundle1.css()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version

        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle("css")), 3)
Example #28
0
    def test_11_paginated_css_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle0.css()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/test_assetsbundle/static/src/css/test_cssfile2.css"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.cssbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(
            self.cr, self.uid, {
                'name': 'test bundle inheritance',
                'type': 'qweb',
                'arch': view_arch,
                'inherit_id': bundle_id,
            })

        bundle1 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={'check_view_ids': [newid]},
                               registry=self.registry,
                               max_css_rules=1)
        bundle1.css()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 4)
Example #29
0
    def test_04_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle0.js()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/test_assetsbundle/static/src/js/test_jsfile4.js"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.jsbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(
            self.cr, self.uid, {
                'name': 'test bundle inheritance',
                'type': 'qweb',
                'arch': view_arch,
                'inherit_id': bundle_id,
            })

        bundle1 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={'check_view_ids': [newid]},
                               registry=self.registry)
        bundle1.js()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
Example #30
0
    def test_01_generation(self):
        """ Checks that a bundle creates an ir.attachment record when its `js` method is called
        for the first time.
        """
        self.bundle = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)

        # there shouldn't be any attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)
        self.assertEquals(len(self.bundle.get_attachments('js')), 0)

        # trigger the first generation and, thus, the first save in database
        self.bundle.js()

        # there should be one attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
        self.assertEquals(len(self.bundle.get_attachments('js')), 1)
Example #31
0
File: main.py Project: ws-mps/odoo
    def livechat_lib(self, ext, **kwargs):
        # _get_asset return the bundle html code (script and link list) but we want to use the attachment content
        xmlid = 'im_livechat.external_lib'
        files, remains = request.env["ir.qweb"]._get_asset_content(
            xmlid, options=request.context)
        asset = AssetsBundle(xmlid, files, remains)

        mock_attachment = getattr(asset, ext)()
        if isinstance(
                mock_attachment, list
        ):  # suppose that CSS asset will not required to be split in pages
            mock_attachment = mock_attachment[0]
        # can't use /web/content directly because we don't have attachment ids (attachments must be created)
        status, headers, content = binary_content(id=mock_attachment.id,
                                                  unique=asset.checksum)
        content_base64 = base64.b64decode(content) if content else ''
        headers.append(('Content-Length', len(content_base64)))
        return request.make_response(content_base64, headers)
Example #32
0
    def test_11_paginated_css_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(
            self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1
        )
        bundle0.css()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle("css")), 3)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/test_assetsbundle/static/src/css/test_cssfile2.css"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.cssbundle_xmlid).id
        newid = self.registry["ir.ui.view"].create(
            self.cr,
            self.uid,
            {"name": "test bundle inheritance", "type": "qweb", "arch": view_arch, "inherit_id": bundle_id},
        )

        bundle1 = AssetsBundle(
            self.cssbundle_xmlid,
            cr=self.cr,
            uid=self.uid,
            context={"check_view_ids": [newid]},
            registry=self.registry,
            max_css_rules=1,
        )
        bundle1.css()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle("css")), 4)
Example #33
0
    def test_03_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle0.js()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'js', 'test_jsfile1.js')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle1.js()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version
        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
Example #34
0
    def test_10_paginated_css_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid, env=self.env, max_css_rules=1)
        bundle0.css()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'css', 'test_cssfile1.css')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.cssbundle_xmlid, env=self.env, max_css_rules=1)
        bundle1.css()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version

        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)
Example #35
0
    def test_04_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle0.js()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle("js")), 1)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/test_assetsbundle/static/src/js/test_jsfile4.js"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.jsbundle_xmlid).id
        newid = self.registry["ir.ui.view"].create(
            self.cr,
            self.uid,
            {"name": "test bundle inheritance", "type": "qweb", "arch": view_arch, "inherit_id": bundle_id},
        )

        bundle1 = AssetsBundle(
            self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={"check_view_ids": [newid]}, registry=self.registry
        )
        bundle1.js()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle("js")), 1)
Example #36
0
    def test_04_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, env=self.env)
        bundle0.js()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/test_assetsbundle/static/src/js/test_jsfile4.js"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.jsbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(self.cr, self.uid, {
            'name': 'test bundle inheritance',
            'type': 'qweb',
            'arch': view_arch,
            'inherit_id': bundle_id,
        })

        bundle1 = AssetsBundle(self.jsbundle_xmlid, env=self.env(context={'check_view_ids': [newid]}))
        bundle1.js()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
Example #37
0
    def test_11_paginated_css_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid, env=self.env, max_css_rules=1)
        bundle0.css()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/test_assetsbundle/static/src/css/test_cssfile2.css"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.cssbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(self.cr, self.uid, {
            'name': 'test bundle inheritance',
            'type': 'qweb',
            'arch': view_arch,
            'inherit_id': bundle_id,
        })

        bundle1 = AssetsBundle(self.cssbundle_xmlid, env=self.env(context={'check_view_ids': [newid]}), max_css_rules=1)
        bundle1.css()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 4)
Example #38
0
    def test_02_access(self):
        """ Checks that the bundle's cache is working, i.e. that the bundle creates only one
        ir.attachment record when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle0.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('js')[0])
        date0 = ira0.create_date

        bundle1 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle1.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version1 = bundle1.version
        ira1 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('js')[0])
        date1 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date1)
Example #39
0
 def _get_asset(self, xmlid, env=None):
     env = (env or self.env)
     files, remains = env['ir.qweb']._get_asset_content(xmlid, env.context)
     return AssetsBundle(xmlid, files, remains, env=env)
Example #40
0
 def _bundle(self, should_create, should_unlink):
     self.counter.clear()
     AssetsBundle(self.lessbundle_xmlid,
                  env=self.env).to_html(debug='assets')
     self.assertEquals(self.counter['create'], int(should_create))
     self.assertEquals(self.counter['unlink'], int(should_unlink))
Example #41
0
 def test_08_paginated_css_generation3(self):
     # self.cssbundle_xlmid contains 3 rules
     self.bundle = AssetsBundle(self.cssbundle_xmlid, env=self.env, max_css_rules=3)
     self.bundle.css()
     self.assertEquals(len(self._any_ira_for_bundle('css')), 1)
     self.assertEquals(len(self.bundle.get_attachments('css')), 1)
Example #42
0
class TestJavascriptAssetsBundle(TransactionCase):
    def setUp(self):
        super(TestJavascriptAssetsBundle, self).setUp()
        self.jsbundle_xmlid = 'test_assetsbundle.bundle1'
        self.cssbundle_xmlid = 'test_assetsbundle.bundle2'

    def _any_ira_for_bundle(self, type):
        """ Returns all ir.attachments associated to a bundle, regardless of the verion.
        """
        bundle = self.jsbundle_xmlid if type == 'js' else self.cssbundle_xmlid
        return self.registry['ir.attachment'].search(self.cr, self.uid,[
            ('url', '=like', '/web/content/%-%/{0}%.{1}'.format(bundle, type))
        ])

    def test_01_generation(self):
        """ Checks that a bundle creates an ir.attachment record when its `js` method is called
        for the first time.
        """
        self.bundle = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)

        # there shouldn't be any attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)
        self.assertEquals(len(self.bundle.get_attachments('js')), 0)

        # trigger the first generation and, thus, the first save in database
        self.bundle.js()

        # there should be one attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
        self.assertEquals(len(self.bundle.get_attachments('js')), 1)

    def test_02_access(self):
        """ Checks that the bundle's cache is working, i.e. that the bundle creates only one
        ir.attachment record when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle0.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('js')[0])
        date0 = ira0.create_date

        bundle1 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle1.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version1 = bundle1.version
        ira1 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('js')[0])
        date1 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date1)

    def test_03_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle0.js()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'js', 'test_jsfile1.js')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle1.js()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version
        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

    def test_04_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        bundle0.js()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/test_assetsbundle/static/src/js/test_jsfile4.js"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.jsbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(self.cr, self.uid, {
            'name': 'test bundle inheritance',
            'type': 'qweb',
            'arch': view_arch,
            'inherit_id': bundle_id,
        })

        bundle1 = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={'check_view_ids': [newid]}, registry=self.registry)
        bundle1.js()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

    def test_05_debug(self):
        """ Checks that a bundle rendered in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.jsbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry)
        content = debug_bundle.to_html(debug=True)
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/js/test_jsfile1.js', content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)

    def test_06_paginated_css_generation1(self):
        """ Checks that a bundle creates enough ir.attachment records when its `css` method is called
        for the first time while the number of css rules exceed the limit.
        """
        # note: changing the max_css_rules of a bundle does not invalidate its attachments
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        self.bundle.css()
        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)
        self.assertEquals(len(self.bundle.get_attachments('css')), 3)

    def test_07_paginated_css_generation2(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=2)
        self.bundle.css()
        self.assertEquals(len(self._any_ira_for_bundle('css')), 2)
        self.assertEquals(len(self.bundle.get_attachments('css')), 2)

    def test_08_paginated_css_generation3(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=3)
        self.bundle.css()
        self.assertEquals(len(self._any_ira_for_bundle('css')), 1)
        self.assertEquals(len(self.bundle.get_attachments('css')), 1)

    def test_09_paginated_css_access(self):
        """ Checks that the bundle's cache is working, i.e. that a bundle creates only enough
        ir.attachment records when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle0.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[0])
        date0 = ira0.create_date
        ira1 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[1])
        date1 = ira1.create_date
        ira2 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[2])
        date2 = ira2.create_date

        bundle1 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle1.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version1 = bundle1.version
        ira3 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[0])
        date3 = ira1.create_date
        ira4 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[1])
        date4 = ira1.create_date
        ira5 = self.registry['ir.attachment'].browse(self.cr, self.uid, self._any_ira_for_bundle('css')[2])
        date5 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date3)
        self.assertEquals(date1, date4)
        self.assertEquals(date2, date5)

    def test_10_paginated_css_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle0.css()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'css', 'test_cssfile1.css')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle1.css()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version

        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

    def test_11_paginated_css_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        bundle0.css()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/test_assetsbundle/static/src/css/test_cssfile2.css"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.cssbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(self.cr, self.uid, {
            'name': 'test bundle inheritance',
            'type': 'qweb',
            'arch': view_arch,
            'inherit_id': bundle_id,
        })

        bundle1 = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={'check_view_ids': [newid]}, registry=self.registry, max_css_rules=1)
        bundle1.css()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 4)

    def test_12_paginated_css_debug(self):
        """ Check that a bundle in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        content = debug_bundle.to_html(debug=True)
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/css/test_cssfile1.css', content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('css')), 0)

    def test_13_paginated_css_order(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid, cr=self.cr, uid=self.uid, context={}, registry=self.registry, max_css_rules=1)
        stylesheets = self.bundle.css()

        self.assertTrue(stylesheets[0].url.endswith('.0.css'))
        self.assertTrue(stylesheets[1].url.endswith('.1.css'))
        self.assertTrue(stylesheets[2].url.endswith('.2.css'))
Example #43
0
class TestJavascriptAssetsBundle(TransactionCase):
    def setUp(self):
        super(TestJavascriptAssetsBundle, self).setUp()
        self.jsbundle_xmlid = 'test_assetsbundle.bundle1'
        self.cssbundle_xmlid = 'test_assetsbundle.bundle2'

    def _any_ira_for_bundle(self, type):
        """ Returns all ir.attachments associated to a bundle, regardless of the verion.
        """
        bundle = self.jsbundle_xmlid if type == 'js' else self.cssbundle_xmlid
        return self.registry['ir.attachment'].search(self.cr, self.uid, [
            ('url', '=like', '/web/content/%-%/{0}%.{1}'.format(bundle, type))
        ])

    def test_01_generation(self):
        """ Checks that a bundle creates an ir.attachment record when its `js` method is called
        for the first time.
        """
        self.bundle = AssetsBundle(self.jsbundle_xmlid,
                                   cr=self.cr,
                                   uid=self.uid,
                                   context={},
                                   registry=self.registry)

        # there shouldn't be any attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)
        self.assertEquals(len(self.bundle.get_attachments('js')), 0)

        # trigger the first generation and, thus, the first save in database
        self.bundle.js()

        # there should be one attachment associated to this bundle
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)
        self.assertEquals(len(self.bundle.get_attachments('js')), 1)

    def test_02_access(self):
        """ Checks that the bundle's cache is working, i.e. that the bundle creates only one
        ir.attachment record when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle0.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('js')[0])
        date0 = ira0.create_date

        bundle1 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle1.js()

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        version1 = bundle1.version
        ira1 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('js')[0])
        date1 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date1)

    def test_03_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle0.js()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'js',
                                 'test_jsfile1.js')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle1.js()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version
        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

    def test_04_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry)
        bundle0.js()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/test_assetsbundle/static/src/js/test_jsfile4.js"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.jsbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(
            self.cr, self.uid, {
                'name': 'test bundle inheritance',
                'type': 'qweb',
                'arch': view_arch,
                'inherit_id': bundle_id,
            })

        bundle1 = AssetsBundle(self.jsbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={'check_view_ids': [newid]},
                               registry=self.registry)
        bundle1.js()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('js')), 1)

    def test_05_debug(self):
        """ Checks that a bundle rendered in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.jsbundle_xmlid,
                                    cr=self.cr,
                                    uid=self.uid,
                                    context={},
                                    registry=self.registry)
        content = debug_bundle.to_html(debug=True)
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/js/test_jsfile1.js',
                      content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('js')), 0)

    def test_06_paginated_css_generation1(self):
        """ Checks that a bundle creates enough ir.attachment records when its `css` method is called
        for the first time while the number of css rules exceed the limit.
        """
        # note: changing the max_css_rules of a bundle does not invalidate its attachments
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                   cr=self.cr,
                                   uid=self.uid,
                                   context={},
                                   registry=self.registry,
                                   max_css_rules=1)
        self.bundle.css()
        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)
        self.assertEquals(len(self.bundle.get_attachments('css')), 3)

    def test_07_paginated_css_generation2(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                   cr=self.cr,
                                   uid=self.uid,
                                   context={},
                                   registry=self.registry,
                                   max_css_rules=2)
        self.bundle.css()
        self.assertEquals(len(self._any_ira_for_bundle('css')), 2)
        self.assertEquals(len(self.bundle.get_attachments('css')), 2)

    def test_08_paginated_css_generation3(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                   cr=self.cr,
                                   uid=self.uid,
                                   context={},
                                   registry=self.registry,
                                   max_css_rules=3)
        self.bundle.css()
        self.assertEquals(len(self._any_ira_for_bundle('css')), 1)
        self.assertEquals(len(self.bundle.get_attachments('css')), 1)

    def test_09_paginated_css_access(self):
        """ Checks that the bundle's cache is working, i.e. that a bundle creates only enough
        ir.attachment records when rendered multiple times.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle0.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version0 = bundle0.version
        ira0 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[0])
        date0 = ira0.create_date
        ira1 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[1])
        date1 = ira1.create_date
        ira2 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[2])
        date2 = ira2.create_date

        bundle1 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle1.css()

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        version1 = bundle1.version
        ira3 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[0])
        date3 = ira1.create_date
        ira4 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[1])
        date4 = ira1.create_date
        ira5 = self.registry['ir.attachment'].browse(
            self.cr, self.uid,
            self._any_ira_for_bundle('css')[2])
        date5 = ira1.create_date

        self.assertEquals(version0, version1)
        self.assertEquals(date0, date3)
        self.assertEquals(date1, date4)
        self.assertEquals(date2, date5)

    def test_10_paginated_css_date_invalidation(self):
        """ Checks that a bundle is invalidated when one of its assets' modification date is changed.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle0.css()
        last_modified0 = bundle0.last_modified
        version0 = bundle0.version

        path = get_resource_path('test_assetsbundle', 'static', 'src', 'css',
                                 'test_cssfile1.css')
        utime(path, None)  # touch

        bundle1 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle1.css()
        last_modified1 = bundle1.last_modified
        version1 = bundle1.version

        self.assertNotEquals(last_modified0, last_modified1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment is correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

    def test_11_paginated_css_content_invalidation(self):
        """ Checks that a bundle is invalidated when its content is modified by adding a file to
        source.
        """
        bundle0 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={},
                               registry=self.registry,
                               max_css_rules=1)
        bundle0.css()
        html0 = bundle0.html
        version0 = bundle0.version

        self.assertEquals(len(self._any_ira_for_bundle('css')), 3)

        view_arch = """
        <data>
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/test_assetsbundle/static/src/css/test_cssfile2.css"/>
            </xpath>
        </data>
        """
        bundle_id = self.browse_ref(self.cssbundle_xmlid).id
        newid = self.registry['ir.ui.view'].create(
            self.cr, self.uid, {
                'name': 'test bundle inheritance',
                'type': 'qweb',
                'arch': view_arch,
                'inherit_id': bundle_id,
            })

        bundle1 = AssetsBundle(self.cssbundle_xmlid,
                               cr=self.cr,
                               uid=self.uid,
                               context={'check_view_ids': [newid]},
                               registry=self.registry,
                               max_css_rules=1)
        bundle1.css()
        html1 = bundle1.html
        version1 = bundle1.version

        self.assertNotEquals(html0, html1)
        self.assertNotEquals(version0, version1)

        # check if the previous attachment are correctly cleaned
        self.assertEquals(len(self._any_ira_for_bundle('css')), 4)

    def test_12_paginated_css_debug(self):
        """ Check that a bundle in debug mode outputs non-minified assets.
        """
        debug_bundle = AssetsBundle(self.cssbundle_xmlid,
                                    cr=self.cr,
                                    uid=self.uid,
                                    context={},
                                    registry=self.registry,
                                    max_css_rules=1)
        content = debug_bundle.to_html(debug=True)
        # find back one of the original asset file
        self.assertIn('/test_assetsbundle/static/src/css/test_cssfile1.css',
                      content)

        # there shouldn't be any assets created in debug mode
        self.assertEquals(len(self._any_ira_for_bundle('css')), 0)

    def test_13_paginated_css_order(self):
        # self.cssbundle_xlmid contains 3 rules
        self.bundle = AssetsBundle(self.cssbundle_xmlid,
                                   cr=self.cr,
                                   uid=self.uid,
                                   context={},
                                   registry=self.registry,
                                   max_css_rules=1)
        stylesheets = self.bundle.css()

        self.assertTrue(stylesheets[0].url.endswith('.0.css'))
        self.assertTrue(stylesheets[1].url.endswith('.1.css'))
        self.assertTrue(stylesheets[2].url.endswith('.2.css'))