From 56bb6d5b320369a65f4aed74ce4afea9d1d30745 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Thu, 2 Feb 2023 10:18:39 +0000 Subject: [PATCH] [FIX] base: allow patching of config.options for 3.11 Since python/cpython#18544, unittest mock is not able to properly find the "odoo.tools.config". When trying to patch the `options` dictionnary, it leads to `AttributeError: module 'odoo.tools.config' has no attribute 'options'` In order to have the tests working in python <= 3.11, we have to import the config module and patch the options in place. Part-of: odoo/odoo#112450 --- odoo/addons/base/tests/test_ir_mail_server.py | 9 +++++---- odoo/addons/base/tests/test_mail.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/odoo/addons/base/tests/test_ir_mail_server.py b/odoo/addons/base/tests/test_ir_mail_server.py index 56edf81fda4..ccfcab4055a 100644 --- a/odoo/addons/base/tests/test_ir_mail_server.py +++ b/odoo/addons/base/tests/test_ir_mail_server.py @@ -9,6 +9,7 @@ from odoo.addons.base.tests.common import MockSmtplibCase from odoo.tests import tagged from odoo.tests.common import TransactionCase from odoo.tools import mute_logger +from odoo.tools import config @tagged('mail_server') @@ -338,7 +339,7 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase): ) @mute_logger('odoo.models.unlink') - @patch.dict("odoo.tools.config.options", {"from_filter": "test.com", "smtp_server": "example.com"}) + @patch.dict(config.options, {"from_filter": "test.com", "smtp_server": "example.com"}) def test_mail_server_binary_arguments_domain(self): """Test the configuration provided in the odoo-bin arguments. @@ -390,7 +391,7 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase): ) @mute_logger('odoo.models.unlink') - @patch.dict("odoo.tools.config.options", {"from_filter": "test.com", "smtp_server": "example.com"}) + @patch.dict(config.options, {"from_filter": "test.com", "smtp_server": "example.com"}) def test_mail_server_binary_arguments_domain_smtp_session(self): """Test the configuration provided in the odoo-bin arguments. @@ -433,7 +434,7 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase): ) @mute_logger('odoo.models.unlink') - @patch.dict('odoo.tools.config.options', {'from_filter': 'fake.com', 'smtp_server': 'cli_example.com'}) + @patch.dict(config.options, {'from_filter': 'fake.com', 'smtp_server': 'cli_example.com'}) def test_mail_server_configuration_cli(self): """Check the mail server when the "smtp_authentication" is "cli". @@ -478,7 +479,7 @@ class TestIrMailServer(TransactionCase, MockSmtplibCase): ) @mute_logger('odoo.models.unlink') - @patch.dict('odoo.tools.config.options', {'from_filter': 'test.com', 'smtp_server': 'example.com'}) + @patch.dict(config.options, {'from_filter': 'test.com', 'smtp_server': 'example.com'}) def test_mail_server_mail_default_from_filter(self): """Test that the config parameter "mail.default.from_filter" overwrite the odoo-bin argument "--from-filter" diff --git a/odoo/addons/base/tests/test_mail.py b/odoo/addons/base/tests/test_mail.py index c1d96b7a5b5..7ae0fba7095 100644 --- a/odoo/addons/base/tests/test_mail.py +++ b/odoo/addons/base/tests/test_mail.py @@ -18,6 +18,7 @@ from odoo.tools import ( email_split, email_domain_normalize, misc, formataddr, prepend_html_content, + config, ) from . import test_mail_examples @@ -494,7 +495,7 @@ class TestEmailTools(BaseCase): class EmailConfigCase(TransactionCase): - @patch.dict("odoo.tools.config.options", {"email_from": "settings@example.com"}) + @patch.dict(config.options, {"email_from": "settings@example.com"}) def test_default_email_from(self, *args): """Email from setting is respected.""" # ICP setting is more important