[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
This commit is contained in:
Christophe Monniez
2023-02-14 08:03:23 +01:00
parent a3dffa86f5
commit 56bb6d5b32
2 changed files with 7 additions and 5 deletions
@@ -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"
+2 -1
View File
@@ -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