diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-06-03 15:49:31 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-06-03 15:49:31 +0200 |
| commit | c8d7ad9a6bc55af465392d772ae15e981d0f80c7 (patch) | |
| tree | e9423fa8d28f85b8ad6a1a16e59afadb8db441e9 /addons/test_mail | |
| parent | 8085f259c87f1e6b7f9cf89067f56b327b8936e3 (diff) | |
| parent | 995aa1685eece9ff1070a637d19d511fb1f80260 (diff) | |
[MERGE] forward port branch saas-12.2 up to 995aa1685ee
Diffstat (limited to 'addons/test_mail')
| -rw-r--r-- | addons/test_mail/tests/test_mail_template.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_mail_template.py b/addons/test_mail/tests/test_mail_template.py index 40fa3f8b634..8fb1939a0ab 100644 --- a/addons/test_mail/tests/test_mail_template.py +++ b/addons/test_mail/tests/test_mail_template.py @@ -72,6 +72,46 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients): body_content=self.test_record.email_from, attachments=[('first.txt', b'My first attachment', 'text/plain'), ('second.txt', b'My second attachment', 'text/plain')]) + def test_composer_template_onchange_attachments(self): + """Tests that all attachments are added to the composer, + static attachments are not duplicated and while reports are re-generated, + and that intermediary attachments are dropped.""" + + composer = self.env['mail.compose.message'].with_context(default_attachment_ids=[]).create({}) + report_template = self.env.ref('web.action_report_externalpreview') + template_1 = self.email_template.copy({ + 'report_template': report_template.id, + }) + template_2 = self.email_template.copy({ + 'attachment_ids': False, + 'report_template': report_template.id, + }) + + onchange_templates = [template_1, template_2, template_1, False] + attachments_onchange = [composer.attachment_ids] + # template_1 has two static attachments and one dynamically generated report, + # template_2 only has the report, so we should get 3, 1, 3 attachments + attachment_numbers = [0, 3, 1, 3, 0] + + with self.env.do_in_onchange(): + for template in onchange_templates: + onchange = composer.onchange_template_id( + template.id if template else False, 'comment', self.test_record._name, self.test_record.id + ) + values = composer._convert_to_record(composer._convert_to_cache(onchange['value'])) + attachments_onchange.append(values['attachment_ids']) + composer.update(onchange['value']) + + self.assertEqual( + [len(attachments) for attachments in attachments_onchange], + attachment_numbers, + ) + + self.assertTrue( + len(attachments_onchange[1] & attachments_onchange[3]) == 2, + "The two static attachments on the template should be common to the two onchanges" + ) + @mute_logger('odoo.addons.mail.models.mail_mail') def test_post_post_w_template(self): self.test_record.sudo(self.user_employee).message_post_with_template(self.email_template.id, composition_mode='comment') @@ -237,3 +277,44 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients): new_partner = Partner.search([('email', '=', email_new_partner)]) self.assertTrue(new_partner) self.assertEqual(new_partner.company_id, company1) + + def test_composer_template_onchange_attachments(self): + """Tests that all attachments are added to the composer, + static attachments are not duplicated and while reports are re-generated, + and that intermediary attachments are dropped.""" + + composer = self.env['mail.compose.message'].with_context(default_attachment_ids=[]).create({}) + report_template = self.env.ref('web.action_report_externalpreview') + template_1 = self.email_template.copy({ + 'report_template': report_template.id, + }) + template_2 = self.email_template.copy({ + 'attachment_ids': False, + 'report_template': report_template.id, + }) + + onchange_templates = [template_1, template_2, template_1, False] + attachments_onchange = [composer.attachment_ids] + # template_1 has two static attachments and one dynamically generated report, + # template_2 only has the report, so we should get 3, 1, 3 attachments + # and when there is no template, no attachments + attachment_numbers = [0, 3, 1, 3, 0] + + with self.env.do_in_onchange(): + for template in onchange_templates: + onchange = composer.onchange_template_id( + template.id if template else False, 'comment', 'mail.test.simple', self.test_record.id + ) + values = composer._convert_to_record(composer._convert_to_cache(onchange['value'])) + attachments_onchange.append(values['attachment_ids']) + composer.update(onchange['value']) + + self.assertEqual( + [len(attachments) for attachments in attachments_onchange], + attachment_numbers, + ) + + self.assertTrue( + len(attachments_onchange[1] & attachments_onchange[3]) == 2, + "The two static attachments on the template should be common to the two onchanges" + ) |
