Skip to content

Commit d44c252

Browse files
committed
[IMP] ..aware_sender: add test for server selection
1 parent 5e84036 commit d44c252

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

mail_company_aware_sender/static/description/index.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15-
Despite the name, some widely supported CSS2 features are used.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -446,9 +445,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
446445
<div class="section" id="maintainers">
447446
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
448447
<p>This module is maintained by the OCA.</p>
449-
<a class="reference external image-reference" href="https://odoo-community.org">
450-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
451-
</a>
448+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
452449
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
453450
mission is to support the collaborative development of Odoo features and
454451
promote its widespread use.</p>

mail_company_aware_sender/tests/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Copyright 2025 Therp BV <https://therp.nl>.
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
from email.utils import parseaddr
4+
35
from odoo.tests.common import SavepointCase
46

57

@@ -17,6 +19,7 @@ def setUpClass(cls):
1719
"name": "localhost",
1820
"smtp_host": "localhost",
1921
"domain_whitelist": "therp.nl",
22+
"sequence": 99,
2023
}
2124
)
2225
cls.company_kingdom = cls.Company.create(
@@ -58,3 +61,10 @@ def setUpClass(cls):
5861
"company_id": cls.company_imperium.id,
5962
}
6063
)
64+
65+
def _assert_email(self, email_from, expected_email, expected_name=None):
66+
"""Assert email_from matches expected parts, tolerant to quoting differences."""
67+
name, email = parseaddr(email_from or "")
68+
self.assertEqual(email, expected_email)
69+
if expected_name is not None:
70+
self.assertEqual(name, expected_name)

mail_company_aware_sender/tests/test_company_aware_sender.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
# Copyright 2025 Therp BV <https://therp.nl>.
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3-
from email.utils import parseaddr
43

54
from .common import CompanyAwareSenderCase
65

76

87
class TestCompanyAwareSender(CompanyAwareSenderCase):
9-
def _assert_email(self, email_from, expected_email, expected_name=None):
10-
"""Assert email_from matches expected parts, tolerant to quoting differences."""
11-
name, email = parseaddr(email_from or "")
12-
self.assertEqual(email, expected_email)
13-
if expected_name is not None:
14-
self.assertEqual(name, expected_name)
15-
168
def test_nothing_changed(self):
179
# Check with default user and author (current user).
1810
mail_thread = (

mail_company_aware_sender/tests/test_mail_server.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
# Copyright 2025 Therp BV <https://therp.nl>.
1+
# Copyright 2025-2026 Therp BV <https://therp.nl>.
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3-
from email.utils import parseaddr
43

54
from odoo.exceptions import ValidationError
65

76
from .common import CompanyAwareSenderCase
87

98

109
class TestMailServer(CompanyAwareSenderCase):
11-
def _assert_email(self, email_from, expected_email, expected_name=None):
12-
"""Assert email_from matches expected parts, tolerant to quoting differences."""
13-
name, email = parseaddr(email_from or "")
14-
self.assertEqual(email, expected_email)
15-
if expected_name is not None:
16-
self.assertEqual(name, expected_name)
17-
1810
def test_test_email_adresses(self):
1911
# Whitelist domain, and enable from address.
2012
self.mail_server.write(
@@ -54,3 +46,32 @@ def test_disable_encapsulation(self):
5446
self.company_imperium
5547
)._get_default_from_address()
5648
self.assertEqual(email_from, None)
49+
50+
def test_email_server_selection(self):
51+
# When one server has domain whitelisted, that server should send message.
52+
self.IrMailServer.create(
53+
{
54+
"name": "default mail server",
55+
"smtp_host": "localhost",
56+
"domain_whitelist": "therp.nl",
57+
"sequence": 5,
58+
}
59+
)
60+
self.mail_server.write(
61+
{
62+
"smtp_from": "info@imperiumromanum.org",
63+
"domain_whitelist": "imperiumromanum.org",
64+
}
65+
)
66+
# Partner charles in imperium should use company aware from.
67+
email_from, email_to = (
68+
self.mail_server.with_user(self.user_charles)
69+
.with_company(self.company_imperium)
70+
._get_test_email_addresses()
71+
)
72+
self._assert_email(email_from, "charlemagne@imperiumromanum.org")
73+
# Call the (misspelled) _get_mail_sever method, defined in the
74+
# mail_outbound_static module, to select the right mail server.
75+
mail_server_id = self.IrMailServer._get_mail_sever("imperiumromanum.org")
76+
# The server with the domain should be used, despite higher sequence.
77+
self.assertEqual(mail_server_id, self.mail_server.id)

0 commit comments

Comments
 (0)