diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2e11427..45870f1 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -82,7 +82,9 @@ jobs: PGPASSWORD: postgres PGPORT: 5432 run: | - TEST_ODOO=${{ matrix.odoo-version }} pytest --cov=./ --cov-config=./setup.cfg -v + pytest --cov=./ --cov-config=./setup.cfg -v + TEST_ODOO=${{ matrix.odoo-version }} pytest --cov=./ --cov-config=./setup.cfg --cov-append -v tests/test_odoo_git.py + TEST_ODOO=${{ matrix.odoo-version }} pytest --cov=./ --cov-config=./setup.cfg --cov-append -v tests/test_odoo_release.py codecov - name: Install Odoo diff --git a/conftest.py b/conftest.py index 245daac..162fcb2 100644 --- a/conftest.py +++ b/conftest.py @@ -5,4 +5,5 @@ odoo_env, change_test_dir, ignore_warnings, + runner ) diff --git a/odoo_tools/api/management.py b/odoo_tools/api/management.py index 5b096ae..36779bf 100644 --- a/odoo_tools/api/management.py +++ b/odoo_tools/api/management.py @@ -1,3 +1,4 @@ +import distro import six import logging import psycopg2 @@ -318,10 +319,7 @@ def install_odoo( .. _NIGHTLY: https://nightly.odoo.com/ """ - if hasattr(opts, 'cache'): - cache = opts.cache - else: - cache = None + cache = opts.cache if release: installer = OfficialRelease( @@ -403,7 +401,7 @@ def packages(self): return package_list - def native_packages(self): + def native_packages(self, distrib_override=None): python_packages = [ "python3-pip", "python3-psycopg2", @@ -423,10 +421,19 @@ def native_packages(self): "curl", ] - distrib = { - "default": base_packages + python_packages, + distrib_map = { + "default": base_packages, "ubuntu": base_packages + python_packages, + "fedora": base_packages + python_packages, "debian": base_packages + python_packages } - return distrib['ubuntu'] + if distrib_override is not None: + distrib_id = distro.id() + else: + distrib_id = distrib_override + + if distrib_id in distrib_map: + return distrib_map[distrib_id] + else: + return distrib_map['default'] diff --git a/odoo_tools/api/objects.py b/odoo_tools/api/objects.py index 01ce6e0..093aa2a 100644 --- a/odoo_tools/api/objects.py +++ b/odoo_tools/api/objects.py @@ -574,12 +574,16 @@ def files(self): considered as "sources". It will also yield files located in the static folder. """ - for file in self.path.glob('**/*'): - if file.is_dir(): - continue - if file.name.endswith('.pyc'): - continue + all_files = [ + file + for file in self.path.glob('**/*') + if not file.is_dir() + if not file.name.endswith('.pyc') + ] + + all_files.sort() + for file in all_files: yield file def package(self): diff --git a/odoo_tools/api/services.py b/odoo_tools/api/services.py index 7e7a7cd..3aa7ffc 100644 --- a/odoo_tools/api/services.py +++ b/odoo_tools/api/services.py @@ -66,9 +66,10 @@ def package( service, output_path, fetch_path=None, - decrypt_key=None + decrypt_key=None, + temp_dir_manager=TemporaryDirectory ): - with TemporaryDirectory() as tempdir: + with temp_dir_manager() as tempdir: target = Path(tempdir) self.checkout( diff --git a/odoo_tools/cli/click/gen.py b/odoo_tools/cli/click/gen.py index 2aa1e39..d6419b4 100644 --- a/odoo_tools/cli/click/gen.py +++ b/odoo_tools/cli/click/gen.py @@ -8,3 +8,8 @@ @click.group() def gen(): pass + + +@gen.command() +def info(): + print("Install more modules like odoo-tools-rest") diff --git a/odoo_tools/cli/click/manage.py b/odoo_tools/cli/click/manage.py index 5e82f61..c89e760 100644 --- a/odoo_tools/cli/click/manage.py +++ b/odoo_tools/cli/click/manage.py @@ -176,19 +176,10 @@ def setup( opts = DictObject() - if not languages: - opts.languages = "all" - else: - opts.languages = languages - - if upgrade: - opts.upgrade = True - - if target: - opts.target = Path.cwd() / target - - if cache: - opts.cache = Path.cwd() / cache + opts.languages = languages if languages else "all" + opts.upgrade = True if upgrade else False + opts.target = Path.cwd() / target if target else None + opts.cache = Path.cwd() / cache if cache else None env.manage.install_odoo( version, diff --git a/odoo_tools/cli/registry.py b/odoo_tools/cli/registry.py index 2c129b3..20c6a12 100644 --- a/odoo_tools/cli/registry.py +++ b/odoo_tools/cli/registry.py @@ -18,7 +18,7 @@ def register(self, name, command): def register_commands(self): for ep in iter_entry_points(group='odootools.command'): - registry.register(ep.name, ep.load()) + self.register(ep.name, ep.load()) for ep in iter_entry_points(group='odootools.command.ext'): command = self.groups[ep.name] diff --git a/odoo_tools/configuration/odoo.py b/odoo_tools/configuration/odoo.py index 00f7ab9..5bdff03 100644 --- a/odoo_tools/configuration/odoo.py +++ b/odoo_tools/configuration/odoo.py @@ -121,26 +121,14 @@ def install(self): self.installed_release ) - if hasattr(self.options, 'languages'): - languages = self.options.languages - else: - languages = 'all' + languages = self.options.languages self.strip_languages(languages) _logger.info("Installing odoo") - target = ( - self.options.target - if hasattr(self.options, 'target') and self.options.target - else None - ) - - upgrade = ( - self.options.upgrade - if hasattr(self.options, 'upgrade') and self.options.upgrade - else False - ) + target = self.options.target + upgrade = self.options.upgrade args = pip_command(target=target, upgrade=upgrade) @@ -282,45 +270,3 @@ def installed_release(self): def install(self): super().install() -# -# -# def setup_odoo_from_git(repo, ref, version, options=None): -# -# if hasattr(options, 'cache'): -# cache = options.cache -# else: -# cache = None -# -# installer = GitRelease( -# version, -# repo, -# ref, -# options=options, -# cache=cache -# ) -# -# with installer: -# if installer.need_update(): -# installer.fetch() -# installer.checkout() -# installer.install() -# -# -# def setup_odoo_release(version, release, options=None): -# if hasattr(options, 'cache'): -# cache = options.cache -# else: -# cache = None -# -# installer = OfficialRelease( -# version, -# release, -# options=options, -# cache=cache -# ) -# -# with installer: -# if installer.need_update(): -# installer.fetch() -# installer.checkout() -# installer.install() diff --git a/setup.py b/setup.py index 69a781a..3d7337e 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ "packaging", "lxml", "docutils", + "distro", "polib", "six>=1.12.0", "cryptography", diff --git a/tests/fixtures.py b/tests/fixtures.py index 93feef1..aa3a190 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -2,6 +2,7 @@ import tempfile import sys import pytest +from click.testing import CliRunner import subprocess from pathlib import Path from mock import MagicMock @@ -10,6 +11,8 @@ ignore_odoo_warnings, ignore_default_warnings ) +from odoo_tools.patch import unload_modules +from odoo_tools.exceptions import OdooNotInstalled from tests.utils import generate_addons @@ -44,22 +47,17 @@ def odoo_cleanup(env): print("tearing down") odoo_path = env.path() + # Remove odoo config if Path(env.context.odoo_rc).exists(): Path(env.context.odoo_rc).unlink() + # Remove odoo subprocess.run(['pip', 'uninstall', '-y', 'odoo']) - - odoo_modules = [ - key - for key in sys.modules.keys() - if key.startswith('odoo.') - ] - - for mod in odoo_modules: - del sys.modules[mod] - subprocess.run(['rm', '-rf', str(odoo_path)]) + # Unload odoo + unload_modules("odoo") + @pytest.fixture(scope="module") def odoo_env(): @@ -69,8 +67,8 @@ def odoo_env(): options.languages = "fr_CA" options.upgrade = False - options.target = False - options.cache = False + options.target = None + options.cache = None odoo_version = "{}.0".format(os.environ['TEST_ODOO']) @@ -89,8 +87,8 @@ def odoo_release(): options.languages = "fr_CA" options.upgrade = False - options.target = False - options.cache = False + options.target = None + options.cache = None odoo_version = "{}.0".format(os.environ['TEST_ODOO']) @@ -114,3 +112,8 @@ def change_test_dir(request, monkeypatch): def ignore_warnings(request): ignore_odoo_warnings() ignore_default_warnings() + + +@pytest.fixture +def runner(): + return CliRunner() diff --git a/tests/test_api_context.py b/tests/test_api_context.py new file mode 100644 index 0000000..86bf3d2 --- /dev/null +++ b/tests/test_api_context.py @@ -0,0 +1,31 @@ +import os +import pytest +from pathlib import Path +from mock import patch +from odoo_tools.api.context import Context + + +def test_context_default_odoorc(tmp_path): + new_env = { + "HOME": str(tmp_path) + } + + with patch.dict(os.environ, new_env, clear=True): + ctx = Context() + assert ctx.default_odoorc() == Path.cwd() / 'odoo.cfg' + + new_env = { + "HOME": str(tmp_path), + } + + with patch.dict(os.environ, new_env, clear=True): + odoo_rc = tmp_path / '.odoorc' + with odoo_rc.open('w') as fout: + fout.write('') + + ctx = Context() + assert ctx.default_odoorc() == odoo_rc + + ctx = Context() + assert ctx.default_odoorc() == Path.cwd() / 'odoo.cfg' + assert ctx.odoo_rc == Path.cwd() / 'odoo.cfg' diff --git a/tests/test_api_objects.py b/tests/test_api_objects.py index 81b5598..50b8ea6 100644 --- a/tests/test_api_objects.py +++ b/tests/test_api_objects.py @@ -2,6 +2,33 @@ from pathlib import Path from odoo_tools.api.objects import CompanySpec, Manifest +fake_files = { + "__init__.py": """ +from . import models +from . import controllers +""", + "models/__init__.py": """ +from . import sale_obj +""", + "models/sale_obj": """ +from odoo import models + +class MyObj(models.Model): + _name = "my.obj" +""", + "controllers/__init__.py": """ +from . import main +""", + "controllers/main.py": """ +from odoo.http import Controller + +class MyController(Controller): + @http.route() + def whoa(): + return "" +""" + } + def test_company_spec(): company = CompanySpec(country_code='CA') @@ -111,3 +138,40 @@ def test_invalid_manifest(tmp_path): with pytest.raises(SyntaxError): manifest = Manifest.from_path(manifest.path) + + +def test_manifest_checksum(tmp_path): + module_path = tmp_path / 'sup' + + manifest = Manifest(tmp_path / 'sup') + + manifest.set_attribute( + ['external_dependencies', 'python'], + ['web', 'base', 'fun'] + ) + + manifest.save() + + main_controller = module_path / 'controllers/main.py' + manifest_file = module_path / '__manifest__.py' + + # Add file to generate valid module + for filename, data in fake_files.items(): + file_path = module_path / filename + file_path.parent.mkdir(exist_ok=True, parents=True) + with file_path.open('w') as fout: + fout.write(data) + checksum = manifest.checksum() + assert checksum.hexdigest() == "01f34218933d0cc173a1cac18ca6c96779901de9" + + # Ensure that sub file modified changes checksum + with main_controller.open('w') as fout: + fout.write("import odoo\n") + checksum = manifest.checksum() + assert checksum.hexdigest() == "006236cde58f9110ccfc1aea264bee2da8c3fc1f" + + # Check that manifest is part of the file + with manifest_file.open('w') as fout: + fout.write('{}') + checksum = manifest.checksum() + assert checksum.hexdigest() == "f7daa17811c84315adf726ad7e6a026943b48a22" diff --git a/tests/test_api_services.py b/tests/test_api_services.py new file mode 100644 index 0000000..82369e1 --- /dev/null +++ b/tests/test_api_services.py @@ -0,0 +1,68 @@ +import json +from mock import patch +from odoo_tools.odoo import Environment + + +def test_load_service(tmp_path): + env = Environment() + + service_path = tmp_path / 'services.json' + service_file = { + "services": [ + { + "name": "odoo", + "odoo": { + "version": "15.0", + }, + "addons": [ + { + "url": "git@github.com:llacroix/odoo-tools.git", + } + ] + }, + { + "name": "dev", + "inherit": "odoo", + "addons": [ + { + "url": "git@github.com:llacroix/odoo-tools-rest.git", + } + ] + } + ] + } + + with service_path.open("w") as fout: + fout.write( + json.dumps(service_file) + ) + + services = env.services.get_services(service_path) + + assert 'odoo' in services.services + assert 'dev' in services.services + + prod = services.services['odoo'] + dev = services.services['dev'].resolved + + assert len(prod.addons) == 1 + assert len(dev.addons) == 2 + + with patch('odoo_tools.api.services.fetch_addons') as fa,\ + patch('odoo_tools.api.services.checkout_repo') as cr,\ + patch('odoo_tools.api.services.ZipFile') as zp: + fa.side_effect = [('p', 'a'), ('b', 'c')] + + res = env.services.checkout( + dev, + str(tmp_path / 'build') + ) + + assert res == ['a', 'c'] + + fa.side_effect = [('p', 'a'), ('b', 'c')] + + env.services.package( + dev, + str(tmp_path / 'package') + ) diff --git a/tests/test_cli.py b/tests/test_cli.py index 18cc02e..25b4e9c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,10 +1,7 @@ import toml import json -import pytest from unittest.mock import patch, MagicMock, PropertyMock -from click.testing import CliRunner -import os from odoo_tools.cli.odot import command from odoo_tools.api.management import ManagementApi from odoo_tools.api.db import DbApi @@ -12,11 +9,6 @@ # from odoo_tools.cli import fetch_addons, copy_addons -@pytest.fixture -def runner(): - return CliRunner() - - def test_command(runner): result = runner.invoke( command, @@ -761,7 +753,12 @@ def test_manage_install_odoo(runner, tmp_path): release=None, ref="15.0", repo='https://github.com/odoo/odoo.git', - opts={'languages': 'all'} + opts={ + 'languages': 'all', + 'upgrade': False, + 'target': None, + 'cache': None + } ) mock_method.reset_mock() @@ -817,6 +814,9 @@ def test_manage_install_odoo(runner, tmp_path): repo='https://github.com/odoo/odoo.git', opts={ 'languages': 'all', + 'cache': None, + 'target': None, + 'upgrade': False } ) @@ -842,6 +842,9 @@ def test_manage_install_odoo(runner, tmp_path): repo='https://github.com/odoo/odoo.git', opts={ 'languages': 'all', + 'cache': None, + 'target': None, + 'upgrade': False, } ) @@ -1274,3 +1277,15 @@ def test_remove_user(runner): assert result.exception is None users_rs.toggle_active.assert_not_called() users_rs.unlink.assert_not_called() + + +def test_gen(runner): + result = runner.invoke( + command, + [ + 'gen', + 'info', + ] + ) + + assert result.exception is None diff --git a/tests/test_command_registry.py b/tests/test_command_registry.py new file mode 100644 index 0000000..c29613d --- /dev/null +++ b/tests/test_command_registry.py @@ -0,0 +1,100 @@ +import pytest +import click +from mock import patch, call, MagicMock + +from odoo_tools.cli.registry import CommandRegistry + + +def test_empty_registry(): + registry = CommandRegistry() + + with pytest.raises(KeyError): + registry.get('gen') + + assert len(registry.groups) == 0 + + +def test_register_command(runner): + + @click.group() + def main(): + pass + + @click.group() + def my_group(): + pass + + @click.command() + def my_cmd(): + print('my-cmd1') + + @click.command() + def my_cmd2(): + print('my-cmd2') + + registry = CommandRegistry() + + ep = MagicMock() + ep.load.return_value = my_group + ep.name = 'my_group' + + ep2 = MagicMock() + ep2.load.return_value = my_cmd + ep2.name = 'my_group' + + with patch('odoo_tools.cli.registry.iter_entry_points') as it: + it.side_effect = [[ep], [ep2]] + registry.register_commands() + + assert len(registry.groups) == 1 + + registry.set_main(main) + + my_group2 = registry.get('my_group') + assert my_group == my_group2 + + registry.load() + assert len(registry.loaded) == 1 + + registry.load() + assert len(registry.loaded) == 1 + + result = runner.invoke( + main, + [ + 'my-group', + 'my-cmd', + ] + ) + + assert result.exception is None + assert result.output == 'my-cmd1\n' + + result = runner.invoke( + main, + [ + 'my-group', + 'my-cmd2', + ] + ) + + assert isinstance(result.exception, SystemExit) + + ep3 = MagicMock() + ep3.load.return_value = my_cmd2 + ep3.name = 'my_group' + + with patch('odoo_tools.cli.registry.iter_entry_points') as it: + it.side_effect = [[], [ep3]] + registry.register_commands() + + result = runner.invoke( + main, + [ + 'my-group', + 'my-cmd2', + ] + ) + + assert result.exception is None + assert result.output == 'my-cmd2\n' diff --git a/tests/test_config_utilities.py b/tests/test_config_utilities.py index 700f36e..81fad2a 100644 --- a/tests/test_config_utilities.py +++ b/tests/test_config_utilities.py @@ -1,3 +1,5 @@ +import sys +from pathlib import Path import pytest from unittest.mock import patch, MagicMock from odoo_tools.utilities.config import ( @@ -8,6 +10,10 @@ ) from odoo_tools.utils import ConfigParser from odoo_tools.api.environment import Environment +from odoo_tools.configuration.pip import pip_command +from odoo_tools.configuration.misc import find_in_path +from odoo_tools.utilities.loaders import FileLoader +from odoo_tools.exceptions import FileParserMissingError from configparser import NoOptionError @@ -93,3 +99,72 @@ def test_config_set_defaults(): with pytest.raises(NoOptionError): config.get('options', 'name') + + +def test_pip_command(): + executable = sys.executable + base_args = [executable, '-m', 'pip', 'install'] + + empty = pip_command() + + assert empty == base_args + + user_args = pip_command(user=True) + assert user_args == base_args + ['--user'] + + upgrade_args = pip_command(upgrade=True) + assert upgrade_args == base_args + ['-U'] + + target = Path("/tmp/fun") + target_args = pip_command(target=target) + python_version = f"{sys.version_info.major}.{sys.version_info.minor}" + assert target_args == base_args + [ + '--target', str(target), + '--implementation', 'cp', + '--python', python_version, + '--no-deps' + ] + + combined_args = pip_command(user=True, upgrade=True) + assert combined_args == base_args + ['--user', '-U'] + + +def test_file_loader(tmp_path): + loader = FileLoader() + + raw_file = tmp_path / 'raw_file' + with raw_file.open('w') as fout: + fout.write("hey") + + loaders = loader.get_loaders(raw_file) + assert loaders == [] + + data = loader.load_file(raw_file) + assert data == "hey" + + raw_txt = tmp_path / 'raw.txt' + with raw_txt.open('w') as fout: + fout.write("hey") + + with pytest.raises(FileParserMissingError): + loader.load_file(raw_txt) + + loader.parsers['.txt'] = lambda data: data + + data = loader.load_file(raw_txt) + assert data == "hey" + + +def test_find_in_path(tmp_path): + path = find_in_path("/usr/bin/python") + assert path == "/usr/bin/python" + + path = find_in_path("../fun") + assert path == "../fun" + + python_exec = Path(sys.executable) + python_binary = python_exec.name + binary_path = python_exec.parent + + path = find_in_path(python_binary, paths=[binary_path]) + assert path == str(python_exec) diff --git a/tests/test_manage.py b/tests/test_manage.py index 7fad7f1..2d81d5a 100644 --- a/tests/test_manage.py +++ b/tests/test_manage.py @@ -38,3 +38,13 @@ def test_management_config(): def test_management_options(): env = Environment() assert isinstance(env.manage.options, dict) + + +def test_management_native_packages(): + env = Environment() + default_packages = env.manage.native_packages("default") + assert len(default_packages) > 0 + + packages = env.manage.native_packages() + assert len(packages) > 0 + assert packages != default_packages diff --git a/tests/test_odoo_git.py b/tests/test_odoo_git.py new file mode 100644 index 0000000..cb95260 --- /dev/null +++ b/tests/test_odoo_git.py @@ -0,0 +1,102 @@ +import os +import sys +import pytest +from collections import defaultdict +from mock import patch, MagicMock +from odoo_tools.api.objects import Manifest + +from odoo_tools.entrypoints import entrypoint +from odoo_tools import entrypoints +from odoo_tools.docker.user_entrypoint import ( + setup_env_config +) + + +@pytest.mark.skipif( + 'TEST_ODOO' not in os.environ, + reason="Testing Odoo is disabled" +) +def test_check_odoo(odoo_env): + odoo_env.check_odoo() + + +@pytest.mark.skipif( + 'TEST_ODOO' not in os.environ, + reason="Testing Odoo is disabled" +) +def test_get_odoo_addons(odoo_env): + assert len(odoo_env.addons_paths()) == 1 + + bus_module = odoo_env.modules.get('bus') + + assert bus_module.technical_name == 'bus' + + from odoo.tools import config + + assert config == odoo_env.odoo_config() + + +@pytest.mark.skipif( + 'TEST_ODOO' not in os.environ, + reason="Testing Odoo is disabled" +) +def test_env_options(odoo_env): + from odoo.tools import config + + config['workers'] = 0 + + vals = dict( + ODOO_LOAD="web,base,fun", + ODOO_WORKERS="3", + ODOO_DATABASE="fun" + ) + + with patch.dict(os.environ, vals, clear=True): + conf = odoo_env.env_options() + + with odoo_env.config() as conf1: + conf1.set('queue', 'channel', 1) + + assert conf['workers'] == "3" + assert conf['server_wide_modules'] == "web,base,fun" + assert conf['db_name'] == 'fun' + + assert config.get('server_wide_modules') == 'base,web' + assert config.get('db_name') is False + assert config.get('workers') == 0 + assert config.misc.get('queue') is None + + odoo_env.sync_options() + + assert config.get('server_wide_modules') == 'web,base,fun' + assert config.get('db_name') == "fun" + assert config.get('workers') == "3" + assert config.misc['queue']['channel'] == '1' + + +@pytest.mark.skipif( + 'TEST_ODOO' not in os.environ, + reason="Requires odoo to fetch env_options" +) +def test_set_env_config(odoo_env, tmp_path): + new_environ = {} + + with patch.dict(os.environ, new_environ, clear=True): + setup_env_config(odoo_env) + + with odoo_env.config(): + assert odoo_env.get_config('db_host') is False + + new_environ = { + "ODOO_DATABASE": "db1", + "ODOO_LOAD": "web,base,kankan", + "ODOO_WITHOUT_DEMO": "web", + } + + with patch.dict(os.environ, new_environ, clear=True): + setup_env_config(odoo_env) + + with odoo_env.config(): + assert odoo_env.get_config('db_name') == 'db1' + assert odoo_env.get_config('server_wide_modules') == 'web,base,kankan' + assert odoo_env.get_config('without_demo') == 'web' diff --git a/tests/test_odoo.py b/tests/test_odoo_release.py similarity index 52% rename from tests/test_odoo.py rename to tests/test_odoo_release.py index fdc0783..926ab5a 100644 --- a/tests/test_odoo.py +++ b/tests/test_odoo_release.py @@ -2,76 +2,11 @@ import sys import pytest from collections import defaultdict -from mock import patch, MagicMock -from odoo_tools.api.objects import Manifest +from mock import MagicMock from odoo_tools.entrypoints import entrypoint from odoo_tools import entrypoints -from odoo_tools.docker.user_entrypoint import ( - setup_env_config -) - - -@pytest.mark.skipif( - 'TEST_ODOO' not in os.environ, - reason="Testing Odoo is disabled" -) -def test_check_odoo(odoo_env): - odoo_env.check_odoo() - - -@pytest.mark.skipif( - 'TEST_ODOO' not in os.environ, - reason="Testing Odoo is disabled" -) -def test_get_odoo_addons(odoo_env): - assert len(odoo_env.addons_paths()) == 1 - - bus_module = odoo_env.modules.get('bus') - - assert bus_module.technical_name == 'bus' - - from odoo.tools import config - - assert config == odoo_env.odoo_config() - - -@pytest.mark.skipif( - 'TEST_ODOO' not in os.environ, - reason="Testing Odoo is disabled" -) -def test_env_options(odoo_env): - from odoo.tools import config - - config['workers'] = 0 - - vals = dict( - ODOO_LOAD="web,base,fun", - ODOO_WORKERS="3", - ODOO_DATABASE="fun" - ) - - with patch.dict(os.environ, vals): - conf = odoo_env.env_options() - - with odoo_env.config() as conf1: - conf1.set('queue', 'channel', 1) - - assert conf['workers'] == "3" - assert conf['server_wide_modules'] == "web,base,fun" - assert conf['db_name'] == 'fun' - - assert config.get('server_wide_modules') == 'base,web' - assert config.get('db_name') is False - assert config.get('workers') == 0 - assert config.misc.get('queue') is None - - odoo_env.sync_options() - - assert config.get('server_wide_modules') == 'web,base,fun' - assert config.get('db_name') == "fun" - assert config.get('workers') == "3" - assert config.misc['queue']['channel'] == '1' +from odoo_tools.api.objects import Manifest @pytest.mark.skipif( @@ -159,35 +94,7 @@ def setup_company_test(db): 'TEST_ODOO' not in os.environ, reason="Requires odoo to fetch env_options" ) -def test_set_env_config(odoo_env, tmp_path): - new_environ = {} - - with patch.dict(os.environ, new_environ, clear=True): - setup_env_config(odoo_env) - - with odoo_env.config(): - assert odoo_env.get_config('db_host') is False - - new_environ = { - "ODOO_DATABASE": "db1", - "ODOO_LOAD": "web,base,kankan", - "ODOO_WITHOUT_DEMO": "web", - } - - with patch.dict(os.environ, new_environ, clear=True): - setup_env_config(odoo_env) - - with odoo_env.config(): - assert odoo_env.get_config('db_name') == 'db1' - assert odoo_env.get_config('server_wide_modules') == 'web,base,kankan' - assert odoo_env.get_config('without_demo') == 'web' - - -@pytest.mark.skipif( - 'TEST_ODOO' not in os.environ, - reason="Requires odoo to fetch env_options" -) -def test_export_translations(tmp_path): +def test_export_translations(odoo_release, tmp_path): db = MagicMock() db.export_translation_terms.return_value = [