11# Copyright 2021 Open Source Integrators
22# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
33
4+ from odoo .exceptions import ValidationError
45from odoo .tests .common import TransactionCase
56
67
@@ -11,6 +12,7 @@ def setUp(self):
1112 self .Company = self .env ["res.company" ]
1213 self .company1 = self .env .ref ("base.main_company" )
1314 self .company2 = self .Company .create ({"name" : "company2" })
15+ self .company3 = self .Company .create ({"name" : "company3" })
1416 # GROUPS for roles
1517 self .groupA = self .env .ref ("base.group_user" )
1618 self .groupB = self .env .ref ("base.group_system" )
@@ -49,15 +51,15 @@ def test_110_company_1(self):
4951 active_company_ids = self .company1 .ids
5052 ).set_groups_from_roles ()
5153 expected = self .groupA | self .groupB | self .groupC
52- found = self .test_user .groups_id .filtered (lambda x : x in expected )
54+ found = self .test_user .group_ids .filtered (lambda x : x in expected )
5355 self .assertEqual (expected , found )
5456
5557 def test_120_company_2 (self ):
5658 "Company 2 selected: Roles A and C are enabled"
5759 self .test_user .with_context (
5860 active_company_ids = self .company2 .ids
5961 ).set_groups_from_roles ()
60- enabled = self .test_user .groups_id
62+ enabled = self .test_user .group_ids
6163 expected = self .groupA | self .groupC
6264 found = enabled .filtered (lambda x : x in expected )
6365 self .assertEqual (expected , found )
@@ -71,11 +73,24 @@ def test_130_all_company(self):
7173 self .test_user .with_context (
7274 active_company_ids = [self .company1 .id , self .company2 .id ]
7375 ).set_groups_from_roles ()
74- enabled = self .test_user .groups_id
76+ enabled = self .test_user .group_ids
7577 expected = self .groupA | self .groupC
7678 found = enabled .filtered (lambda x : x in expected )
7779 self .assertEqual (expected , found )
7880
7981 not_expected = self .groupB
8082 found = enabled .filtered (lambda x : x in not_expected )
8183 self .assertFalse (found )
84+
85+ def test_140_company_3 (self ):
86+ "Company 3 selected: ValidationError"
87+ user_vals = {
88+ "name" : "ROLES TEST USER 2" ,
89+ "login" : "test_user_2" ,
90+ "company_ids" : [(6 , 0 , [self .company1 .id , self .company2 .id ])],
91+ "role_line_ids" : [
92+ (0 , 0 , {"role_id" : self .roleA .id , "company_id" : self .company3 .id }),
93+ ],
94+ }
95+ with self .assertRaises (ValidationError ):
96+ self .User .create (user_vals )
0 commit comments