def test_role_create(self):
        param1 = TestCrossEnterpriseCommands.params1  # type: KeeperParams
        param2 = TestCrossEnterpriseCommands.params2  # type: KeeperParams

        ent1_parent_id = [x['node_id'] for x in param1.enterprise['nodes']][0]

        cmd = EnterpriseRoleCommand()
        ent2_role_id = cmd.get_enterprise_id(param2)
        dt = {"displayname": "Role"}
        encrypted_data = api.encrypt_aes(
            json.dumps(dt).encode('utf-8'),
            param2.enterprise['unencrypted_tree_key'])
        rq = {
            "command": "role_add",
            "role_id": ent2_role_id,
            "node_id": ent1_parent_id,
            "encrypted_data": encrypted_data,
            "visible_below": True,
            "new_user_inherit": False
        }
        failed = False
        try:
            api.communicate(param2, rq)
        except KeeperApiError as err:
            failed = True
            self.assertEqual(err.result_code, "bad_inputs_node_id")
        self.assertTrue(failed)
    def test_add_user_to_role(self):
        param1 = TestCrossEnterpriseCommands.params1  # type: KeeperParams
        param2 = TestCrossEnterpriseCommands.params2  # type: KeeperParams

        users = [x for x in param2.enterprise['users']]
        self.assertGreater(len(users), 0, 'cannot resolve user')
        user = users[0]
        ent2_user_id = user['enterprise_user_id']

        ids = []
        if 'roles' in param1.enterprise:
            ids = [x['role_id'] for x in param1.enterprise['roles']]
        role_cmd = EnterpriseRoleCommand()
        if len(ids) == 0:
            role_cmd.execute(param1, add=True, role=['Role1'])
            ids = [x['role_id'] for x in param1.enterprise['roles']]

        self.assertGreater(len(ids), 0, 'cannot resolve role')
        ent1_role_id = ids[0]
        rq = {
            "command": "role_user_add",
            "role_id": ent1_role_id,
            "enterprise_user_id": ent2_user_id
        }
        failed = False
        try:
            api.communicate(param1, rq)
        except KeeperApiError as err:
            failed = True
            self.assertEqual(err.result_code, "bad_inputs_enterprise_user_id")
        self.assertTrue(failed)

        failed = False
        try:
            api.communicate(param2, rq)
        except KeeperApiError as err:
            failed = True
            self.assertEqual(err.result_code, "bad_inputs_role_id")
        self.assertTrue(failed)

        rq = {"command": "role_delete", "role_id": ent1_role_id}
        failed = False
        try:
            api.communicate(param2, rq)
        except KeeperApiError as err:
            failed = True
            self.assertEqual(err.result_code, "bad_inputs_role_id")
        self.assertTrue(failed)