-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] mail_send_copy: work with existing BCC+adding tests2
- Loading branch information
Showing
2 changed files
with
38 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import test_mail_send_copy | ||
from . import test_mail_send_copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,29 +8,35 @@ | |
from odoo.addons.mail.tests.test_mail_composer import TestMailComposer | ||
|
||
|
||
class TestMailSendCopy(TestMailComposer): | ||
class TestMailSendCopy(TestMailComposer): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context={"testing": True}) | ||
|
||
# Create test partner | ||
cls.partner = cls.env["res.partner"].create({ | ||
"name": "Test Partner", | ||
"email": "[email protected]", | ||
}) | ||
cls.partner = cls.env["res.partner"].create( | ||
{ | ||
"name": "Test Partner", | ||
"email": "[email protected]", | ||
} | ||
) | ||
|
||
def test_send_email_with_copy(self): | ||
"""Test that sender is added to BCC when sending email""" | ||
composer = self.env["mail.compose.message"].create({ | ||
"partner_ids": [(6, 0, [self.partner.id])], | ||
"subject": "Test Subject", | ||
"body": "<p>Test Body</p>", | ||
"email_from": "[email protected]", | ||
}) | ||
composer = self.env["mail.compose.message"].create( | ||
{ | ||
"partner_ids": [(6, 0, [self.partner.id])], | ||
"subject": "Test Subject", | ||
"body": "<p>Test Body</p>", | ||
"email_from": "[email protected]", | ||
} | ||
) | ||
|
||
# Mock the send_email method | ||
with patch('odoo.addons.base.models.ir_mail_server.IrMailServer.send_email') as mock_send_email: | ||
with patch( | ||
"odoo.addons.base.models.ir_mail_server.IrMailServer.send_email" | ||
) as mock_send_email: | ||
composer._action_send_mail() | ||
# Verify that send_email was called | ||
self.assertTrue(mock_send_email.called) | ||
|
@@ -39,21 +45,27 @@ def test_send_email_with_copy(self): | |
# The message is the first argument | ||
message = call_args[0] | ||
# Check BCC in the email message | ||
self.assertIn('[email protected]', message['Bcc']) | ||
self.assertIn("[email protected]", message["Bcc"]) | ||
|
||
def test_send_email_without_copy(self): | ||
"""Test that sender is not added to BCC when do_not_send_copy is True""" | ||
composer = self.env["mail.compose.message"].with_context( | ||
do_not_send_copy=True | ||
).create({ | ||
"partner_ids": [(6, 0, [self.partner.id])], | ||
"subject": "Test Subject No Copy", | ||
"body": "<p>Test Body</p>", | ||
"email_from": "[email protected]", | ||
}) | ||
|
||
with patch('odoo.addons.base.models.ir_mail_server.IrMailServer.send_email') as mock_send_email: | ||
composer = ( | ||
self.env["mail.compose.message"] | ||
.with_context(do_not_send_copy=True) | ||
.create( | ||
{ | ||
"partner_ids": [(6, 0, [self.partner.id])], | ||
"subject": "Test Subject No Copy", | ||
"body": "<p>Test Body</p>", | ||
"email_from": "[email protected]", | ||
} | ||
) | ||
) | ||
|
||
with patch( | ||
"odoo.addons.base.models.ir_mail_server.IrMailServer.send_email" | ||
) as mock_send_email: | ||
composer._action_send_mail() | ||
self.assertTrue(mock_send_email.called) | ||
message = mock_send_email.call_args[0][0] | ||
self.assertNotIn('Bcc', message) | ||
self.assertNotIn("Bcc", message) |