2020-02-05 10:34:32 +01:00
|
|
|
# Copyright 2017-2020 Tecnativa - Pedro M. Baeza
|
2022-11-03 15:12:03 +01:00
|
|
|
# Copyright 2022 Tecnativa - Víctor Martínez
|
2018-01-23 13:36:17 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
from odoo import exceptions
|
2020-02-05 10:32:10 +01:00
|
|
|
from odoo.tests import common
|
2018-01-23 13:36:17 +01:00
|
|
|
|
|
|
|
|
2022-11-03 15:12:03 +01:00
|
|
|
class TestMassMailingResend(common.TransactionCase):
|
2018-01-23 13:36:17 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2022-11-03 15:12:03 +01:00
|
|
|
super().setUpClass()
|
2020-02-05 10:34:32 +01:00
|
|
|
cls.list = cls.env["mailing.list"].create({"name": "Test list"})
|
|
|
|
cls.contact1 = cls.env["mailing.contact"].create(
|
2022-11-03 15:12:03 +01:00
|
|
|
{
|
|
|
|
"name": "Contact 1",
|
|
|
|
"email": "email1@test.com",
|
|
|
|
"list_ids": [[6, 0, [cls.list.id]]],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
cls.contact2 = cls.env["mailing.contact"].create(
|
|
|
|
{
|
|
|
|
"name": "Contact 2",
|
|
|
|
"email": "email2@test.com",
|
|
|
|
"list_ids": [[6, 0, [cls.list.id]]],
|
|
|
|
}
|
2020-02-05 10:32:10 +01:00
|
|
|
)
|
2020-02-05 10:34:32 +01:00
|
|
|
cls.mass_mailing = cls.env["mailing.mailing"].create(
|
2020-02-05 10:32:10 +01:00
|
|
|
{
|
|
|
|
"name": "Test mass mailing",
|
|
|
|
"email_from": "test@example.org",
|
2020-02-05 10:34:32 +01:00
|
|
|
"mailing_model_id": cls.env.ref("mass_mailing.model_mailing_list").id,
|
2020-02-05 10:32:10 +01:00
|
|
|
"contact_list_ids": [(6, 0, cls.list.ids)],
|
2020-02-05 10:34:32 +01:00
|
|
|
"subject": "Mailing test",
|
2020-02-05 10:32:10 +01:00
|
|
|
}
|
|
|
|
)
|
2022-11-03 15:12:03 +01:00
|
|
|
cls.mm_cron = cls.env.ref("mass_mailing.ir_cron_mass_mailing_queue").sudo()
|
2018-01-23 13:36:17 +01:00
|
|
|
|
|
|
|
def test_resend_error(self):
|
|
|
|
with self.assertRaises(exceptions.UserError):
|
|
|
|
self.mass_mailing.button_draft()
|
|
|
|
|
2022-11-03 15:12:03 +01:00
|
|
|
def _mailing_action_done(self):
|
|
|
|
self.mass_mailing.action_launch()
|
|
|
|
self.mm_cron.method_direct_trigger()
|
|
|
|
|
|
|
|
def test_resend_process(self):
|
|
|
|
# Send mailing
|
|
|
|
self._mailing_action_done()
|
2020-02-05 10:32:10 +01:00
|
|
|
self.assertEqual(self.mass_mailing.state, "done")
|
2022-11-03 15:12:03 +01:00
|
|
|
self.assertEqual(self.mass_mailing.sent, 2)
|
|
|
|
# Simulate that an email has not been sent
|
|
|
|
self.mass_mailing.mailing_trace_ids.filtered(
|
|
|
|
lambda x: x.email == self.contact2.email
|
|
|
|
).unlink()
|
|
|
|
self.assertEqual(self.mass_mailing.sent, 1)
|
|
|
|
# Back to draft
|
2018-01-23 13:36:17 +01:00
|
|
|
self.mass_mailing.button_draft()
|
2020-02-05 10:32:10 +01:00
|
|
|
self.assertEqual(self.mass_mailing.state, "draft")
|
2022-11-03 15:12:03 +01:00
|
|
|
# Send mailing again (already sent not sent again)
|
|
|
|
self._mailing_action_done()
|
|
|
|
self.assertEqual(self.mass_mailing.state, "done")
|
|
|
|
self.assertEqual(self.mass_mailing.sent, 2)
|