From 5a2d789d1aadaed787b58dec2de46447602a3310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 21 Nov 2017 13:45:00 +0100 Subject: [PATCH] [REF] crm: tests: make tests independent from mail Purpose is to be able to move mail tests in a separate module without breaking other tests. It seems dependency is not real, only some data to add. It is better to have self contained tests anyway. --- addons/crm/tests/common.py | 26 +------------------ .../crm/tests/test_new_lead_notification.py | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/addons/crm/tests/common.py b/addons/crm/tests/common.py index ef90160a6cc..f437d348325 100644 --- a/addons/crm/tests/common.py +++ b/addons/crm/tests/common.py @@ -2,31 +2,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.tests.common import TransactionCase -from odoo.addons.mail.tests.common import BaseFunctionalTest - -class TestCrm(BaseFunctionalTest): - - @classmethod - def setUpClass(cls): - super(TestCrm, cls).setUpClass() - - user_group_employee = cls.env.ref('base.group_user') - user_group_salesman_all = cls.env.ref('sales_team.group_sale_salesman_all_leads') - - # Test users to use through the various tests - Users = cls.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True}) - cls.user_salesman_all = Users.create({ - 'name': 'Riton La Chignole', - 'login': 'riton', - 'email': 'riton.salesman_all@example.com', - 'notification_type': 'inbox', - 'groups_id': [(6, 0, [user_group_employee.id, user_group_salesman_all.id])] - }) - - cls.sales_team_1 = cls.env['crm.team'].create({ - 'name': 'Test Sales Channel', - 'alias_name': 'test_sales_team', - }) class TestCrmCases(TransactionCase): @@ -49,5 +24,6 @@ class TestCrmCases(TransactionCase): 'name': "Crm Salesman", 'login': "csu", 'email': "crmuser@yourcompany.com", + 'notification_type': 'inbox', 'groups_id': [(6, 0, [self.env.ref('sales_team.group_sale_salesman_all_leads').id, self.env.ref('base.group_partner_manager').id])] }) diff --git a/addons/crm/tests/test_new_lead_notification.py b/addons/crm/tests/test_new_lead_notification.py index 514be895d3a..20f958e25c7 100644 --- a/addons/crm/tests/test_new_lead_notification.py +++ b/addons/crm/tests/test_new_lead_notification.py @@ -1,18 +1,24 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from .common import TestCrm +from .common import TestCrmCases -class NewLeadNotification(TestCrm): +class NewLeadNotification(TestCrmCases): def test_new_lead_notification(self): """ Test newly create leads like from the website. People and channels subscribed to the sales channel shoud be notified. """ # subscribe a partner and a channel to the sales channel with new lead subtype + channel_listen = self.env['mail.channel'].create({'name': 'Listener'}) + sales_team_1 = self.env['crm.team'].create({ + 'name': 'Test Sales Channel', + 'alias_name': 'test_sales_team', + }) + subtype = self.env.ref("crm.mt_salesteam_lead") - self.sales_team_1.message_subscribe(partner_ids=[self.user_salesman_all.partner_id.id], subtype_ids=[subtype.id]) - self.sales_team_1.message_subscribe(channel_ids=[self.channel_listen.id], subtype_ids=[subtype.id]) + sales_team_1.message_subscribe(partner_ids=[self.crm_salesman.partner_id.id], subtype_ids=[subtype.id]) + sales_team_1.message_subscribe(channel_ids=[channel_listen.id], subtype_ids=[subtype.id]) # Imitate what happens in the controller when somebody creates a new # lead from the website form @@ -22,17 +28,17 @@ class NewLeadNotification(TestCrm): "email_from": "somemail@example.com", "name": "Some subject", "partner_name": "Some company", - "team_id": self.sales_team_1.id, + "team_id": sales_team_1.id, "phone": "+0000000000" }) # partner and channel should be auto subscribed - self.assertIn(self.user_salesman_all.partner_id, lead.message_partner_ids) - self.assertIn(self.channel_listen, lead.message_channel_ids) + self.assertIn(self.crm_salesman.partner_id, lead.message_partner_ids) + self.assertIn(channel_listen, lead.message_channel_ids) msg = lead.message_ids[0] - self.assertIn(self.user_salesman_all.partner_id, msg.needaction_partner_ids) - self.assertIn(self.channel_listen, msg.channel_ids) + self.assertIn(self.crm_salesman.partner_id, msg.needaction_partner_ids) + self.assertIn(channel_listen, msg.channel_ids) # The user should have a new unread message - lead_user = lead.sudo(self.user_salesman_all) + lead_user = lead.sudo(self.crm_salesman) self.assertTrue(lead_user.message_needaction)