|
|
@ -88,11 +88,11 @@ class TestMailTracking(TransactionCase): |
|
|
|
tracking_email.event_create('open', metadata) |
|
|
|
self.assertEqual(tracking_email.state, 'opened') |
|
|
|
|
|
|
|
def mail_send(self): |
|
|
|
def mail_send(self, recipient): |
|
|
|
mail = self.env['mail.mail'].create({ |
|
|
|
'subject': 'Test subject', |
|
|
|
'email_from': 'from@domain.com', |
|
|
|
'email_to': 'to@domain.com', |
|
|
|
'email_to': recipient, |
|
|
|
'body_html': '<p>This is a test message</p>', |
|
|
|
}) |
|
|
|
mail.send() |
|
|
@ -106,7 +106,7 @@ class TestMailTracking(TransactionCase): |
|
|
|
controller = MailTrackingController() |
|
|
|
db = self.env.cr.dbname |
|
|
|
image = base64.decodestring(BLANK) |
|
|
|
mail, tracking = self.mail_send() |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
self.assertEqual(mail.email_to, tracking.recipient) |
|
|
|
self.assertEqual(mail.email_from, tracking.sender) |
|
|
|
with mock.patch(mock_request) as mock_func: |
|
|
@ -115,7 +115,7 @@ class TestMailTracking(TransactionCase): |
|
|
|
self.assertEqual(image, res.response[0]) |
|
|
|
|
|
|
|
def test_concurrent_open(self): |
|
|
|
mail, tracking = self.mail_send() |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
ts = time.time() |
|
|
|
metadata = { |
|
|
|
'ip': '127.0.0.1', |
|
|
@ -146,7 +146,7 @@ class TestMailTracking(TransactionCase): |
|
|
|
self.assertEqual(len(opens), 2) |
|
|
|
|
|
|
|
def test_concurrent_click(self): |
|
|
|
mail, tracking = self.mail_send() |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
ts = time.time() |
|
|
|
metadata = { |
|
|
|
'ip': '127.0.0.1', |
|
|
@ -188,11 +188,66 @@ class TestMailTracking(TransactionCase): |
|
|
|
def test_smtp_error(self): |
|
|
|
with mock.patch(mock_send_email) as mock_func: |
|
|
|
mock_func.side_effect = Warning('Test error') |
|
|
|
mail, tracking = self.mail_send() |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
self.assertEqual('error', tracking.state) |
|
|
|
self.assertEqual('Warning', tracking.error_type) |
|
|
|
self.assertEqual('Test error', tracking.error_description) |
|
|
|
|
|
|
|
def test_partner_email_change(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('open', {}) |
|
|
|
orig_score = self.recipient.email_score |
|
|
|
orig_email = self.recipient.email |
|
|
|
self.recipient.email = orig_email + '2' |
|
|
|
self.assertEqual(50.0, self.recipient.email_score) |
|
|
|
self.recipient.email = orig_email |
|
|
|
self.assertEqual(orig_score, self.recipient.email_score) |
|
|
|
|
|
|
|
def test_process_hard_bounce(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('hard_bounce', {}) |
|
|
|
self.assertEqual('bounced', tracking.state) |
|
|
|
|
|
|
|
def test_process_soft_bounce(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('soft_bounce', {}) |
|
|
|
self.assertEqual('soft-bounced', tracking.state) |
|
|
|
|
|
|
|
def test_process_delivered(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('delivered', {}) |
|
|
|
self.assertEqual('delivered', tracking.state) |
|
|
|
|
|
|
|
def test_process_deferral(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('deferral', {}) |
|
|
|
self.assertEqual('deferred', tracking.state) |
|
|
|
|
|
|
|
def test_process_spam(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('spam', {}) |
|
|
|
self.assertEqual('spam', tracking.state) |
|
|
|
|
|
|
|
def test_process_unsub(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('unsub', {}) |
|
|
|
self.assertEqual('unsub', tracking.state) |
|
|
|
|
|
|
|
def test_process_reject(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('reject', {}) |
|
|
|
self.assertEqual('rejected', tracking.state) |
|
|
|
|
|
|
|
def test_process_open(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('open', {}) |
|
|
|
self.assertEqual('opened', tracking.state) |
|
|
|
|
|
|
|
def test_process_click(self): |
|
|
|
mail, tracking = self.mail_send(self.recipient.email) |
|
|
|
tracking.event_create('click', {}) |
|
|
|
self.assertEqual('opened', tracking.state) |
|
|
|
|
|
|
|
def test_db(self): |
|
|
|
db = self.env.cr.dbname |
|
|
|
controller = MailTrackingController() |
|
|
|