Files
odoo_source/odoo/addons/base/tests/test_module.py
T
Julien Castiaux 2e29a93503 [REF] core: remove http.addons_manifest
The http.addons_manifest is a map {module: manifest_dict} that is
populated upon the first http request. This map is basically a module
manifest cache with an extra `addons_path` key, the path of the module
on the file-system. This cache is eagerly populated upon the first http
request, the map is empty in non-http contextes (e.g. cron) which have
been a source of bugs (e.g. 50c8eb1).

A manifest cache is necessary because reading and parsing python files
from the file-system is not that cheap but there is no reason that cache
is located in `odoo.http`. A thin cache layer now wraps
`load_information_from_description_file()`/`load_manifest()` and is
lazily populated.

The `http.addons_manifest` have been removed. The extra `addons_path`
key is now present in the "normal" manifest. The `read_manifest()` was
hardly used so it has been deprecated. The only way to retrieve a
manifest is now `load_information_from_description_file()` which was
renamed `load_manifest()` (no cache) and `get_manifest()` (cache).

Side note about performances, the cache is necessary. Addons manifest
are read-only and reading + parsing python files from the file system is
not a cheap operation. Running the e-commerce tour
`@website_sale.test_04_admin_website_sale_tour` without cache on
`load_manifest()` requires 68,29 secs to complete on my laptop,
exceeding the default 1-minute time frame allowed in tests. Using a
cache the time is down to 36,53 secs. The performance impact is huge.

Part-of: odoo/odoo#79977
2021-12-14 12:39:54 +00:00

86 lines
3.0 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import os.path
import tempfile
from os.path import join as opj
from unittest.mock import patch
import odoo.addons
from odoo.modules.module import load_manifest
from odoo.release import major_version
from odoo.tests.common import BaseCase
class TestModuleManifest(BaseCase):
@classmethod
def setUpClass(cls):
cls._tmp_dir = tempfile.TemporaryDirectory(prefix='odoo-test-addons-')
cls.addClassCleanup(cls._tmp_dir.cleanup)
cls.addons_path = cls._tmp_dir.name
patcher = patch.object(odoo.addons, '__path__', [cls.addons_path])
patcher.start()
cls.addClassCleanup(patcher.stop)
def setUp(self):
self.module_root = tempfile.mkdtemp(prefix='odoo-test-module-', dir=self.addons_path)
self.module_name = os.path.basename(self.module_root)
def test_default_manifest(self):
with open(opj(self.module_root, '__manifest__.py'), 'w') as file:
file.write(str({'name': f'Temp {self.module_name}', 'license': 'MIT'}))
with self.assertNoLogs('odoo.modules.module', 'WARNING'):
manifest = load_manifest(self.module_name)
self.maxDiff = None
self.assertDictEqual(manifest, {
'addons_path': self.addons_path,
'application': False,
'assets': {},
'author': 'Odoo S.A.',
'auto_install': False,
'bootstrap': False,
'category': 'Uncategorized',
'data': [],
'demo': [],
'demo_xml': [],
'depends': [],
'description': '',
'external_dependencies': [],
'icon': '/base/static/description/icon.png',
'init_xml': [],
'installable': True,
'images': [],
'images_preview_theme': {},
'license': 'MIT',
'live_test_url': '',
'name': f'Temp {self.module_name}',
'post_init_hook': '',
'post_load': None,
'pre_init_hook': '',
'sequence': 100,
'snippet_lists': {},
'summary': '',
'test': [],
'update_xml': [],
'uninstall_hook': '',
'version': f'{major_version}.1.0',
'web': False,
'website': '',
})
def test_missing_manifest(self):
with self.assertLogs('odoo.modules.module', 'DEBUG') as capture:
manifest = load_manifest(self.module_name)
self.assertEqual(manifest, {})
self.assertIn("no manifest file found", capture.output[0])
def test_missing_license(self):
with open(opj(self.module_root, '__manifest__.py'), 'w') as file:
file.write(str({'name': f'Temp {self.module_name}'}))
with self.assertLogs('odoo.modules.module', 'WARNING') as capture:
manifest = load_manifest(self.module_name)
self.assertEqual(manifest['license'], 'LGPL-3')
self.assertIn("Missing `license` key", capture.output[0])