From 98b6081ef1ae14500c783f499b23c81ee4e5e4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 9 Aug 2018 10:22:03 +0200 Subject: [PATCH] [REF] mass_mailing: make tests independent from demo data Purpose of this commit is to avoid having tests depending on demo data. Especially those tests are recent, introduced at 967d228a44080381d185c252ff29c993b2b88429 and should have been made independent before merge. File is renamed according to guidelines. This commit is linked to task ID 1872198 and PR #26188. --- addons/mass_mailing/tests/__init__.py | 2 +- .../tests/test_mass_mailing_content.py | 50 +++++++++++++++++++ .../tests/test_mass_mailing_responsive.py | 33 ------------ 3 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 addons/mass_mailing/tests/test_mass_mailing_content.py delete mode 100644 addons/mass_mailing/tests/test_mass_mailing_responsive.py diff --git a/addons/mass_mailing/tests/__init__.py b/addons/mass_mailing/tests/__init__.py index f228b7d5635..2c4f6d291f4 100644 --- a/addons/mass_mailing/tests/__init__.py +++ b/addons/mass_mailing/tests/__init__.py @@ -2,4 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import test_mass_mailing_list_merge -from . import test_mass_mailing_responsive +from . import test_mass_mailing_content diff --git a/addons/mass_mailing/tests/test_mass_mailing_content.py b/addons/mass_mailing/tests/test_mass_mailing_content.py new file mode 100644 index 00000000000..20fa50aeee5 --- /dev/null +++ b/addons/mass_mailing/tests/test_mass_mailing_content.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests import common + + +class TestResponsiveMail(common.SavepointCase): + + def test_responsive_mail(self): + """ Testing mail mailing responsive mail body """ + self.user_employee = self.env['res.users'].with_context({ + 'mail_create_nolog': True, + 'mail_create_nosubscribe': True, + 'mail_notrack': True, + 'no_reset_password': True, + }).create({ + 'name': 'Geraldine Mass Mailing User', + 'login': 'geraldine', + 'email': 'g.g@example.com', + 'groups_id': [(6, 0, [ + self.env.ref('mass_mailing.group_mass_mailing_user').id, + self.env.ref('base.group_partner_manager').id, # TDE FIXME: check if really necessary for mass mailing + ])], + }) + + test_record = self.env['res.partner'].create({'name': 'Mass Mail Partner'}) + mass_mail_record = self.env['mail.mass_mailing'].sudo(self.user_employee).create({ + 'name': 'Test', + 'state': 'draft', + 'mailing_model_id': self.env.ref('base.model_res_partner').id, + }) + + composer = self.env['mail.compose.message'].sudo(self.user_employee).with_context({ + 'default_composition_mode': 'mass_mail', + 'default_model': 'res.partner', + 'default_res_id': test_record.id, + }).create({ + 'subject': 'Mass Mail Responsive', + 'body': 'I am Responsive body', + 'mass_mailing_id': mass_mail_record.id + }) + + mail_values = composer.get_mail_values([test_record.id]) + body_html = str(mail_values[test_record.id]['body_html']) + + self.assertIn('', body_html) + self.assertIn('', body_html) + self.assertIn('viewport', body_html) + self.assertIn('@media', body_html) + self.assertIn('I am Responsive body', body_html) diff --git a/addons/mass_mailing/tests/test_mass_mailing_responsive.py b/addons/mass_mailing/tests/test_mass_mailing_responsive.py deleted file mode 100644 index 4a186ae652c..00000000000 --- a/addons/mass_mailing/tests/test_mass_mailing_responsive.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo.tests import common - - -class TestResponsiveMail(common.SavepointCase): - - def test_responsive_mail(self): - """ - Testing mail mailing responsive mail body - """ - test_record = self.env['res.partner'].create({'name': 'Mass Mail Partner'}) - mass_mail_record = self.env.ref('mass_mailing.mass_mail_2') - - composer = self.env['mail.compose.message'].sudo().with_context({ - 'default_composition_mode': 'mass_mail', - 'default_model': 'res.partner', - 'default_res_id': test_record.id, - }).create({ - 'subject': 'Mass Mail Responsive', - 'body': 'I am Responsive body', - 'mass_mailing_id': mass_mail_record.id - }) - - mail_values = composer.get_mail_values([test_record.id]) - body_html = str(mail_values[test_record.id]['body_html']) - - self.assertIn('', body_html) - self.assertIn('', body_html) - self.assertIn('viewport', body_html) - self.assertIn('@media', body_html) - self.assertIn('I am Responsive body', body_html)