def handle(self, request, data): try: set_dict, unset_list = utils.parse_str_meta(data['group_specs']) if set_dict: manila.share_group_type_set_specs( request, self.initial["id"], set_dict) if unset_list: get = manila.share_group_type_get_specs( request, self.initial["id"]) # NOTE(vponomaryov): skip keys that are already unset to_unset = set(unset_list).intersection(set(get.keys())) if to_unset: manila.share_group_type_unset_specs( request, self.initial["id"], to_unset) msg = _( "Successfully updated group specs for share group type '%s'.") msg = msg % self.initial['name'] messages.success(request, msg) return True except ValidationError as e: # handle error without losing dialog self.api_error(e.messages[0]) return False except Exception: msg = _("Unable to update group_specs for share group type.") exceptions.handle(request, msg) return False
def test_share_group_type_unset_specs(self): sgt = 'fake_share_group_type' keys = ['fake', 'list', 'of', 'keys', 'for', 'deletion'] result = api.share_group_type_unset_specs(self.request, sgt, keys) get_method = self.manilaclient.share_group_types.get self.assertIsNotNone(result) self.assertEqual(get_method.return_value.unset_keys.return_value, result) get_method.assert_called_once_with(sgt) get_method.return_value.unset_keys.assert_called_once_with(keys)
def test_share_group_type_unset_specs(self): sgt = 'fake_share_group_type' keys = ['fake', 'list', 'of', 'keys', 'for', 'deletion'] result = api.share_group_type_unset_specs(self.request, sgt, keys) get_method = self.manilaclient.share_group_types.get self.assertIsNotNone(result) self.assertEqual( get_method.return_value.unset_keys.return_value, result) get_method.assert_called_once_with(sgt) get_method.return_value.unset_keys.assert_called_once_with(keys)