From 454fab074b683ff9421530ddb5e56944b6f62296 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 13 Nov 2019 11:48:09 +0000 Subject: [PATCH 1/2] [FIX] base_user_role: Improve tests resiliency These 2 tests were checking the exact set of groups a user should have. If these tests are ran in a database where a module is previously installed which adds more groups to the base role, these exact group sets would be inexact, although the behavior that is being tested was actually properly working. With this patch, basically I'm testing if the user contains the groups from the roles, not the exact role set expected. It should work in integration scenarios. @Tecnativa TT20468 --- base_user_role/tests/test_user_role.py | 56 +++++++++++++++++--------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/base_user_role/tests/test_user_role.py b/base_user_role/tests/test_user_role.py index 800add0d..c3259efa 100644 --- a/base_user_role/tests/test_user_role.py +++ b/base_user_role/tests/test_user_role.py @@ -136,12 +136,17 @@ class TestUserRole(TransactionCase): self.assertEqual(user_group_ids, role_group_ids) def test_role_unlink(self): - # Get role1 groups - role1_group_ids = ( - self.role1_id.implied_ids.ids + self.role1_id.trans_implied_ids.ids + # Get role1 and role2 groups + role1_groups = ( + self.role1_id.implied_ids + | self.role1_id.trans_implied_ids + | self.role1_id.group_id + ) + role2_groups = ( + self.role2_id.implied_ids + | self.role2_id.trans_implied_ids + | self.role2_id.group_id ) - role1_group_ids.append(self.role1_id.group_id.id) - role1_group_ids = sorted(set(role1_group_ids)) # Configure the user with role1 and role2 self.user_id.write( @@ -152,22 +157,32 @@ class TestUserRole(TransactionCase): ] } ) + # Check user has groups from role1 and role2 + self.assertLessEqual(role1_groups, self.user_id.groups_id) + self.assertLessEqual(role2_groups, self.user_id.groups_id) # Remove role2 self.role2_id.unlink() - user_group_ids = sorted({group.id for group in self.user_id.groups_id}) - self.assertEqual(user_group_ids, role1_group_ids) + # Check user has groups from only role1 + self.assertLessEqual(role1_groups, self.user_id.groups_id) + self.assertFalse(role2_groups <= self.user_id.groups_id) # Remove role1 self.role1_id.unlink() - user_group_ids = sorted({group.id for group in self.user_id.groups_id}) - self.assertEqual(user_group_ids, []) + # Check user has no groups from role1 and role2 + self.assertFalse(role1_groups <= self.user_id.groups_id) + self.assertFalse(role2_groups <= self.user_id.groups_id) def test_role_line_unlink(self): - # Get role1 groups - role1_group_ids = ( - self.role1_id.implied_ids.ids + self.role1_id.trans_implied_ids.ids + # Get role1 and role2 groups + role1_groups = ( + self.role1_id.implied_ids + | self.role1_id.trans_implied_ids + | self.role1_id.group_id + ) + role2_groups = ( + self.role2_id.implied_ids + | self.role2_id.trans_implied_ids + | self.role2_id.group_id ) - role1_group_ids.append(self.role1_id.group_id.id) - role1_group_ids = sorted(set(role1_group_ids)) # Configure the user with role1 and role2 self.user_id.write( @@ -178,18 +193,23 @@ class TestUserRole(TransactionCase): ] } ) + # Check user has groups from role1 and role2 + self.assertLessEqual(role1_groups, self.user_id.groups_id) + self.assertLessEqual(role2_groups, self.user_id.groups_id) # Remove role2 from the user self.user_id.role_line_ids.filtered( lambda l: l.role_id.id == self.role2_id.id ).unlink() - user_group_ids = sorted({group.id for group in self.user_id.groups_id}) - self.assertEqual(user_group_ids, role1_group_ids) + # Check user has groups from only role1 + self.assertLessEqual(role1_groups, self.user_id.groups_id) + self.assertFalse(role2_groups <= self.user_id.groups_id) # Remove role1 from the user self.user_id.role_line_ids.filtered( lambda l: l.role_id.id == self.role1_id.id ).unlink() - user_group_ids = sorted({group.id for group in self.user_id.groups_id}) - self.assertEqual(user_group_ids, []) + # Check user has no groups from role1 and role2 + self.assertFalse(role1_groups <= self.user_id.groups_id) + self.assertFalse(role2_groups <= self.user_id.groups_id) def test_default_user_roles(self): self.default_user.write( From a1004a883581b61c0f16be9088259e5a62bb0e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Wed, 28 Sep 2022 09:39:59 +0200 Subject: [PATCH 2/2] fixup! [FIX] base_user_role: Improve tests resiliency --- base_user_role/tests/test_user_role.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/base_user_role/tests/test_user_role.py b/base_user_role/tests/test_user_role.py index c3259efa..b39440ac 100644 --- a/base_user_role/tests/test_user_role.py +++ b/base_user_role/tests/test_user_role.py @@ -137,16 +137,8 @@ class TestUserRole(TransactionCase): def test_role_unlink(self): # Get role1 and role2 groups - role1_groups = ( - self.role1_id.implied_ids - | self.role1_id.trans_implied_ids - | self.role1_id.group_id - ) - role2_groups = ( - self.role2_id.implied_ids - | self.role2_id.trans_implied_ids - | self.role2_id.group_id - ) + role1_groups = self.role1_id.trans_implied_ids | self.role1_id.group_id + role2_groups = self.role2_id.trans_implied_ids | self.role2_id.group_id # Configure the user with role1 and role2 self.user_id.write( @@ -173,16 +165,8 @@ class TestUserRole(TransactionCase): def test_role_line_unlink(self): # Get role1 and role2 groups - role1_groups = ( - self.role1_id.implied_ids - | self.role1_id.trans_implied_ids - | self.role1_id.group_id - ) - role2_groups = ( - self.role2_id.implied_ids - | self.role2_id.trans_implied_ids - | self.role2_id.group_id - ) + role1_groups = self.role1_id.trans_implied_ids | self.role1_id.group_id + role2_groups = self.role2_id.trans_implied_ids | self.role2_id.group_id # Configure the user with role1 and role2 self.user_id.write(