From 35711f27da0e6ba4aa263d13dc679a548ea0dd38 Mon Sep 17 00:00:00 2001 From: Guillaume Pothier Date: Wed, 21 Jun 2023 17:10:43 -0400 Subject: [PATCH] Add test for the create role from user wizard --- base_user_role/tests/test_user_role.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/base_user_role/tests/test_user_role.py b/base_user_role/tests/test_user_role.py index 800add0d..1afce291 100644 --- a/base_user_role/tests/test_user_role.py +++ b/base_user_role/tests/test_user_role.py @@ -225,3 +225,24 @@ class TestUserRole(TransactionCase): AccessError, "You are not allowed to access 'User role'" ): role.read() + + def test_create_role_from_user(self): + # Use a wizard instance to create a new role based on the user. + # We use assign_to_user = False, as otherwise this module forcibly + # assigns the role's groups to the user, which would make this + # test useless. + wizard = self.env["wizard.create.role.from.user"].create( + { + "name": "Role for user (without assign)", + "assign_to_user": False, + } + ) + ctx = {"active_ids": [self.user_id.id]} + result = wizard.with_context(ctx).create_from_user() + + # Check that the role has the same groups as the user + role_id = result["res_id"] + role = self.role_model.browse([role_id]) + user_group_ids = sorted(set(self.user_id.groups_id.ids)) + role_group_ids = sorted(set(role.trans_implied_ids.ids)) + self.assertEqual(user_group_ids, role_group_ids)