[FIX] test_mail: correct test
*/ Adapt test to new version */ do not use removed method `do_in_onchange` */ remove duplicated test
This commit is contained in:
@@ -89,16 +89,15 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
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]
|
||||
attachment_numbers = [0, 3, 1, 3, 3]
|
||||
|
||||
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'])
|
||||
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],
|
||||
@@ -275,44 +274,3 @@ 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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user