Files
odoo_source/addons/bus/tests/test_assetsbundle.py
T
Aaron Bohy 93938cfdf3 [IMP] web,*: remove assets_backend_prod_only
This commit reworks a little bit the backend assets to remove a
bundle and thus save a call at webclient startup. The bundle
"assets_backend_prod_only" existed only to allow to add files in
production, but not in the tests (typically, the file that spawns
the webclient).

This commit introduces a new bundle "web.assets_web" that contains
"assets_backend" and the few files that we only want in production.
In the /web page, we now load "assets_web" instead of
"assets_backend" and "assets_backend_prod_only". In the /web/tests
page, we keep loading "assets_backend", which is now directly
included into "web.tests_assets".

For the sake of consistency, this commit also renames the dark
mode bundle "dark_mode_assets_backend" into "assets_web_dark".

closes odoo/odoo#135204

Related: odoo/enterprise#47316
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-09-13 08:20:40 +00:00

44 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo.tests
from odoo.osv import expression
@odoo.tests.tagged('post_install', '-at_install', 'assets_bundle')
class BusWebTests(odoo.tests.HttpCase):
def test_bundle_sends_bus(self):
"""
Tests two things:
- Messages are posted to the bus when assets change
i.e. their hash has been recomputed and differ from the attachment's
- The interface deals with those bus messages by displaying one notification
"""
db_name = self.env.registry.db_name
# start from a clean slate
self.env['ir.attachment'].search([('name', 'ilike', 'web.assets_web%')]).unlink()
self.env.registry.clear_cache()
sendones = []
def patched_sendone(self, channel, notificationType, message):
""" Control API and number of messages posted to the bus linked to
bundle_changed events """
if notificationType == 'bundle_changed':
sendones.append((channel, message))
self.patch(type(self.env['bus.bus']), '_sendone', patched_sendone)
self.authenticate('admin', 'admin')
self.url_open('/web')
# One sendone for each asset bundle and for each CSS / JS
self.assertEqual(
len(sendones),
2,
'Received %s' % '\n'.join('%s - %s' % (tmp[0], tmp[1]) for tmp in sendones)
)
for (channel, message) in sendones:
self.assertEqual(channel, 'broadcast')
self.assertEqual(len(message), 1)
self.assertTrue(isinstance(message.get('server_version'), str))