[IMP] web: add tests for bundle pregeneration.

Since bundle generations should be generated before post install tests,
a loading of a /web shouldn't try to save a new version

This is currently breaking for / because of the website_id added in the
extra part of the attachement. Even if the content is the same.

Part-of: odoo/odoo#99176
This commit is contained in:
Xavier-Do
2022-09-12 13:48:59 +02:00
parent b58967d8d1
commit ae3e68c1f4
+20
View File
@@ -6,15 +6,19 @@ import time
import odoo
import odoo.tests
from odoo.tests.common import HttpCase
from odoo.modules.module import get_manifest
from odoo.tools import mute_logger
from unittest.mock import patch
_logger = logging.getLogger(__name__)
class TestAssetsGenerateTimeCommon(odoo.tests.TransactionCase):
def generate_bundles(self):
self.env['ir.attachment'].search([('url', '=like', '/web/assets/%')]).unlink() # delete existing attachement
installed_module_names = self.env['ir.module.module'].search([('state', '=', 'installed')]).mapped('name')
bundles = {
key
@@ -65,3 +69,19 @@ class TestAssetsGenerateTime(TestAssetsGenerateTimeCommon):
for bundle, duration in self.generate_bundles():
threshold = thresholds.get(bundle, 2)
self.assertLess(duration, threshold, "Bundle %r took more than %s sec" % (bundle, threshold))
@odoo.tests.tagged('post_install', '-at_install')
class TestLoad(HttpCase):
def test_assets_already_exists(self):
self.authenticate('admin', 'admin')
_save_attachment = odoo.addons.base.models.assetsbundle.AssetsBundle.save_attachment
def save_attachment(bundle, extension, content):
attachment = _save_attachment(bundle, extension, content)
message = f"Trying to save an attachement for {bundle.name} when it should already exist: {attachment.url}"
_logger.error(message)
return attachment
with patch('odoo.addons.base.models.assetsbundle.AssetsBundle.save_attachment', save_attachment):
self.url_open('/web').raise_for_status()
#self.url_open('/').raise_for_status() #currently breaking because of the website_id