From ae3e68c1f4fae66e132b794f5292fa07dcd11c9f Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 10 Aug 2022 13:43:21 +0000 Subject: [PATCH] [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 --- addons/web/tests/test_assets.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addons/web/tests/test_assets.py b/addons/web/tests/test_assets.py index fd3155252f9..c3e1c8d8bf7 100644 --- a/addons/web/tests/test_assets.py +++ b/addons/web/tests/test_assets.py @@ -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