Skip to content

Commit

Permalink
[FIX] base: allow patching of config.options for 3.11
Browse files Browse the repository at this point in the history
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#112317
  • Loading branch information
d-fence authored and StevenSermeus committed Mar 9, 2023
1 parent ef85459 commit 9d08b98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions odoo/addons/base/tests/test_ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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')
Expand Down Expand Up @@ -337,7 +338,7 @@ def test_mail_server_send_email_smtp_session(self):
)

@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.
Expand Down Expand Up @@ -389,7 +390,7 @@ def test_mail_server_binary_arguments_domain(self):
)

@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.
Expand Down Expand Up @@ -432,7 +433,7 @@ def test_mail_server_binary_arguments_domain_smtp_session(self):
)

@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"
Expand Down
3 changes: 2 additions & 1 deletion odoo/addons/base/tests/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
email_split, email_domain_normalize,
misc, formataddr,
prepend_html_content,
config,
)

from . import test_mail_examples
Expand Down Expand Up @@ -465,7 +466,7 @@ def test_email_domain_normalize(self):


class EmailConfigCase(TransactionCase):
@patch.dict("odoo.tools.config.options", {"email_from": "[email protected]"})
@patch.dict(config.options, {"email_from": "[email protected]"})
def test_default_email_from(self, *args):
"""Email from setting is respected."""
# ICP setting is more important
Expand Down

0 comments on commit 9d08b98

Please sign in to comment.