[MOV] sale -> sales_team: extract new test common

Also move crm.team access rights test from sale to sales_team where it 
should be tested.

Part-of: odoo/odoo#96791
This commit is contained in:
Victor Feyens
2022-08-08 12:33:03 +02:00
parent 546721e441
commit f753fce0b7
2 changed files with 70 additions and 3 deletions
+40 -1
View File
@@ -1,8 +1,47 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import TransactionCase
from odoo.addons.mail.tests.common import mail_new_test_user
from odoo.tests.common import TransactionCase
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
class SalesTeamCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env['base'].with_context(**DISABLED_MAIL_CONTEXT).env
cls.group_sale_salesman = cls.env.ref('sales_team.group_sale_salesman')
cls.group_sale_manager = cls.env.ref('sales_team.group_sale_manager')
cls.sale_user = cls.env['res.users'].create({
'name': 'Test Salesman',
'login': 'salesman',
'password': 'salesman',
'email': 'default_user_salesman@example.com',
'signature': '--\nMark',
'notification_type': 'email',
'groups_id': [(6, 0, cls.group_sale_salesman.ids)],
})
cls.sale_manager = cls.env['res.users'].create({
'name': 'Test Sales Manager',
'login': 'salesmanager',
'password': 'salesmanager',
'email': 'default_user_salesmanager@example.com',
'signature': '--\nDamien',
'notification_type': 'email',
'groups_id': [(6, 0, cls.group_sale_manager.ids)],
})
cls.sale_team = cls.env['crm.team'].create({
'name': 'Test Sales Team',
})
# Disable other teams (demo data/existing data)
cls.env['crm.team'].search([
('id', '!=', cls.sale_team.id),
]).action_archive()
class TestSalesCommon(TransactionCase):
+30 -2
View File
@@ -2,8 +2,9 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import exceptions
from odoo.addons.sales_team.tests.common import TestSalesCommon, TestSalesMC
from odoo.tests.common import users
from odoo.tests import tagged, users
from odoo.addons.sales_team.tests.common import SalesTeamCommon, TestSalesCommon, TestSalesMC
class TestDefaultTeam(TestSalesCommon):
@@ -202,3 +203,30 @@ class TestMultiCompany(TestSalesMC):
# cannot change company as it breaks memberships mc check
with self.assertRaises(exceptions.UserError):
team_c2.write({'company_id': self.company_2.id})
@tagged('post_install', '-at_install')
class TestAccessRights(SalesTeamCommon):
@users('salesmanager')
def test_access_sales_manager(self):
""" Test sales manager's access rights """
# Manager can create a Sales Team
india_channel = self.env['crm.team'].with_context(tracking_disable=True).create({
'name': 'India',
})
self.assertIn(
india_channel.id, self.env['crm.team'].search([]).ids,
'Sales manager should be able to create a Sales Team')
# Manager can edit a Sales Team
india_channel.write({'name': 'new_india'})
self.assertEqual(
india_channel.name, 'new_india',
'Sales manager should be able to edit a Sales Team')
# Manager can delete a Sales Team
india_channel.unlink()
self.assertNotIn(
india_channel.id, self.env['crm.team'].search([]).ids,
'Sales manager should be able to delete a Sales Team')