From e1f503fa849ad315f5c33814ca93f725aff3e7ac Mon Sep 17 00:00:00 2001 From: nenenko Date: Tue, 16 Jul 2024 13:20:29 +0200 Subject: [PATCH] fix: parent group update fixed; logger messages updated --- scripts/user_group_mgmt.py | 13 ++++++------- tests/test_restore.py | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/user_group_mgmt.py b/scripts/user_group_mgmt.py index 41952c1..cb754a5 100644 --- a/scripts/user_group_mgmt.py +++ b/scripts/user_group_mgmt.py @@ -228,9 +228,7 @@ def _get_gd_user_groups(self) -> list[CatalogUserGroup]: def _is_changed(group: TargetUserGroup, existing_group: CatalogUserGroup) -> bool: """Checks if user group has some changes and needs to be updated.""" group.parent_user_groups.sort() - parents_changed = ( - group.parent_user_groups != existing_group.get_parents - ) + parents_changed = group.parent_user_groups != existing_group.get_parents name_changed = group.user_group_name != existing_group.name return parents_changed or name_changed @@ -247,7 +245,10 @@ def _create_or_update_user_group( self.sdk.catalog_user.create_or_update_user_group(catalog_user_group) logger.info(f"Succeeded to {action} user group {group_id}") except Exception as e: - message = e.args[0] if e.args else eval(e.body)["detail"] + if hasattr(e, "body") and e.body: + message = eval(e.body).get("detail", e) + else: + message = e.args[0] if e.args else str(e) logger.error(f"Failed to {action} user group {group_id}: {message}") def _create_missing_user_groups(self, group_ids_to_create) -> None: @@ -282,9 +283,7 @@ def _update_existing_user_groups(self, group_ids_to_update) -> None: for group in groups_to_update: existing_group = existing_groups[group.user_group_id] if self._is_changed(group, existing_group): - logger.info( - f"Updating user group {group.user_group_id}..." - ) + logger.info(f"Updating user group {group.user_group_id}...") self._create_or_update_user_group( group.user_group_id, group.user_group_name, diff --git a/tests/test_restore.py b/tests/test_restore.py index 1ea8e84..3fdc2c5 100644 --- a/tests/test_restore.py +++ b/tests/test_restore.py @@ -408,13 +408,13 @@ def test_load_user_data_filters(): user_data_filters_expected = { "userDataFilters": [ { - "id": "datafilter2", + "id": "datafilter4", "maql": '{label/campaign_channels.category} = "1"', "title": "Status filter", "user": {"id": "5c867a8a-12af-45bf-8d85-c7d16bedebd1", "type": "user"}, }, { - "id": "datafilter4", + "id": "datafilter2", "maql": '{label/campaign_channels.category} = "1"', "title": "Status filter", "user": {"id": "5c867a8a-12af-45bf-8d85-c7d16bedebd1", "type": "user"},